How to Export Playlists from NewPipe

I am, like many other free software advocates, an enthusiastic user of the alternative YouTube client NewPipe, and I keep all of my playlists in there. While working on a page for my playlist on mathematical lectures the need to export playlists from NewPipe naturally appeared. I figured that with enough digging I would find an obscure button somewhere to export my playlists to JSON or something, but apparently NewPipe has no such feature. This is a tutorial on how to hack your way around this limitation.

As such, this tutorial relies on internal implementation details of the NewPipe app, and may brake with future updates. Since there is no official feature to extract this data from the app, we have to filter this data from all of the app data. To get this data, you should follow the official instructions on how to export the data and you will get a ZIP file containing a SQLite database file newpipe.db. Among other things, this file contains information on the videos inside each playlist, but the issue is that the information on videos from all playlists is stored in a single table named streams.

To find out from which playlist each video in stream is we need to look at the playlists table and the playlist_stream_join. First and foremost, we need to find out the so called “playlist id” of our playlist. This can be done by inspecting the playlist_id column of the row corresponding to our playlist in the playlists table, as in

select playlist_id, title form playlists;

Next we need get the information (url + title) of the videos inside our playlist, which can be done via the following query.

select url, title from streams
where uid in
  (select stream_id from playlist_stream_join where playlist_id = <PLAYLIST ID>);

You should replace “<PLAYLIST ID>” from the last query with the id obtained by inspecting the entries of the playlists table. After that, you can convert the result of this last query to your favorite data format, such as CSV or JSON, using standard NewPipe features. To be honest, I don’t blame the NewPipe team for not implementing this feature: it is such an obscure feature. I would like to be able to somehow share my playlists with friends in some sort of text format, but I don’t really see how exporting playlists to machine readable formats such as JSON.