Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add label methods, properties to Episodes #868

Closed
wants to merge 2 commits into from

Conversation

glensc
Copy link
Contributor

@glensc glensc commented Jan 10, 2022

Description

Seems LabelMixin was added to Album, Collection, Show, and Movie, but left out of Episode.

My testing with 1.24.3.5033-757abe6b4 shows that Episodes can also have labels.

>>> episode.addLabel(['skip-pts'])
>>> episode = (fetch episode again)
>>> print(episode.labels)
[<Label:/library/sections/2/:Skip-pts>]

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the docstring for new or existing methods
  • I have added tests when applicable

@JonnyWong16
Copy link
Collaborator

JonnyWong16 commented Jan 10, 2022

Labels were not added to episodes because you can't add them in the Plex UI.

There may be unexpected issues/bugs with sharing label restrictions because Plex isn't designed to support episodes.

@glensc
Copy link
Contributor Author

glensc commented Jan 10, 2022

Additionally, seems Plex doesn't find any matches for episodes even you can do filter episodes by label (Under Advanced Filters)

image

@JonnyWong16
Copy link
Collaborator

The Label filter is for shows (show.label).

image

@meisnate12
Copy link
Contributor

meisnate12 commented Jan 10, 2022

so as far as i can tell episode.label does work in the filter string but you cant do it though the UI or through any of the standard ways to make a smart collection using the plexapi but i was able to get it working with the following code. You could do something similar if you want it to be in a search. Use it at your own risk.

from plexapi.server import PlexServer
from plexapi import utils


PLEX_URL = ""
PLEX_TOKEN = ""
PLEX_LIBRARY = ""
EPISODE_LABEL = ""
COLLECTION_NAME = ""

ps = PlexServer(PLEX_URL, PLEX_TOKEN, timeout=600)
lib = next((s for s in ps.library.sections() if s.title == PLEX_LIBRARY), None)

if lib:
    key = None
    for choice in lib.listFilterChoices("label"):
        if choice.title == EPISODE_LABEL:
            key = choice.key
            break
    if key:
        args = {
            "type": 4,
            "title": COLLECTION_NAME,
            "smart": 1,
            "sectionId": lib.key,
            "uri": f"server://{ps.machineIdentifier}/com.plexapp.plugins.library/library/sections/{lib.key}/all?type=4&episode.label={key}"
        }
        ps.query(f"/library/collections{utils.joinArgs(args)}", method=ps._session.post)

plexapi/video.py Outdated Show resolved Hide resolved
plexapi/video.py Show resolved Hide resolved
@JonnyWong16
Copy link
Collaborator

Add test.

https://github.com/pkkid/python-plexapi/blob/master/tests/test_video.py#L1151

test_mixins.edit_label(episode)

@glensc
Copy link
Contributor Author

glensc commented Jan 12, 2022

Test added 874d6e2

@glensc
Copy link
Contributor Author

glensc commented Jan 12, 2022

Are the errors really from this PR?


=================================== FAILURES ===================================
_______________ test_library_section_totalViewSize[anonymously] ________________
Traceback (most recent call last):
  File "/home/runner/work/python-plexapi/python-plexapi/tests/test_library.py", line 98, in test_library_section_totalViewSize
    assert tvshows.totalViewSize() == 3
AssertionError: assert 2 == 3
  +2
  -3
________________ test_library_editAdvanced_default[anonymously] ________________
Traceback (most recent call last):
  File "/home/runner/work/python-plexapi/python-plexapi/plexapi/library.py", line 655, in editAdvanced
    enums = idEnums[settingID]
KeyError: 'collectionMode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/work/python-plexapi/python-plexapi/tests/test_library.py", line 417, in test_library_editAdvanced_default
    movies.editAdvanced(collectionMode=0)
  File "/home/runner/work/python-plexapi/python-plexapi/plexapi/library.py", line 657, in editAdvanced
    raise NotFound('%s not found in %s' % (value, list(idEnums.keys())))
plexapi.exceptions.NotFound: 0 not found in ['hidden', 'enableCinemaTrailers', 'country', 'originalTitles', 'localizedArtwork', 'useLocalAssets', 'respectTags', 'useExternalExtras', 'skipNonTrailerExtras', 'useRedbandTrailers', 'includeExtrasWithLocalizedSubtitles', 'includeAdultContent', 'autoCollectionThreshold', 'ratingsSource', 'enableBIFGeneration']
_______________________ test_server_search[anonymously] ________________________
Traceback (most recent call last):
  File "/home/runner/work/python-plexapi/python-plexapi/tests/test_server.py", line 149, in test_server_search
    assert plex.search(title)
AssertionError: assert []
 +  where [] = <bound method PlexServer.search of <PlexServer:http://127.0.0.1:324>>('Elephants Dream')
 +    where <bound method PlexServer.search of <PlexServer:http://127.0.0.1:324>> = <PlexServer:http://127.0.0.1:324>.search
_____________ test_that_reload_return_the_same_object[anonymously] _____________
Traceback (most recent call last):
  File "/home/runner/work/python-plexapi/python-plexapi/tests/test_video.py", line 1172, in test_that_reload_return_the_same_object
    movie_search = plex.search("Elephants Dream")[0]
IndexError: list index out of range

@glensc
Copy link
Contributor Author

glensc commented Jan 12, 2022

EDIT: nevermind, the last CI job has passed OK:

@JonnyWong16
Copy link
Collaborator

Combined into PR #872 so it's all in one PR.

@glensc glensc deleted the episode-label branch February 28, 2022 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants