Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions PlexPlaylistExport.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import argparse
import requests
import plexapi
import sys
import codecs
from plexapi.server import PlexServer
from unidecode import unidecode
Expand Down Expand Up @@ -55,32 +56,33 @@ def list_playlists(options: ExportOptions):
""" Lists all 'audio' playlists on the given Plex server
"""

print('Connecting to plex...', end='')
print('Connecting to plex...', end='', file=sys.stderr, flush=True)
try:
plex = PlexServer(options.host, options.token)
except (plexapi.exceptions.Unauthorized, requests.exceptions.ConnectionError):
print(' failed')
print(' failed', file=sys.stderr, flush=True)
return
print(' done')
print(' done', file=sys.stderr, flush=True)

if options.user != None:
print('Switching to managed account %s...' % options.user, end='')
print('Switching to managed account %s...' % options.user, end='', file=sys.stderr, flush=True)
try:
plex = plex.switchUser(options.user)
except (plexapi.exceptions.Unauthorized, requests.exceptions.ConnectionError):
print(' failed')
print(' failed', file=sys.stderr, flush=True)
return
print(' done')
print(' done', file=sys.stderr, flush=True)

print('Getting playlists... ', end='')
print('Getting playlists... ', end='', file=sys.stderr, flush=True)
playlists = plex.playlists()
print(' done')
print(' done', file=sys.stderr, flush=True)

print('')
print('Supply any of the following playlists to --playlist <playlist>:')
print('', file=sys.stderr, flush=True)
print('Supply any of the following playlists to --playlist <playlist>:', file=sys.stderr, flush=True)
for item in playlists:
if (item.playlistType == 'audio'):
print('\t%s' % item.title)
# Print the playlist titles to stdout so they can be captured separately from the status outputs
print('%s' % item.title, file=sys.stdout, flush=True)

def export_playlist(options: ExportOptions):
""" Exports a given playlist from the specified Plex server in M3U format.
Expand Down Expand Up @@ -213,4 +215,4 @@ def main():
export_playlist(options)

if __name__ == "__main__":
main()
main()