Skip to content

Library Hubs and Music Stations#518

Merged
Hellowlol merged 35 commits intomasterfrom
library_hubs
Oct 1, 2020
Merged

Library Hubs and Music Stations#518
Hellowlol merged 35 commits intomasterfrom
library_hubs

Conversation

@blacktwin
Copy link
Collaborator

@blacktwin blacktwin commented Jun 22, 2020

Adding Station support as requested in #361

Adding Library Hubs. Returns "More By {ARTIST}" or "Rediscover"

  • New feature (non-breaking change which adds functionality)

@blacktwin
Copy link
Collaborator Author

Code snippets:

for y in plex.library.section('Music').filterFields(mediaType='album'):
    print(vars(y))
    break
"""
{   '_data': <Element 'Field' at 0x0000022F716CF638>,
    '_details_key': '',
    '_initpath': '/library/sections/27/all?type=9',
    '_server': <PlexServer:http://127.0.0.1:324>,
    'key': 'album.title',
    'operators': [   <Operator:=:contains>,
                     <Operator:!=:does-not-contain>,
                     <Operator:==:is>,
                     <Operator:!==:is-not>,
                     <Operator:<=:begins-with>,
                     <Operator:>=:ends-with>],
    'subType': None,
    'title': 'Album Title',
    'type': 'string'}
"""
for sort in plex.library.section('TV Shows')._sorts():
    print(vars(sort))
    break
"""
{   '_data': <Element 'Directory' at 0x0000022F716C73B8>,
    '_details_key': '',
    '_initpath': '/library/sections/3/sorts',
    '_server': <PlexServer:http://127.0.0.1:324>,
    'defaultDirection': 'asc',
    'descKey': 'titleSort:desc',
    'firstCharacterKey': '/library/sections/3/firstCharacter',
    'key': 'titleSort',
    'title': 'Title'}
"""
for first in plex.library.section('Movies').firstCharacter():
    print(vars(first))
    break
"""
{   '_data': <Element 'Directory' at 0x0000022F716D69A8>,
    '_details_key': '',
    '_initpath': '/library/sections/2/firstCharacter',
    '_server': <PlexServer:http://127.0.0.1:324>,
    'key': '%23',
    'size': '16',
    'title': '#'}
"""

@blacktwin
Copy link
Collaborator Author

With the removal of the hardcoded ALLOWED_FILTERS ALLOWED_SORT and BOOLEAN_FILTER searching and syncing may take longer and cause an additional query but the upside should be that these lists are now dynamic.

data = self._server.query(key)
for meta in data.iter('Meta'):
for metaType in meta.iter('Type'):
if mediaType and metaType.attrib.get('type') == mediaType:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify this one.

if not mediatype or ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that one was tripping me up. I'm repeating the same for loop for both but I get the mediaType isolated when called. I'll move this PR to draft while I figure it out. I'm open to suggestions, of course.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What your doing is fine, but just use the or so you check both conditions at the same time.

self.firstCharacterKey = data.attrib.get('firstCharacterKey')


class Field(PlexObject):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a class called Field. Maybe change the name or atleast make a better docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah docstrings need updated. I based the name off the xml tagging. Technically they can both exist after 3746b4e . But, yeah, I can change it.

@blacktwin
Copy link
Collaborator Author

blacktwin commented Jul 2, 2020

folders and subfolders method is kinda neat.

for item in plex.library.section('Music').folders():
    for sub in item.subfolders():
        for track in sub.subfolders():
            print(vars(track))

We can get to the media item through the /folder endpoint.

@blacktwin blacktwin mentioned this pull request Sep 9, 2020
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 71.221% when pulling 4f96838 on library_hubs into 737401b on master.

@blacktwin
Copy link
Collaborator Author

With the exception of the decrease in coverage, this PR is gtg.

@Hellowlol Hellowlol merged commit 6a5981c into master Oct 1, 2020
@jjlawren jjlawren mentioned this pull request Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants