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 and playlist_stream_join tables. First and foremost, we need to find out the so called β€œplaylist id” of our playlist. This is a code which represents our playlist in NewPipe’s internal system. The playlist id can be obtained by inspecting the playlist_id column of the row corresponding to our playlist in the playlists table, as in

select playlist_id, title from playlists;

Next we need get the information (url + title) of the videos inside our playlist. Again, there is no single table containing this information. NewPipe stores the information on which videos are contained in which playlists at the playlist_stream_join table, while the information on each individual video is stored at the streams table. The order the videos are stored in the streams table is essentially arbitrary, so to get get the videos in the same order as in the playlist we are trying to export we need sort our query by the join_index column of the playlist_stream_join table. This 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>)
order by
  (select join_index from playlist_stream_join where stream_id = uid and 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.

To be honest, I don’t blame the NewPipe team for not implementing this functionality: 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 would help. Anyway, at least we geeky people can access this information. πŸ˜›