Skip to content

Commit

Permalink
Fix series
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarnauts committed Sep 28, 2020
1 parent 2c6566f commit da57c04
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
4 changes: 2 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</requires>
<extension point="xbmc.python.pluginsource" library="addon_entry.py">
<provides>video</provides>
<medialibraryscanpath content="movies">library/movies</medialibraryscanpath>
<medialibraryscanpath content="tvshows">library/tvshows</medialibraryscanpath>
<medialibraryscanpath content="movies">library/movies/</medialibraryscanpath>
<medialibraryscanpath content="tvshows">library/tvshows/</medialibraryscanpath>
</extension>
<extension point="xbmc.service" library="service_entry.py"/>
<extension point="xbmc.addon.metadata">
Expand Down
16 changes: 9 additions & 7 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import routing

from resources.lib import kodilogging, kodiutils
from resources.lib.streamz.exceptions import NoLoginException, InvalidLoginException, LoginErrorException, NoTelenetSubscriptionException, \
NoStreamzSubscriptionException
from resources.lib.streamz.exceptions import (NoLoginException, InvalidLoginException, LoginErrorException, NoTelenetSubscriptionException,
NoStreamzSubscriptionException)

kodilogging.config()
routing = routing.Plugin() # pylint: disable=invalid-name
Expand Down Expand Up @@ -109,16 +109,18 @@ def show_catalog_program_season(program, season):
def library_movies():
""" Show a list of all movies for integration into the Kodi Library """
from resources.lib.modules.catalog import Catalog
from resources.lib.streamz import Movie
Catalog().show_catalog_category(content_filter=Movie)
Catalog().show_library_movies()


@routing.route('/library/tvshows')
def library_tvshows():
@routing.route('/library/tvshows/<program>')
def library_tvshows(program=None):
""" Show a list of all tv series for integration into the Kodi Library """
from resources.lib.modules.catalog import Catalog
from resources.lib.streamz import Program
Catalog().show_catalog_category(content_filter=Program)
if program is None:
Catalog().show_library_tvshows()
else:
Catalog().show_program_season(program, -1)


@routing.route('/catalog/recommendations/<storefront>')
Expand Down
31 changes: 28 additions & 3 deletions resources/lib/modules/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from resources.lib import kodiutils
from resources.lib.kodiutils import TitleItem
from resources.lib.modules.menu import Menu
from resources.lib.streamz import Movie, Program
from resources.lib.streamz.api import Api, CACHE_PREVENT
from resources.lib.streamz.auth import Auth
from resources.lib.streamz.exceptions import UnavailableException
Expand Down Expand Up @@ -44,12 +45,11 @@ def show_catalog(self):
# Sort categories by default like in Streamz.
kodiutils.show_listing(listing, 30003, content='files')

def show_catalog_category(self, category=None, content_filter=None):
def show_catalog_category(self, category=None):
""" Show a category in the catalog
:type category: str
:type content_filter: class
"""
items = self._api.get_items(category, content_filter=content_filter)
items = self._api.get_items(category)

listing = []
for item in items:
Expand All @@ -59,6 +59,31 @@ def show_catalog_category(self, category=None, content_filter=None):
# Used for A-Z listing or when movies and episodes are mixed.
kodiutils.show_listing(listing, 30003, content='movies' if category == 'films' else 'tvshows', sort=['label', 'year', 'duration'])

def show_library_movies(self):
""" Show all movies in the catalog. """
items = self._api.get_items(content_filter=Movie)

listing = []
for item in items:
title_item = Menu.generate_titleitem(item)
listing.append(title_item)

kodiutils.show_listing(listing, 30003, content='movies', sort=['label', 'year', 'duration'])

def show_library_tvshows(self):
""" Show all tvshows in the catalog. """
items = self._api.get_items(content_filter=Program)

listing = []
for item in items:
title_item = Menu.generate_titleitem(item)
# Add a trailing slash since Kodi seems to store the tvshows in the database with a trailing slash
# If we don't do this, the hash will not validate and everything will be rescanned
title_item.path = kodiutils.url_for('library_tvshows', program=item.program_id) + '/'
listing.append(title_item)

kodiutils.show_listing(listing, 30003, content='tvshows', sort=['label', 'year', 'duration'])

def show_program(self, program):
""" Show a program from the catalog
:type program: str
Expand Down
7 changes: 6 additions & 1 deletion resources/lib/streamz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import absolute_import, division, unicode_literals

import hashlib
import json
import logging

Expand Down Expand Up @@ -216,6 +217,9 @@ def get_program(self, program_id, cache=CACHE_AUTO):

channel = self._parse_channel(program.get('channelLogoUrl'))

# Calculate a hash value of the ids of all episodes
program_hash = hashlib.md5()

seasons = {}
for item_season in program.get('seasons', []):
episodes = {}
Expand All @@ -239,6 +243,7 @@ def get_program(self, program_id, cache=CACHE_AUTO):
progress=item_episode.get('playerPositionSeconds', 0),
watched=item_episode.get('doneWatching', False),
)
program_hash.update(item_episode.get('id'))

seasons[item_season.get('index')] = Season(
number=item_season.get('index'),
Expand All @@ -260,7 +265,7 @@ def get_program(self, program_id, cache=CACHE_AUTO):
seasons=seasons,
channel=channel,
legal=program.get('legalIcons'),
content_hash='', # TODO: set hash
content_hash=program_hash.hexdigest().upper(),
)

@staticmethod
Expand Down

0 comments on commit da57c04

Please sign in to comment.