def PLAY(params): log.debug("== ENTER: PLAY ==") log.debug("PLAY ACTION PARAMS: {0}", params) item_id = params.get("item_id") auto_resume = int(params.get("auto_resume", "-1")) log.debug("AUTO_RESUME: {0}", auto_resume) forceTranscode = params.get("force_transcode", None) is not None log.debug("FORCE_TRANSCODE: {0}", forceTranscode) media_source_id = params.get("media_source_id", "") log.debug("media_source_id: {0}", media_source_id) use_default = params.get("use_default", "false") == "true" log.debug("use_default: {0}", use_default) # set the current playing item id # set all the playback info, this will be picked up by the service # the service will then start the playback xbmc.Player().stop() play_info = {} play_info["item_id"] = item_id play_info["auto_resume"] = str(auto_resume) play_info["force_transcode"] = forceTranscode play_info["media_source_id"] = media_source_id play_info["use_default"] = use_default send_event_notification("embycon_play_action", play_info)
def send_next_episode_details(item): next_episode = get_next_episode(item) if next_episode is None: log.debug("No next episode") return gui_options = {} gui_options["server"] = download_utils.getServer() gui_options["name_format"] = None gui_options["name_format_type"] = "" item_details = extract_item_info(item, gui_options) next_item_details = extract_item_info(next_episode, gui_options) current_item = {} current_item["id"] = item_details.id current_item["title"] = item_details.name current_item["image"] = item_details.art.get('tvshow.poster', '') current_item["thumb"] = item_details.art.get('thumb', '') current_item["fanartimage"] = item_details.art.get('tvshow.fanart', '') current_item["overview"] = item_details.plot current_item["tvshowtitle"] = item_details.series_name current_item["playcount"] = item_details.play_count current_item["season"] = item_details.season_number current_item["episode"] = item_details.episode_number current_item["rating"] = item_details.critic_rating current_item["year"] = item_details.year next_item = {} next_item["id"] = next_item_details.id next_item["title"] = next_item_details.name next_item["image"] = next_item_details.art.get('tvshow.poster', '') next_item["thumb"] = next_item_details.art.get('thumb', '') next_item["fanartimage"] = next_item_details.art.get('tvshow.fanart', '') next_item["overview"] = next_item_details.plot next_item["tvshowtitle"] = next_item_details.series_name next_item["playcount"] = next_item_details.play_count next_item["season"] = next_item_details.season_number next_item["episode"] = next_item_details.episode_number next_item["rating"] = next_item_details.critic_rating next_item["year"] = next_item_details.year next_info = { "current_item": current_item, "next_item": next_item } log.debug("send_next_episode_details: {0}", next_info) send_event_notification("embycon_next_episode", next_info)
def getContent(url, params): log.debug("== ENTER: getContent ==") media_type = params.get("media_type", None) if not media_type: xbmcgui.Dialog().ok(i18n('error'), i18n('no_media_type')) log.debug("URL: {0}", url) log.debug("MediaType: {0}", media_type) pluginhandle = int(sys.argv[1]) settings = xbmcaddon.Addon() # determine view type, map it from media type to view type view_type = "" content_type = "" media_type = str(media_type).lower().strip() if media_type.startswith("movie"): view_type = "Movies" content_type = 'movies' elif media_type == "musicalbums": view_type = "Albums" content_type = 'albums' elif media_type == "musicartists": view_type = "Artists" content_type = 'artists' elif media_type == "musicartist": view_type = "Albums" content_type = 'albums' elif media_type == "music" or media_type == "audio" or media_type == "musicalbum": view_type = "Music" content_type = 'songs' elif media_type.startswith("boxsets"): view_type = "Movies" content_type = 'sets' elif media_type.startswith("boxset"): view_type = "BoxSets" content_type = 'movies' elif media_type == "tvshows": view_type = "Series" content_type = 'tvshows' elif media_type == "series": view_type = "Seasons" content_type = 'seasons' elif media_type == "season" or media_type == "episodes": view_type = "Episodes" content_type = 'episodes' log.debug("media_type:{0} content_type:{1} view_type:{2} ", media_type, content_type, view_type) # show a progress indicator if needed progress = None if (settings.getSetting('showLoadProgress') == "true"): progress = xbmcgui.DialogProgress() progress.create(i18n('loading_content')) progress.update(0, i18n('retrieving_data')) # update url for paging start_index = 0 page_limit = int(settings.getSetting('moviePageSize')) if page_limit > 0 and media_type.startswith("movie"): url_prev = None m = re.search('StartIndex=([0-9]{1,4})', url) if m and m.group(1): log.debug("UPDATING NEXT URL: {0}", url) start_index = int(m.group(1)) log.debug("current_start : {0}", start_index) if start_index > 0: prev_index = start_index - page_limit if prev_index < 0: prev_index = 0 url_prev = re.sub('StartIndex=([0-9]{1,4})', 'StartIndex=' + str(prev_index), url) url_next = re.sub('StartIndex=([0-9]{1,4})', 'StartIndex=' + str(start_index + page_limit), url) log.debug("UPDATING NEXT URL: {0}", url_next) else: log.debug("ADDING NEXT URL: {0}", url) url_next = url + "&StartIndex=" + str(start_index + page_limit) + "&Limit=" + str(page_limit) url = url + "&StartIndex=" + str(start_index) + "&Limit=" + str(page_limit) log.debug("ADDING NEXT URL: {0}", url_next) # use the data manager to get the data result = dataManager.GetContent(url) total_records = 0 if result is not None and isinstance(result, dict): total_records = result.get("TotalRecordCount", 0) dir_items, detected_type = processDirectory(result, progress, params) if dir_items is None: return # add paging items if page_limit > 0 and media_type.startswith("movie"): if url_prev: list_item = xbmcgui.ListItem("Prev Page (" + str(start_index - page_limit + 1) + "-" + str(start_index) + " of " + str(total_records) + ")") u = sys.argv[0] + "?url=" + urllib.quote(url_prev) + "&mode=GET_CONTENT&media_type=movies" dir_items.insert(0, (u, list_item, True)) if start_index + page_limit < total_records: upper_count = start_index + (page_limit * 2) if upper_count > total_records: upper_count = total_records list_item = xbmcgui.ListItem("Next Page (" + str(start_index + page_limit + 1) + "-" + str(upper_count) + " of " + str(total_records) + ")") u = sys.argv[0] + "?url=" + urllib.quote(url_next) + "&mode=GET_CONTENT&media_type=movies" dir_items.append((u, list_item, True)) # set the Kodi content type if content_type: xbmcplugin.setContent(pluginhandle, content_type) elif detected_type is not None: # if the media type is not set then try to use the detected type log.debug("Detected content type: {0}", detected_type) if detected_type == "Movie": view_type = "Movies" content_type = 'movies' if detected_type == "Episode": view_type = "Episodes" content_type = 'episodes' xbmcplugin.setContent(pluginhandle, content_type) # set the sort items if page_limit > 0 and media_type.startswith("movie"): xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_UNSORTED) else: setSort(pluginhandle, view_type) xbmcplugin.addDirectoryItems(pluginhandle, dir_items) xbmcplugin.endOfDirectory(pluginhandle, cacheToDisc=False) # send display items event display_items_notification = {"view_type": view_type} send_event_notification("display_items", display_items_notification) if (progress != None): progress.update(100, i18n('done')) progress.close() return
def getContent(url, params): log.debug("== ENTER: getContent ==") media_type = params.get("media_type", None) if not media_type: xbmcgui.Dialog().ok(i18n('error'), i18n('no_media_type')) log.debug("URL: {0}", url) log.debug("MediaType: {0}", media_type) pluginhandle = int(sys.argv[1]) settings = xbmcaddon.Addon() # determine view type, map it from media type to view type viewType = "" media_type = str(media_type).lower().strip() if media_type.startswith("movie"): viewType = "Movies" xbmcplugin.setContent(pluginhandle, 'movies') elif media_type == "musicalbums": viewType = "Albums" xbmcplugin.setContent(pluginhandle, 'albums') elif media_type == "musicartists": viewType = "Artists" xbmcplugin.setContent(pluginhandle, 'artists') elif media_type == "musicartist": viewType = "Albums" xbmcplugin.setContent(pluginhandle, 'albums') elif media_type == "music" or media_type == "audio" or media_type == "musicalbum": viewType = "Music" xbmcplugin.setContent(pluginhandle, 'songs') elif media_type.startswith("boxsets"): viewType = "Movies" xbmcplugin.setContent(pluginhandle, 'sets') elif media_type.startswith("boxset"): viewType = "BoxSets" xbmcplugin.setContent(pluginhandle, 'movies') elif media_type == "tvshows": viewType = "Series" xbmcplugin.setContent(pluginhandle, 'tvshows') elif media_type == "series": viewType = "Seasons" xbmcplugin.setContent(pluginhandle, 'seasons') elif media_type == "season" or media_type == "episodes": viewType = "Episodes" xbmcplugin.setContent(pluginhandle, 'episodes') log.debug("ViewType: {0} media_type: {1}", viewType, media_type) # show a progress indicator if needed progress = None if (settings.getSetting('showLoadProgress') == "true"): progress = xbmcgui.DialogProgress() progress.create(i18n('loading_content')) progress.update(0, i18n('retrieving_data')) # use the data manager to get the data result = dataManager.GetContent(url) dirItems = processDirectory(result, progress, params) if dirItems is None: return # set the sort items setSort(pluginhandle, viewType) xbmcplugin.addDirectoryItems(pluginhandle, dirItems) xbmcplugin.endOfDirectory(pluginhandle, cacheToDisc=False) # send display items event display_items_notification = {"view_type": viewType} send_event_notification("display_items", display_items_notification) if (progress != None): progress.update(100, i18n('done')) progress.close() return
def promptForStopActions(item_id, current_possition): settings = xbmcaddon.Addon() prompt_next_percentage = int(settings.getSetting('promptPlayNextEpisodePercentage')) play_prompt = settings.getSetting('promptPlayNextEpisodePercentage_prompt') == "true" prompt_delete_episode_percentage = int(settings.getSetting('promptDeleteEpisodePercentage')) prompt_delete_movie_percentage = int(settings.getSetting('promptDeleteMoviePercentage')) # everything is off so return if (prompt_next_percentage == 100 and prompt_delete_episode_percentage == 100 and prompt_delete_movie_percentage == 100): return jsonData = download_utils.downloadUrl("{server}/emby/Users/{userid}/Items/" + item_id + "?format=json") result = json.loads(jsonData) if result is None: log.debug("promptForStopActions failed! no result from server.") return prompt_to_delete = False runtime = result.get("RunTimeTicks", 0) # if no runtime we cant calculate perceantge so just return if runtime == 0: log.debug("No runtime so returing") return # item percentage complete percenatge_complete = int(((current_possition * 10000000) / runtime) * 100) log.debug("Episode Percentage Complete: {0}", percenatge_complete) if (prompt_delete_episode_percentage < 100 and result.get("Type", "na") == "Episode" and percenatge_complete > prompt_delete_episode_percentage): prompt_to_delete = True if (prompt_delete_movie_percentage < 100 and result.get("Type", "na") == "Movie" and percenatge_complete > prompt_delete_movie_percentage): prompt_to_delete = True if prompt_to_delete: log.debug("Prompting for delete") delete(result) # prompt for next episode if (prompt_next_percentage < 100 and result.get("Type", "na") == "Episode" and percenatge_complete > prompt_next_percentage): next_episode = get_next_episode(result) if next_episode is not None: resp = True index = next_episode.get("IndexNumber", -1) if play_prompt: next_epp_name = "%02d - %s" % (index, next_episode.get("Name", "n/a")) resp = xbmcgui.Dialog().yesno(i18n("play_next_title"), i18n("play_next_question"), next_epp_name, autoclose=10000) if resp: next_item_id = next_episode.get("Id") log.debug("Playing Next Episode: {0}", next_item_id) play_info = {} play_info["item_id"] = next_item_id play_info["auto_resume"] = "-1" play_info["force_transcode"] = False send_event_notification("embycon_play_action", play_info)