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)
Ejemplo n.º 3
0
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 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()
Ejemplo n.º 5
0
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 showMagazineFilterIndex(pub_filter=None):

    if pub_filter is None:

        items = [
            {"title": jw_common.t(30026), "mode": "open_magazine_index", "pub_filter": " ", "year_filter": ""},
            {"title": jw_common.t(30027), "mode": "open_magazine_index", "pub_filter": "g", "year_filter": ""},
            {"title": jw_common.t(30028), "mode": "open_magazine_index", "pub_filter": "wp", "year_filter": ""},
            {"title": jw_common.t(30029), "mode": "open_magazine_index", "pub_filter": "w", "year_filter": ""},
        ]

        # Support for simpliefied study edition of watchtower [english, spanish, ...]
        language = jw_config.language
        if jw_config.const[language]["has_simplified_edition"] == True:
            items.append(
                {"title": jw_common.t(30030), "mode": "open_magazine_index", "pub_filter": "ws", "year_filter": ""}
            )

    if pub_filter is not None:

        items = []

        for year in [" ", "2014", "2013", "2012"]:
            title = year
            if title == " ":
                title = jw_common.t(30031)

            items.append({"title": title, "mode": "open_magazine_index", "pub_filter": pub_filter, "year_filter": year})

    for item in items:

        if item["title"] == "-":
            continue

        title_text = jw_common.cleanUpText(item["title"])
        listItem = xbmcgui.ListItem(title_text)

        params = {
            "content_type": "audio",
            "mode": item["mode"],
            "pub_filter": item["pub_filter"],
            "year_filter": item["year_filter"],
        }

        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 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 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
Ejemplo n.º 9
0
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 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
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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()
Ejemplo n.º 13
0
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)	
Ejemplo n.º 14
0
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)		
Ejemplo n.º 15
0
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) 
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
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