def showAudioBibleBookJson(book_num): lang_code = jw_config.const[jw_config.language]["lang_code"] json_url = jw_config.app_url json_url = json_url + lang_code json_url = json_url + "_TRGCHlZRQVNYVrXF?output=json&pub=bi12&fileformat=MP3&alllangs=0&langwritten=" json_url = json_url + lang_code json_url = json_url + "&txtCMSLang=" json_url = json_url + lang_code json_url = json_url + "&booknum=" json_url = json_url + book_num json = jw_common.loadJsonFromUrl(url = json_url, ajax = False, month_cache = True) lang_code = lang_code book_name = json["pubName"] cover_url = json["pubImage"]["url"] for mp3 in json["files"][lang_code]["MP3"]: # Skip 'zip' files if mp3["mimetype"] != "audio/mpeg": continue params = { "content_type" : "audio", "mode" : "play_mp3", "file_url" : mp3["file"]["url"] } #url = mp3["file"]["url"] url = jw_config.plugin_name + '?' + urllib.urlencode(params) title = book_name + " - " + mp3["title"] listItem = xbmcgui.ListItem( label = title, thumbnailImage = cover_url ) listItem.setInfo( type = 'Music', infoLabels = {'Title': title } ) listItem.setProperty("IsPlayable","true") xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = False ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def showDailyText(date): language = jw_config.language json_url = jw_config.wol_url json_url = json_url + "dt/" json_url = json_url + jw_config.const[language]["wol"] + "/" + date json = jw_common.loadJsonFromUrl(url = json_url, ajax = True) text = json["items"][0]["content"] text = jw_common.cleanUpText(text) dialog = DailiyText() dialog.customInit(text) dialog.doModal() del dialog
def showWeekProgram(date): language = jw_config.language json_url = jw_config.wol_url json_url = json_url + "dt/" json_url = json_url + jw_config.const[language]["wol"] + "/" + date json = jw_common.loadJsonFromUrl(url = json_url, ajax = True) text = "[COLOR=FF0000FF][B]" + jw_common.t(30035) + "[/B][/COLOR]\n" text = text + json["items"][1]["content"] # there is a trailing \n in the item text text = text + "[COLOR=FF0000FF][B]" + jw_common.t(30028) + "[/B][/COLOR]" text = text + "\n" + json["items"][2]["content"] text = jw_common.cleanUpText(text).encode("utf8") dialog = WeekProgram() dialog.customInit(text) dialog.doModal() del dialog
def showVideoJsonUrl(json_url, thumb): language = jw_config.language json_url = json_url json = jw_common.loadJsonFromUrl(url = json_url, ajax = False, month_cache = True) max_resolution = xbmcplugin.getSetting(jw_config.plugin_pid, "max_resolution") # json equals to [] when a cached json was empty if json is None or json == [] : string = jw_common.t(30033) + " " xbmcgui.Dialog().ok("jworg browser", string) return language_code = jw_config.const[language]["lang_code"] # Case: "Bible from Japan" Video # No speak, so no language, so only one "" entry suitable for every language if len(json["languages"]) == 0: language_code = "" try : temp = json["files"][language_code] except : try: temp = json["files"]["univ"] language_code = "univ" except: # e.g. http://www.jw.org/apps/TRGCHlZRQVNYVrXF?docid=802014548&output=json&fileformat=mp4&alllangs=1&track=1&langwritten=I&txtCMSLang=I temp = json["files"]["E"] language_code = "E" pass # Create in memory dict of dict with all available videos video_dict = {} for mp4 in json["files"][language_code]["MP4"]: res = mp4["label"] url_to_play = mp4["file"]["url"] mp4_title_cleaned = jw_common.cleanUpText (mp4["title"]) title = "[" + res + "] - " + mp4_title_cleaned if res not in video_dict : video_dict[res] = {} video_dict[res].update({mp4_title_cleaned: url_to_play}) # Try do autodetect the video to play basaed on user setting of # default video resolution list_only = False if (max_resolution != "0" and max_resolution != "") or max_resolution is None : right_resoluction_dict = None max_resolution = max_resolution + "p" # If found default resolution video, I use this # else I use the latest added (because it's the the highest) res available if max_resolution in video_dict is not None : right_resoluction_dict = video_dict[max_resolution] else : max_resolution, right_resoluction_dict = video_dict.popitem() # If I've only one video at right res, I play It if len(right_resoluction_dict) == 1 : title, url_to_play = right_resoluction_dict.popitem() listItem = xbmcgui.ListItem( label = title ) listItem.setInfo( type = 'Video', infoLabels = {'Title': mp4_title_cleaned} ) xbmc.Player().play(item=url_to_play, listitem=listItem) return # This is an error condition, could not verify never ... elif len(right_resoluction_dict) == 0 : xbmc.log("JWORG: NO one video at res " + max_resolution, xbmc.LOGERROR) # There are many video at the right res: enable listing of ONLY these else : list_only = max_resolution # Standard listing code for mp4 in json["files"][language_code]["MP4"]: url = mp4["file"]["url"] res = mp4["label"] mp4_title_cleaned = jw_common.cleanUpText (mp4["title"]) title = "[" + res + "] - " + mp4_title_cleaned if (list_only is not False) and (res != max_resolution) : # if user has choosen a res, and there are more than one video on this res # I skip every video of different resolution, but show a list # of all available video of this resolution continue listItem = xbmcgui.ListItem( label = title, thumbnailImage = thumb ) listItem.setInfo( type = 'Video', infoLabels = {'Title': mp4_title_cleaned} ) listItem.setProperty("IsPlayable","true") xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = False ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def setVideoUrl(main_video_title, json_url, thumb) : language = jw_config.language json_url = "http://www.jw.org" + json_url json = jw_common.loadJsonFromUrl(url = json_url, ajax = False, month_cache = True) max_resolution = xbmcplugin.getSetting(jw_config.plugin_pid, "max_resolution") max_resolution_string = max_resolution + "p" # json equals to [] when a cached json was empty if json is None or json == [] : string = jw_common.t(30033) + " " xbmcgui.Dialog().ok("Jw.org audio/video browser", string) return language_code = jw_config.const[language]["lang_code"] # Case: "Bible from Japan" Video # No speak, so no language, so only one "" entry suitable for every language if len(json["languages"]) == 0: language_code = "" try : temp = json["files"][language_code] except : try: temp = json["files"]["univ"] except: # e.g. http://www.jw.org/apps/TRGCHlZRQVNYVrXF?docid=802014548&output=json&fileformat=mp4&alllangs=1&track=1&langwritten=I&txtCMSLang=I temp = json["files"]["E"] pass video_dict = {} xbmc.log ("JWORG: json_url " + json_url.encode("utf-8"), xbmc.LOGERROR) for mp4 in temp["MP4"]: res = mp4["label"] url_to_play = mp4["file"]["url"] mp4_title_cleaned = jw_common.cleanUpText (mp4["title"]) title = mp4_title_cleaned + " [" + res + "]" if mp4_title_cleaned not in video_dict : video_dict[mp4_title_cleaned] = {} if res not in video_dict[mp4_title_cleaned] : video_dict[mp4_title_cleaned][res] = {} video_dict[mp4_title_cleaned][res] = {"title" : title, "full_title" : mp4_title_cleaned, "url" : url_to_play, "resolution" : res } if max_resolution == '0' : addVideoFolderItem(main_video_title, json_url, thumb ) return if (len(video_dict) ==1) : # good, only one video title if max_resolution_string in video_dict[mp4_title_cleaned] : # max resolution available ! addPlayableItem(video_dict[mp4_title_cleaned][max_resolution_string], thumb ) else : # look max resolution available under the choosen one for available_res in video_dict[mp4_title_cleaned] : if available_res < max_resolution_string : addPlayableItem(video_dict[mp4_title_cleaned][available_res], thumb ) break else : # more then one video related to this title - show the list addVideoFolderItem(main_video_title, json_url, thumb ) return