diff --git a/resources/lib/managers/catchup_manager.py b/resources/lib/managers/catchup_manager.py index 21dc40a..c786540 100644 --- a/resources/lib/managers/catchup_manager.py +++ b/resources/lib/managers/catchup_manager.py @@ -4,7 +4,7 @@ from lib.providers import get_provider from lib.router import router -from lib.utils.gui import create_directory_items +from lib.utils.gui import create_list_item class CatchupManager: @@ -17,31 +17,35 @@ def __init__(self): def get_channels(self) -> list: """Return channels available for catchup TV.""" channels = self.provider.get_catchup_channels() - directory_items = create_directory_items(channels) - succeeded = xbmcplugin.addDirectoryItems(router.handle, directory_items, len(directory_items)) - xbmcplugin.endOfDirectory(router.handle, succeeded) + for channel in channels: + xbmcplugin.addDirectoryItem(router.handle, channel["path"], create_list_item(channel, True), True) + + xbmcplugin.endOfDirectory(router.handle) def get_categories(self, catchup_channel_id: str) -> list: """Return content categories for the required channel.""" categories = self.provider.get_catchup_categories(catchup_channel_id) - directory_items = create_directory_items(categories) - succeeded = xbmcplugin.addDirectoryItems(router.handle, directory_items, len(directory_items)) - xbmcplugin.endOfDirectory(router.handle, succeeded) + for category in categories: + xbmcplugin.addDirectoryItem(router.handle, category["path"], create_list_item(category, True), True) + + xbmcplugin.endOfDirectory(router.handle) def get_articles(self, catchup_channel_id: str, category_id: str) -> list: """Return content (TV show, movie, etc) for the required channel and category.""" articles = self.provider.get_catchup_articles(catchup_channel_id, category_id) - directory_items = create_directory_items(articles) - succeeded = xbmcplugin.addDirectoryItems(router.handle, directory_items, len(directory_items)) - xbmcplugin.endOfDirectory(router.handle, succeeded) + for article in articles: + xbmcplugin.addDirectoryItem(router.handle, article["path"], create_list_item(article, True), True) + + xbmcplugin.endOfDirectory(router.handle) def get_videos(self, catchup_channel_id: str, article_id: str) -> list: """Return the video list for the required show.""" videos = self.provider.get_catchup_videos(catchup_channel_id, article_id) - directory_items = create_directory_items(videos) - succeeded = xbmcplugin.addDirectoryItems(router.handle, directory_items, len(directory_items)) - xbmcplugin.endOfDirectory(router.handle, succeeded) + for video in videos: + xbmcplugin.addDirectoryItem(router.handle, video["path"], create_list_item(video)) + + xbmcplugin.endOfDirectory(router.handle) diff --git a/resources/lib/managers/stream_manager.py b/resources/lib/managers/stream_manager.py index f753c6f..0c1c919 100644 --- a/resources/lib/managers/stream_manager.py +++ b/resources/lib/managers/stream_manager.py @@ -1,12 +1,11 @@ """Video stream manager.""" import inputstreamhelper -import xbmcgui import xbmcplugin from lib.providers import get_provider from lib.router import router -from lib.utils.gui import create_video_item +from lib.utils.gui import create_play_item from lib.utils.kodi import localize, ok_dialog @@ -17,32 +16,29 @@ def __init__(self): """Initialize Stream Manager object.""" self.provider = get_provider() - def load_live_stream(self, stream_id: str) -> xbmcgui.ListItem: + def load_live_stream(self, stream_id: str) -> None: """Load live TV stream.""" stream_info = self.provider.get_live_stream_info(stream_id) - if not stream_info: - ok_dialog(localize(30900)) - return - - is_helper = inputstreamhelper.Helper(stream_info["manifest_type"], drm=stream_info["drm"]) - if not is_helper.check_inputstream(): - ok_dialog(localize(30901)) - return + self._load_stream(stream_info) - list_item = create_video_item(stream_info) - xbmcplugin.setResolvedUrl(router.handle, True, list_item) - - def load_chatchup_stream(self, stream_id: str) -> xbmcgui.ListItem: + def load_chatchup_stream(self, stream_id: str) -> None: """Load catchup TV stream.""" stream_info = self.provider.get_catchup_stream_info(stream_id) - if not stream_info: + self._load_stream(stream_info) + + def _load_stream(self, stream_info: dict = None) -> None: + """Load stream.""" + if stream_info is None: ok_dialog(localize(30900)) + xbmcplugin.setResolvedUrl(router.handle, False) return - is_helper = inputstreamhelper.Helper(stream_info["manifest_type"], drm=stream_info["drm"]) - if not is_helper.check_inputstream(): - ok_dialog(localize(30901)) + is_helper = inputstreamhelper.Helper(stream_info["manifest_type"], drm=stream_info["license_type"]) + + if is_helper.check_inputstream(): + play_item = create_play_item(stream_info, is_helper.inputstream_addon) + xbmcplugin.setResolvedUrl(router.handle, True, play_item) return - list_item = create_video_item(stream_info) - xbmcplugin.setResolvedUrl(router.handle, True, list_item) + ok_dialog(localize(30901)) + xbmcplugin.setResolvedUrl(router.handle, False) diff --git a/resources/lib/providers/abstract_orange_provider.py b/resources/lib/providers/abstract_orange_provider.py index 70f7138..3e27d49 100644 --- a/resources/lib/providers/abstract_orange_provider.py +++ b/resources/lib/providers/abstract_orange_provider.py @@ -125,7 +125,6 @@ def get_catchup_channels(self) -> list: return [ { - "is_folder": True, "label": str(channel["name"]).upper(), "path": build_addon_url(f"/channels/{channel['id']}/categories"), "art": {"thumb": channel["logos"]["ref_millenials_partner_white_logo"]}, @@ -140,7 +139,6 @@ def get_catchup_categories(self, catchup_channel_id: str) -> list: return [ { - "is_folder": True, "label": category["name"][0].upper() + category["name"][1:], "path": build_addon_url(f"/channels/{catchup_channel_id}/categories/{category['id']}/articles"), } @@ -156,7 +154,6 @@ def get_catchup_articles(self, catchup_channel_id: str, category_id: str) -> lis return [ { - "is_folder": True, "label": article["title"], "path": build_addon_url(f"/channels/{catchup_channel_id}/articles/{article['id']}/videos"), "art": {"poster": article["covers"]["ref_16_9"]}, @@ -171,7 +168,6 @@ def get_catchup_videos(self, catchup_channel_id: str, article_id: str) -> list: return [ { - "is_folder": False, "label": video["title"], "path": build_addon_url(f"/catchup-streams/{video['id']}"), "art": {"poster": video["covers"]["ref_16_9"]}, @@ -230,7 +226,6 @@ def _get_stream_info(self, stream_type: str, version: str, item_type: str, strea "path": stream_info["url"], "mime_type": "application/xml+dash", "manifest_type": "mpd", - "drm": drm.name.lower(), "license_type": drm.value, "license_key": f"{license_server_url}|{headers}|{post_data}|{response}", } diff --git a/resources/lib/utils/gui.py b/resources/lib/utils/gui.py index 00ae5e6..1f6838d 100644 --- a/resources/lib/utils/gui.py +++ b/resources/lib/utils/gui.py @@ -1,64 +1,49 @@ """Helpers for Kodi GUI.""" from xbmcgui import ListItem -import inputstreamhelper -def create_directory_items(data: list) -> list: - """Create a list of directory items from data.""" - items = [] +def create_list_item(item_data: dict, is_folder: bool = False) -> ListItem: + """Create a list item from data.""" + list_item = ListItem(label=item_data.get("label"), path=item_data.get("path")) + + if "art" in item_data: + item_art_data: dict = item_data.get("art", {}) + list_item.setArt( + { + "poster": item_art_data.get("poster"), + "thumb": item_art_data.get("thumb"), + } + ) + + if not is_folder: + list_item.setProperties( + { + "IsPlayable": "true", + } + ) + + if "info" in item_data: + item_info_data: dict = item_data.get("info", {}) + video_info_tag = list_item.getVideoInfoTag() + video_info_tag.setDuration(item_info_data.get("duration")) + video_info_tag.setGenres(item_info_data.get("genres")) + video_info_tag.setPlot(item_info_data.get("plot")) + video_info_tag.setYear(item_info_data.get("year")) - for d in data: - is_folder = bool(d["is_folder"]) - - list_item = ListItem(label=d["label"], path=d["path"]) - list_item.setIsFolder(is_folder) - - if "art" in d: - list_item.setArt( - { - "poster": d["art"].get("poster", None), - "thumb": d["art"].get("thumb", None), - } - ) - - if not is_folder: - list_item.setProperties( - { - "inputstream": "inputstream.adaptive", - "IsPlayable": "true", - } - ) - - if "info" in d: - video_info_tag = list_item.getVideoInfoTag() - video_info_tag.setDuration(d["info"].get("duration", None)) - video_info_tag.setGenres(d["info"].get("genres", None)) - video_info_tag.setPlot(d["info"].get("plot", None)) - video_info_tag.setYear(d["info"].get("year", None)) - video_info_tag.setPremiered(d["info"].get("premiered", None)) - - items.append((d["path"], list_item, is_folder)) - - return items - - -def create_video_item(stream_info: dict) -> ListItem: - """Create a video item from stream data.""" - - is_helper = inputstreamhelper.Helper(stream_info['manifest_type'], - drm = stream_info["license_type"]) - - if is_helper.check_inputstream(): - list_item = ListItem(path=stream_info["path"]) + return list_item - list_item.setContentLookup(False) - list_item.setMimeType(stream_info["mime_type"]) - list_item.setProperty('inputstream', is_helper.inputstream_addon) +def create_play_item(stream_info: dict, inputstream_addon: str) -> ListItem: + """Create a play item from stream data.""" + play_item = ListItem(path=stream_info["path"]) + play_item.setContentLookup(False) + play_item.setMimeType(stream_info["mime_type"]) - list_item.setProperty('inputstream.adaptive.manifest_type', stream_info['manifest_type']) - list_item.setProperty('inputstream.adaptive.license_type', stream_info["license_type"]) - list_item.setProperty("inputstream.adaptive.license_key", stream_info["license_key"]) + play_item.setProperty("inputstream", inputstream_addon) + # play_item.setProperty("inputstream.adaptive.play_timeshift_buffer", "true") + # play_item.setProperty("inputstream.adaptive.manifest_config", '{"timeshift_bufferlimit":14400}') + play_item.setProperty("inputstream.adaptive.license_type", stream_info["license_type"]) + play_item.setProperty("inputstream.adaptive.license_key", stream_info["license_key"]) - return list_item + return play_item