Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
feat(shows): add support for tv shows (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Mar 10, 2024
1 parent 67a47bd commit f1da472
Show file tree
Hide file tree
Showing 21 changed files with 516 additions and 168 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,16 @@ jobs:
env:
PLEXAPI_PLEXAPI_TIMEOUT: "60"
id: bootstrap
uses: LizardByte/plexhints@v2023.1226.203406
uses: LizardByte/plexhints@v2024.129.31313
with:
additional_server_queries_put: >-
/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2Cdev.lizardbyte.themerr-plex
/system/agents/com.plexapp.agents.themoviedb/config/1?order=com.plexapp.agents.themoviedb%2Cdev.lizardbyte.themerr-plex
additional_server_queries: >-
put|/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2Cdev.lizardbyte.themerr-plex
put|/system/agents/com.plexapp.agents.themoviedb/config/1?order=com.plexapp.agents.themoviedb%2Cdev.lizardbyte.themerr-plex
put|/system/agents/com.plexapp.agents.themoviedb/config/2?order=com.plexapp.agents.themoviedb%2Cdev.lizardbyte.themerr-plex
put|/system/agents/com.plexapp.agents.thetvdb/config/2?order=com.plexapp.agents.thetvdb%2Cdev.lizardbyte.themerr-plex
get|/:/plugins/dev.lizardbyte.themerr-plex/prefs/set?bool_overwrite_plex_provided_themes=true
plugin_bundles_to_install: >-
Themerr-plex.bundle
without_shows: true
without_music: true
without_photos: true

Expand All @@ -211,7 +213,6 @@ jobs:
run: |
python -m pytest \
-rxXs \
--maxfail=1 \
--tb=native \
--verbose \
--cov=Contents/Code \
Expand Down
50 changes: 35 additions & 15 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
from plexhints.decorator_kit import handler # decorator kit
from plexhints.locale_kit import Locale
from plexhints.log_kit import Log # log kit
from plexhints.model_kit import Movie # model kit
from plexhints.model_kit import MetadataModel # model kit
from plexhints.object_kit import MessageContainer, MetadataSearchResult, SearchResult # object kit
from plexhints.prefs_kit import Prefs # prefs kit

# imports from Libraries\Shared
from typing import Optional
from typing import Optional, Union

try:
# get the original Python builtins module
Expand Down Expand Up @@ -195,9 +195,9 @@ def Start():
start_queue_threads() # start queue threads
Log.Debug('queue threads started.')

if Prefs['bool_plex_movie_support']:
if Prefs['bool_plex_movie_support'] or Prefs['bool_plex_series_support']:
plex_listener() # start watching plex
Log.Debug('plex_listener started, watching for activity from new Plex Movie agent.')
Log.Debug('plex_listener started, watching for activity from new Plex agents.')

setup_scheduling() # start scheduled tasks
Log.Debug('scheduled tasks started.')
Expand All @@ -216,9 +216,9 @@ def main():
pass


class Themerr(Agent.Movies):
class Themerr(object):
"""
Class representing the Themerr-plex Movie Agent.
Class representing the Themerr-plex Agent.
This class defines the metadata agent. See the archived Plex documentation
`Defining an agent class
Expand Down Expand Up @@ -270,9 +270,12 @@ class Themerr(Agent.Movies):
accepts_from = []
contributes_to = contributes_to

@staticmethod
def search(results, media, lang, manual):
# type: (SearchResult, Media.Movie, str, bool) -> Optional[SearchResult]
def __init__(self, *args, **kwargs):
super(Themerr, self).__init__(*args, **kwargs)
self.agent_type = "movies" if isinstance(self, Agent.Movies) else "tv_shows"

def search(self, results, media, lang, manual):
# type: (SearchResult, Union[Media.Movie, Media.TV_Show], str, bool) -> Optional[SearchResult]
"""
Search for an item.
Expand All @@ -286,7 +289,7 @@ def search(results, media, lang, manual):
----------
results : SearchResult
An empty container that the developer should populate with potential matches.
media : Media.Movie
media : Union[Media.Movie, Media.TV_Show]
An object containing hints to be used when performing the search.
lang : str
A string identifying the user’s currently selected language. This will be one of the constants added to the
Expand Down Expand Up @@ -319,14 +322,18 @@ def search(results, media, lang, manual):
if media.primary_agent == 'dev.lizardbyte.retroarcher-plex':
media_id = 'games-%s' % re.search(r'((igdb)-(\d+))', media.primary_metadata.id).group(1)
else:
media_id = 'movies-%s-%s' % (media.primary_agent.rsplit('.', 1)[-1], media.primary_metadata.id)
media_id = '{}-{}-{}'.format(
self.agent_type,
media.primary_agent.rsplit('.', 1)[-1],
media.primary_metadata.id
)
# e.g. = 'movies-imdb-tt0113189'
# e.g. = 'movies-themoviedb-710'

results.Append(MetadataSearchResult(
id=media_id,
name=media.primary_metadata.title,
year=media.primary_metadata.year,
year=getattr(media.primary_metadata, 'year', None), # TV Shows don't have a year attribute
score=100,
lang=lang, # no lang to get from db
thumb=None # no point in adding thumb since plex won't show it anywhere
Expand All @@ -339,7 +346,7 @@ def search(results, media, lang, manual):

@staticmethod
def update(metadata, media, lang, force):
# type: (Movie, Media.Movie, str, bool) -> Optional[Movie]
# type: (MetadataModel, Union[Media.Movie, Media.TV_Show], str, bool) -> MetadataModel
"""
Update metadata for an item.
Expand All @@ -351,10 +358,10 @@ def update(metadata, media, lang, force):
Parameters
----------
metadata : object
metadata : MetadataModel
A pre-initialized metadata object if this is the first time the item is being updated, or the existing
metadata object if the item is being refreshed.
media : object
media : Union[Media.Movie, Media.TV_Show]
An object containing information about the media hierarchy in the database.
lang : str
A string identifying which language should be used for the metadata. This will be one of the constants
Expand All @@ -363,6 +370,11 @@ def update(metadata, media, lang, force):
A boolean value identifying whether the user forced a full refresh of the metadata. If this argument is
``True``, all metadata should be refreshed, regardless of whether it has been populated previously.
Returns
-------
MetadataModel
The metadata object.
Examples
--------
>>> Themerr().update(metadata=..., media=..., lang='en', force=True)
Expand All @@ -375,3 +387,11 @@ def update(metadata, media, lang, force):
update_plex_item(rating_key=rating_key)

return metadata


class ThemerrMovies(Themerr, Agent.Movies):
agent_type_verbose = "Movies"


class ThemerrTvShows(Themerr, Agent.TV_Shows):
agent_type_verbose = "TV"
15 changes: 10 additions & 5 deletions Contents/Code/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
themerr_data_directory = os.path.join(plugin_support_data_directory, plugin_identifier, 'DataItems')

contributes_to = [
'tv.plex.agents.movie',
'com.plexapp.agents.imdb',
'com.plexapp.agents.themoviedb',
# 'com.plexapp.agents.thetvdb', # not available as movie agent
'dev.lizardbyte.retroarcher-plex'
'tv.plex.agents.movie', # new movie agent
'tv.plex.agents.series', # new tv show agent
'com.plexapp.agents.imdb', # legacy movie agent
'com.plexapp.agents.themoviedb', # legacy movie and tv show agent
'com.plexapp.agents.thetvdb', # legacy tv show agent
'dev.lizardbyte.retroarcher-plex' # retroarcher plugin
]

guid_map = dict(
Expand Down Expand Up @@ -85,13 +86,15 @@
game_franchises='[GAME FRANCHISE]: ',
movies='[MOVIE]: ',
movie_collections='[MOVIE COLLECTION]: ',
tv_shows='[TV SHOW]: ',
)
url_prefix = dict(
games='https://www.igdb.com/games/',
game_collections='https://www.igdb.com/collections/',
game_franchises='https://www.igdb.com/franchises/',
movies='https://www.themoviedb.org/movie/',
movie_collections='https://www.themoviedb.org/collection/',
tv_shows='https://www.themoviedb.org/tv/',
)

# two additional strings to fill in later, item title and item url
Expand All @@ -109,6 +112,8 @@
movie_collections='{}&labels={}&template={}&title={}{}&{}={}{}'.format(
base_url, issue_label, issue_template, title_prefix['movie_collections'], '{}', url_name,
url_prefix['movie_collections'], '{}'),
tv_shows='{}&labels={}&template={}&title={}{}&{}={}{}'.format(
base_url, issue_label, issue_template, title_prefix['tv_shows'], '{}', url_name, url_prefix['tv_shows'], '{}'),
)

media_type_dict = dict(
Expand Down
3 changes: 3 additions & 0 deletions Contents/Code/default_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

default_prefs = dict(
bool_plex_movie_support='True',
bool_plex_series_support='True',
bool_overwrite_plex_provided_themes='False',
bool_prefer_mp4a_codec='True',
bool_remove_unused_theme_songs='True',
bool_remove_unused_art='False',
bool_remove_unused_posters='False',
bool_auto_update_items='True',
bool_auto_update_movie_themes='True',
bool_auto_update_tv_themes='True',
bool_auto_update_collection_themes='True',
bool_update_collection_metadata_plex_movie='False',
bool_update_collection_metadata_legacy='True',
Expand Down
Loading

0 comments on commit f1da472

Please sign in to comment.