Skip to content

Instantly share code, notes, and snippets.

@sug0
Last active June 1, 2020 19:43
Show Gist options
  • Select an option

  • Save sug0/1528c08c3fb9d9de00bcc5e962beb7a2 to your computer and use it in GitHub Desktop.

Select an option

Save sug0/1528c08c3fb9d9de00bcc5e962beb7a2 to your computer and use it in GitHub Desktop.
Convert NewPipe playlists from SQLite to JSON
import sqlite3
import json
if __name__ == '__main__':
with sqlite3.connect('newpipe.db') as conn:
c = conn.cursor()
playlists = { id:{'name':name, 'tracks':[]} for id, name, _ in \
c.execute('select * from playlists') }
stream_to_playlist = { stream_id:playlist_id for playlist_id, stream_id, _ in \
c.execute('select * from playlist_stream_join') }
streams = { id:(title, url) for id, _, url, title, _, _, _, _, _, _, _, _ in \
c.execute('select * from streams') }
for stream_id in streams:
try:
playlist_id = stream_to_playlist[stream_id]
except KeyError:
continue
playlist = playlists[playlist_id]
title, url = streams[stream_id]
playlist['tracks'].append({'title':title, 'url':url})
with open('playlists.json', 'w') as f:
f.write(json.dumps({ playlists[id]['name']:playlists[id]['tracks'] \
for id in playlists }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment