Example #1
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()
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 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 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)
Example #7
0
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()