def showVideoFilter(): language = jw_config.language # jw_common.getUrl(language) ends with "/" it's something like "http://www.jw.org/it/" url = jw_common.getUrl(language) + jw_config.const[language]["video_path"] html = jw_common.loadUrl(url) regexp_video_filters = '<option data-priority.* value="([^"]+)">([^<]+)</option>' filters = re.findall(regexp_video_filters, html) # Output video filter list for video_filter in filters: title = jw_common.cleanUpText( video_filter[1] ) listItem = xbmcgui.ListItem( title ) params = { "content_type" : "video", "mode" : "open_video_index", "start" : 0, "video_filter" : video_filter[0] } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def showNewsPage(url): url = "http://www.jw.org" + url html = jw_common.loadUrl(url) new = News() new.customInit(html) new.doModal() del new
def showArticle(url): url = "http://www.jw.org" + url html = jw_common.loadUrl(url) activity = Activity() activity.customInit(html) activity.doModal() del activity xbmc.executebuiltin('Action("back")') return
def showDramaticReadingIndex(start): language = jw_config.language reading_index_url = jw_common.getUrl(language) reading_index_url = reading_index_url + jw_config.const[language]["dramatic_reading_index"] reading_index_url = reading_index_url + "?start=" + start + "&sortBy=" + jw_config.audio_sorting html = jw_common.loadUrl(reading_index_url) soup = BeautifulSoup(html) publications = soup.findAll("div", { "class" : re.compile(r'\bPublication\b') }) for publication in publications : title = publication.find('h3').contents[0].encode("utf-8") title = jw_common.cleanUpText(title) json_url = None try : json_url = publication.find("a", { "class" : "jsDownload" }).get('data-jsonurl') except : pass # placeholder if cover is missing cover_url = "http://assets.jw.org/themes/content-theme/images/thumbProduct_placeholder.jpg" try : cover_url = publication.findAll("img")[1].get('src') except : pass listItem = xbmcgui.ListItem( label = title, thumbnailImage = cover_url ) params = { "content_type" : "audio", "mode" : "open_music_json", "json_url" : json_url } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = False ) jw_common.setNextPageLink(html, "open_dramatic_reading_index", "audio") xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid) jw_common.setThumbnailView()
def showActivitySection(url): url = "http://www.jw.org" + url html = jw_common.loadUrl(url) soup = BeautifulSoup(html) # container of news, so we can leave out the sidebar article = soup.findAll("div", {'id' : 'article'}) news = article[0].findAll('div', {'class' : re.compile(r'\bPublicationArticle')}) for n in news : anchor = n.findAll("a") link = anchor[1].get("href") # Lookup news title #detect first item title = n.findAll('div', {'class' : "itemAdText"}) if len(title)>0 : title = jw_common.cleanUpText(anchor[1].get("title").encode("utf-8")) else : content = anchor[1].findAll(text=True) content_string = " ".join(content) title = jw_common.cleanUpText(content_string.encode("utf-8")) image = n.findAll("img") image_src = image[0].get("src") listItem = xbmcgui.ListItem( label = title, thumbnailImage = image_src, ) params = { "content_type" : "executable", "mode" : "open_activity_article", "url" : link } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = False ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid) return
def showMagazineFilteredIndex(pub_filter=None, year_filter=None): language = jw_config.language magazine_url = jw_common.getUrl(language) magazine_url = magazine_url + jw_config.const[language]["magazine_index"] magazine_url = magazine_url + "?pubFilter=" + pub_filter.strip() + "&yearFilter=" + year_filter.strip() html = jw_common.loadUrl(magazine_url) soup = BeautifulSoup(html) publications = soup.findAll("div", {"class": re.compile(r"\bPublicationIssue\b")}) for publication in publications: cover_title = publication.find("span", {"class": re.compile(r"\bperiodicalTitleBlock\b")}) issue_date = cover_title.find("span", {"class": re.compile(r"\bissueDate\b")}).contents[0].encode("utf-8") issue_date = jw_common.cleanUpText(issue_date) try: # wp and g issue_title = cover_title.find("span", {"class": re.compile(r"\bcvrTtl\b")}).contents[0].encode("utf-8") except: # w (study edtion) issue_title = cover_title.find("span", {"class": re.compile(r"\bpubName\b")}).contents[0].encode("utf-8") issue_title = jw_common.cleanUpText(issue_title) json_url = None try: json_url = publication.find("a", {"class": re.compile(r"\bstream\b")}).get("data-jsonurl") except: pass # placeholder if cover is missing cover_url = "http://assets.jw.org/themes/content-theme/images/thumbProduct_placeholder.jpg" try: cover_url = publication.findAll("img")[1].get("src") except: pass listItem = xbmcgui.ListItem(label=issue_date + ": " + issue_title, thumbnailImage=cover_url) params = {"content_type": "audio", "mode": "open_magazine_json", "json_url": json_url} url = jw_config.plugin_name + "?" + urllib.urlencode(params) xbmcplugin.addDirectoryItem(handle=jw_config.plugin_pid, url=url, listitem=listItem, isFolder=True) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def searchResolution(category_url, row_index) : # looking for choosen resolution or first available resolution unde it max_resolution = xbmcplugin.getSetting(jw_config.plugin_pid, "max_resolution") if max_resolution == 0 : return False row_index = int(row_index) #because it's a string actually ! html = jw_common.loadUrl(category_url) soup = BeautifulSoup(html) row = soup.findAll('tr')[row_index] row_cells = row.findAll("td") start_cell = 2 # zero-base indexing first_cell_class = row.findAll("td")[0]["class"] if first_cell_class == "calign": start_cell = 3 video_dict = {} cell_index = -1 for cell in row_cells : cell_index = cell_index + 1 if cell_index == (start_cell -1): article_title = jw_common.cleanUpText(cell.contents[0].encode("utf-8")) if cell_index >= start_cell : # This is needed for resolution cell empty if cell.find("a") is None : continue video_src = cell.find("a").get("href") video_quality = cell.find("a").contents[0].encode("utf-8") video_dict [ video_quality ] = video_src # Look for choosen resolution max_resolution_string = max_resolution + "p" keys = sorted(list(video_dict.keys()), reverse=True) for key in keys : if (key <= max_resolution_string ) : return key # If am here, I surely have NOT the default resolution found return False
def showActivityIndex(): language = jw_config.language url = jw_common.getUrl(language) url = url + jw_config.const[language]["activity_index"] html = jw_common.loadUrl(url) # sections[n][0] = section link # sections[n][1] = section title # <p><a href="/it/testimoni-di-geova/attivit%C3%A0/ministero/" title="Ministero pubblico" class="btnLink"> # VEDI TUTTO</a></p> regexp_section = '<p><a href="([^"]+)" title="([^"]+)" class="btnLink">[^<]+</a></p>' sections = re.findall (regexp_section, html) # iages[n][0] = full url of thumb regexp_images = "data-img-size-sm='([^']+)'" images = re.findall (regexp_images, html) for section in sections : title = jw_common.cleanUpText( section[1] ) listItem = xbmcgui.ListItem( label = title, # no thumbnail available from website, will be used standard folder icon ) params = { "content_type" : "executable", "mode" : "open_activity_section", "url" : section[0] } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) count = 0 xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid) return
def showNewsIndex(): language = jw_config.language url = jw_common.getUrl(language) url = url + jw_config.const[language]["news_index"] html = jw_common.loadUrl(url) regexp_title = '<h3 class="tsrTtle"><a href="([^"]+)"( title="[^"]+")?>([^<]+)</a></h3>' news_found = re.findall(regexp_title, html) # This is to try to filter out cases of double image linked regexp_images = "data-img-type='(lsr|sqs|lss)' .*data-img-size-(lg|md|sm)='([^']+)'" images = re.findall(regexp_images, html) count = 0 for news in news_found: title = jw_common.cleanUpText( news[2] ) # Stop news parsing at the first lateral link (an head) found if "/?v=" in news[0] : break listItem = xbmcgui.ListItem( label = title, thumbnailImage = images[count][2] ) params = { "content_type" : "executable", "mode" : "open_news_page", "url" : news[0] } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = False ) count = count + 1 xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def showVideoFilter(): language = jw_config.language url = jw_config.main_url + jw_config.const[language]["sign_index"] html = jw_common.loadUrl(url) soup = BeautifulSoup(html) boxes = soup.findAll('div',{"class":"box"}) for box in boxes : box_content = box.findAll('div',{'class':'boxcontent'}) for content in box_content : content_divs = content.findAll('div') img_src = content_divs[0].findAll('img')[0].get("src") category_link = content_divs[1].find('a').get('href') category_name = content_divs[1].find('a').contents[0].encode("utf-8") category_name = jw_common.cleanUpText(category_name) listItem = xbmcgui.ListItem( label = category_name, thumbnailImage = img_src ) params = { "content_type" : "video", "mode" : "open_sign_video_category", "url" : category_link, "thumb" : img_src } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def showAudioBibleIndex(): language = jw_config.language bible_index_url = jw_common.getUrl(language) + jw_config.const[language]["bible_index_audio"] html = jw_common.loadUrl(url = bible_index_url, month_cache = True) soup = BeautifulSoup(html) cover_div = soup.findAll('div',{"class": re.compile(r'\bcvr\b')}) span = cover_div[0].findAll('span') img_url = span[0].get('data-img-size-md') boxes = soup.findAll('li',{"class": re.compile(r'\bbookName\b')}) book_num = 0 for box in boxes : book_num = book_num +1 anchors =box.findAll('a') book_name = anchors[0].contents[0] listItem = xbmcgui.ListItem( label = book_name, thumbnailImage = img_url ) params = { "content_type" : "audio", "mode" : "open_bible_book_index", "book_num" : book_num } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def selBook(category_url, thumb) : html = jw_common.loadUrl(category_url) soup = BeautifulSoup(html) book_selector = soup.findAll('select', {'id' : 'selBook'}) if len(book_selector)==1 : options = book_selector[0].findAll('option') for option in options : book = option.contents[0].encode("utf-8") book_num = option.get("value").encode("utf-8") listItem = xbmcgui.ListItem( label = book, thumbnailImage = thumb, ) category_url_with_book = category_url + "&selBook=" + book_num params = { "content_type" : "video", "mode" : "open_sign_video_category", "url" : category_url_with_book, "thumb" : thumb, } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def showVideoCategory(category_url, thumb) : html = jw_common.loadUrl(category_url) soup = BeautifulSoup(html) # search "select year" box [italian watchtower sing language, for example] sel_year_label = soup.findAll('label', {'for' : 'selYear' }) if len(sel_year_label) > 0 : year_selector = soup.findAll('select', {'id' : 'selYear'}) selected_year = year_selector[0].findAll('option', {'selected':'selected'}) listItem = xbmcgui.ListItem( label = "[COLOR blue][B]" + sel_year_label[0].contents[0].encode("utf-8") + " (" + selected_year[0].contents[0].encode("utf-8") + ") " + "[/B][/COLOR]", thumbnailImage = thumb, ) params = { "content_type" : "video", "mode" : "open_sign_video_sel_year", "url" : category_url, 'thumb' : thumb, } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) # search "select book" box [italian bible sing language, for example] sel_book_labels = soup.findAll('label', {'for' : 'selBook' }) if len(sel_book_labels) > 0 : book_selector = soup.findAll('select', {'id' : 'selBook'}) selected_book = book_selector[0].findAll('option', {'selected':'selected'}) listItem = xbmcgui.ListItem( label = "[COLOR blue][B]" + sel_book_labels[0].contents[0].encode("utf-8") + " (" + selected_book[0].contents[0].encode("utf-8") + ") " + "[/B][/COLOR]", thumbnailImage = thumb, ) params = { "content_type" : "video", "mode" : "open_sign_video_sel_book", "url" : category_url, 'thumb' : thumb, } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) # Start looking for publication details pub_titles = soup.findAll('tr', {'class' : re.compile(r'\bpubTitle\b')}) pub_titles_found = len(pub_titles) if pub_titles_found > 1 : pub_title_index = -1 for title in pub_titles : issue_title_cell = title.findAll('th')[0] issue_title = issue_title_cell.find('em').contents[0].encode("utf-8") issue_title = issue_title + issue_title_cell.contents[1].encode("utf-8") issue_title = jw_common.cleanUpText(issue_title) pub_title_index = pub_title_index + 1 listItem = xbmcgui.ListItem( label = issue_title, thumbnailImage = thumb ) params = { "content_type" : "video", "mode" : "open_sign_video_category_with_specific_issue", "url" : category_url, "thumb" : thumb, "pub_title_index" : pub_title_index } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid) return elif pub_titles_found == 1 : showVideoCategorySpecificIssue(category_url, thumb, 0) else : showVideoCategorySpecificIssue(category_url, thumb, -1)
def showVideoIndex(start, video_filter): language = jw_config.language url = jw_common.getUrl(language) + jw_config.const[language]["video_path"] + "/?start=" + str(start) + "&videoFilter=" + video_filter + "&sortBy=" + jw_config.video_sorting html = jw_common.loadUrl (url) # I mix two method to patch quick and dirty. One day I'll cleanup soup = BeautifulSoup(html) index_list = soup.findAll("div", { "id" : 'videosIndexList' }) boxes = index_list[0].findAll("div", { "class" : re.compile(r'\bmixDesc\b') }, recursive=False) count = 0 posters = {} # Scraping for video images for box in boxes : img = box.find("span", {"class" : 'jsRespImg' }) if img is None : img = box.find("img") if img is None : posters[count] = None else : posters[count] = img.get('src') else : posters[count] = img.get('data-img-size-lg') if posters[count] is None : posters[count] = img.get('data-img-size-md') count = count + 1 # Grep video titles regexp_video_title = 'data-onpagetitle="([^"]+)"' videos = re.findall(regexp_video_title, html) # Grep url of json wich contain data on different version of the video [240,360, etc..] regexp_video_json = '.*[^"] data-jsonurl="([^"]+)".*' video_json = re.findall(regexp_video_json, html) if video_json is None or video_json == [] : string = jw_common.t(30033) + " " xbmcgui.Dialog().ok("jworg browser", string) return count = 0 total = len(videos) progress = xbmcgui.DialogProgress() progress.create(jw_common.t(30042), jw_common.t(30043), jw_common.t(30044) ) # Output video list for title in videos: if posters[count] is None : count = count + 1 continue json_url = video_json[count] # if video has a video in default resolution # the url will be a playable item # otherwise it will be a xbmc folder url setVideoUrl(title, json_url, posters[count]) count = count + 1 percent = float(count) / float(total) * 100 message = jw_common.t(30045).format(count, total) progress.update( int(percent), "", "", message) if progress.iscanceled(): break progress.close() # if it's the first page, I show the 'filter' if start == 0 : listItem = xbmcgui.ListItem( label = jw_common.t(30041) ) params = { "content_type" : "video", "mode" : "open_video_filter", } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) # Sign language link sign_index = jw_config.const[language]["sign_index"] if sign_index != False : title = jw_common.t(30040) listItem = xbmcgui.ListItem( title ) params = { 'content_type' : 'video', 'mode' : "open_sign_index", } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) jw_common.setNextPageLink(html, "open_video_index", "video", "video_filter", video_filter) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid) jw_common.setThumbnailView()
def showMusicIndex(start): language = jw_config.language music_index_url = jw_common.getUrl(language) music_index_url = music_index_url + jw_config.const[language]["music_index"] music_index_url = music_index_url + "?start=" + start + "&sortBy=" + jw_config.audio_sorting html = jw_common.loadUrl(url = music_index_url, month_cache = True) soup = BeautifulSoup(html) publications = soup.findAll("div", { "class" : re.compile(r'\bPublication\b') }) for publication in publications : # Read publication format to exclude pdf from songs (in some locales there is the sound book # in the same list of mp3 albums) audio_format = publication.find("div", { "class" : re.compile(r'\bjsAudioFormat\b') } ) if "disabled" in audio_format["class"] : continue title = publication.find('h3').contents[0].encode("utf-8") title = jw_common.cleanUpText(title) json_url = None try : json_url = publication.find("a", { "class" : "jsDownload" }).get('data-jsonurl') except : pass # placeholder if cover is missing cover_url = "http://assets.jw.org/themes/content-theme/images/thumbProduct_placeholder.jpg" try : cover_url = publication.findAll("img")[1].get('src') except : pass listItem = xbmcgui.ListItem( label = title, thumbnailImage = cover_url ) params = { "content_type" : "audio", "mode" : "open_music_json", "json_url" : json_url } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = True ) jw_common.setNextPageLink(html, "open_music_index", "audio") xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid) jw_common.setThumbnailView()
def showVideoCategorySpecificRow(category_url, thumb, row_index) : row_index = int(row_index) #because it's a string actually ! html = jw_common.loadUrl(category_url) soup = BeautifulSoup(html) row = soup.findAll('tr')[row_index] row_cells = row.findAll("td") start_cell = 2 # zero-base indexing first_cell_class = row.findAll("td")[0]["class"] if first_cell_class == "calign": start_cell = 3 video_dict = {} cell_index = -1 for cell in row_cells : cell_index = cell_index + 1 if cell_index == (start_cell -1): article_title = jw_common.cleanUpText(cell.contents[0].encode("utf-8")) if cell_index >= start_cell : # This is needed for resolution cell empty if cell.find("a") is None : continue video_src = cell.find("a").get("href") video_quality = cell.find("a").contents[0].encode("utf-8") video_dict [ video_quality ] = video_src listItem = xbmcgui.ListItem( label = "[" + video_quality + "] - " + article_title, thumbnailImage = thumb ) listItem.setInfo( type = 'Video', infoLabels = {'Title': article_title} ) listItem.setProperty("IsPlayable","true") xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = video_src, listitem = listItem, isFolder = False ) # looking for choosen resolution or first available resolution unde it max_resolution = xbmcplugin.getSetting(jw_config.plugin_pid, "max_resolution") if max_resolution > 0 : max_resolution_string = max_resolution + "p" keys = sorted(list(video_dict.keys()), reverse=True) for key in keys : if (key <= max_resolution_string ) : listItem = xbmcgui.ListItem( label = article_title ) listItem.setInfo( type = 'Video', infoLabels = {'Title': article_title} ) url_to_play = video_dict[key] xbmc.Player().play(item=url_to_play, listitem=listItem) return # this will be executed only if no available res found # this could happen if not preference setted, or if # for example, selected 240p and only 360p availabe. xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
def showVideoCategorySpecificIssue(category_url, thumb, pub_title_index) : pub_title_index = int(pub_title_index) #because it's a string actually ! html = jw_common.loadUrl(category_url) soup = BeautifulSoup(html) rows = soup.findAll('tr') pub_index_found = -1 first_chapter_row = None last_chapter_row = None row_index = -1 for row in rows : row_index = row_index + 1 row_class = None try: row_class = row["class"] except: pass if row_class is not None and 'pubTitle' in row_class : pub_index_found = pub_index_found + 1 continue if row_class is None and pub_index_found == pub_title_index: first_cell = row.findAll("td")[0] first_cell_class = first_cell["class"] # This is needed because watchtower, for example, has one image for a whole issue # so after first row of the issue, the other rows have no images if first_cell_class == "calign" : cell = row.findAll("td")[2] thumb = first_cell.findAll('img')[0].get('src') else : cell = row.findAll("td")[1] # Needed for publications without videos ! # Example: http://www.jw.org/apps/I_QrYQFVTrCsVrGlBBX?selLang=ISL&selPub=938 try : chapter_title = cell.contents[0].encode("utf-8") chapter_title = jw_common.cleanUpText(chapter_title) except : continue res_found = searchResolution(category_url, row_index) if res_found == False : chapter_title = "[COLOR=blue][B]" + chapter_title + "[/B][/COLOR]" is_folder = True else : chapter_title = chapter_title + " [" + res_found + "]" is_folder = False listItem = xbmcgui.ListItem( label = chapter_title, thumbnailImage = thumb ) params = { "content_type" : "video", "mode" : "open_sign_video_category_specific_row", "url" : category_url, "thumb" : thumb, "row_index" : row_index } url = jw_config.plugin_name + '?' + urllib.urlencode(params) xbmcplugin.addDirectoryItem( handle = jw_config.plugin_pid, url = url, listitem = listItem, isFolder = is_folder ) xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)