#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Listen to plex alerts and print them to the console. Because we're using print as a function, example only works in Python3. """ import time from plexapi.server import PlexServer def _print(msg): print(msg) if __name__ == '__main__': try: plex = PlexServer() listener = plex.startAlertListener(_print) while True: time.sleep(1) except KeyboardInterrupt: listener.stop()
playlist_title = argv[4] item_title = argv[5] def cb(data): if 'StatusNotification' and data['size'] == 1: status = data[u'StatusNotification'][0] if 'title' in status and status['title'] == 'Library scan complete': print('finished refresing') notifier.stop() server = PlexServer(url, token) library = server.library section = library.section(section_title) notifier = server.startAlertListener(callback=cb) if section.refreshing: print('already refrehsing') else: print('start refrehsing') section.update() while notifier.isAlive(): sleep(0.1) print('addig item to playlist') items = section.searchTracks(title=item_title, sort='addedAt:desc', maxresults=1) print('items', items)