From 49bbf06141f83a452c50e3deddb18fcae24c78e7 Mon Sep 17 00:00:00 2001 From: Scott McLewin Date: Fri, 26 Dec 2025 14:00:41 -0600 Subject: [PATCH] Subtle change to the --list output. By sending status to stderr and the playlist titles to stdout it allows scripts to capture stdout only. This allows a script to iterate over the list of playlists to automatically extract all of them. My use case is that I run Plex and Lyrion Music Server on the same Docker swarm sharing the same volume of music. I still have devices in the home that tie into LMS, but use Plex as my primary media server on my phone, in my car and in browser. Your script allows me to manage all my playlists in Plex and simply export them all into the Lyrion Music Server. I never create or edit playlists in LMS. Great work, thank you! --- PlexPlaylistExport.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/PlexPlaylistExport.py b/PlexPlaylistExport.py index 5e4ddc3..4673b33 100644 --- a/PlexPlaylistExport.py +++ b/PlexPlaylistExport.py @@ -17,6 +17,7 @@ import argparse import requests import plexapi +import sys import codecs from plexapi.server import PlexServer from unidecode import unidecode @@ -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 :') + print('', file=sys.stderr, flush=True) + print('Supply any of the following playlists to --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. @@ -213,4 +215,4 @@ def main(): export_playlist(options) if __name__ == "__main__": - main() \ No newline at end of file + main()