python-plexapi icon indicating copy to clipboard operation
python-plexapi copied to clipboard

Structures for AlertListener messages

Open glensc opened this issue 1 year ago • 0 comments

What is your feature request?

AlertListener events are json payloads with such structure:

{'type': 'activity', 'size': 1, 'ActivityNotification': [{'event': 'ended', 'uuid': '12204475-ab69-4d49-80c4-ea87c808d1b7', 'Activity': {'uuid': '12204475-ab69-4d49-80c4-ea87c808d1b7', 'type': 'library.refresh.items', 'cancellable': False, 'userID': 1, 'title': 'Refreshing', 'subtitle': 'Refreshing media analysis', 'progress': 100, 'Context': {'accessible': True, 'analyzed': False, 'exists': True, 'key': '/library/metadata/22466', 'refreshed': False}}}]}

Would be nice to have utility classes that parse size and yield structures based on type. Additionally add some dispatcher logic to be able to handle events based on payload.

Are there any workarounds?

No response

Code Snippets

For the "message to class" logic I've implemented in my project:

  • https://github.com/Taxel/PlexTraktSync/blob/f2e4f297bac0c07a952db62f0c2e0a5194b035ba/plextraktsync/watch/EventFactory.py

This contains message classes:

  • https://github.com/Taxel/PlexTraktSync/blob/f2e4f297bac0c07a952db62f0c2e0a5194b035ba/plextraktsync/watch/events.py

and this contains dispatcher:

  • https://github.com/Taxel/PlexTraktSync/blob/f2e4f297bac0c07a952db62f0c2e0a5194b035ba/plextraktsync/watch/EventDispatcher.py

Additional Context

The reason I ask this, is that I have another project where want to filter and AlertListener messages...

What part of this could be in plexapi, what part is too specific not to be included? what would the structure and naming be? (I'm willing to make a PR if that's clear)

glensc avatar Mar 26 '24 23:03 glensc