コード例 #1
0
def make_list():#to do everything to get all the rounds
	datenow = datetime.date.today()

	PH = Pagehandler()
	html = Pagehandler.opener.open('http://afltv.afl.com.au/schedule/group_view').read()
	if(PH.login_needed(html)):
		PH.login() #ok login, but we do nothing else

	#now get the rounds from the html string:
	try:
		rounds = []
		soup = BeautifulSoup(html)
		for r in soup.find_all('li', attrs={"class":"linked round"}):
			ra = r.find('a')
			ras = ra.find('span')
			dateround = urlstring_to_date(str(ra['href']))
			if(dateround):
				#we want to display only rounds which are not in the future
				ddiff = dateround-datenow
				diff = ddiff.days
				if(diff <= 1): #because of different timezones it could be an other day.
					rounds.append({'name':str(ras.text),'href':str(ra['href']),'channel':'rounds'})

		__addon__ = xbmcaddon.Addon()

		ok = fill_media_list_replay(rounds)
	except:
		# oops print error message
		print "ERROR:"
		ok = False

	# send notification we're finished, successfully or unsuccessfully
	xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
	#save cookies
	PH.save_cookie()
コード例 #2
0
def make_list(href):#to do everything to get all videos for that game
	PH = Pagehandler()
	html = Pagehandler.opener.open('http://afltv.afl.com.au'+href).read()
	if(PH.login_needed(html)):
		PH.login() #ok login, but we do nothing else
		html = Pagehandler.opener.open('http://afltv.afl.com.au'+href).read()
		if(PH.login_needed(html)):
			d = xbmcgui.Dialog()
			d.ok('AFLTV Error', 'AFLTV login failed, check your login data.')
			return False



	#now get the rounds from the html string:
	try:
		videos = []
		soup = BeautifulSoup(html)
		available_videos = soup.find('ul',attrs={'class':re.compile("available-videos")})
		if(not available_videos):
			d = xbmcgui.Dialog()
			d.ok('AFLTV Error', "There are no videos available.")
			return False
		#search for all replay videos
		replays = available_videos.find('li', attrs={'class':re.compile("replay")})
		if(replays):
			for li in replays.find_all('li'):
				current_name = None
				current_href = None
				li2 = str(li)
				a = re.findall(r'<a\s+?class="video".*?href="(.*?)">(.*?)</a>',li2, re.I)
				if(len(a) > 0):
					for ia in a:
						current_href = ia[0]
						current_name = ia[1].strip()
						if(current_href and current_name):
							videos.append({'name':current_name, 'href':current_href, 'channel':'video'})
		#search for all highlight videos
		highlights = available_videos.find('li', attrs={'class':re.compile("highlights")})
		if(highlights):
			for li in highlights.find_all('li'):
				current_name = None
				current_href = None
				li2 = str(li)
				a = re.findall(r'<a\s+?class="video".*?href="(.*?)">(.*?)</a>',li2, re.I)
				if(len(a) > 0):
					for ia in a:
						current_href = ia[0]
						current_name = ia[1].strip()
						if(current_href and current_name):
							videos.append({'name':current_name, 'href':current_href, 'channel':'video'})

		if(len(videos) == 0):
			d = xbmcgui.Dialog()
			d.ok('AFLTV Error', "There are no videos available.")
			return False

		__addon__ = xbmcaddon.Addon()

		ok = fill_media_list_replay(videos)
	except:
		# oops print error message
		print "ERROR:"
		ok = False

	if(ok == 0):
		return False

	# send notification we're finished, successfully or unsuccessfully
	xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
	#save cookies
	PH.save_cookie()
コード例 #3
0
def make_list(href):#to do everything to get all games in that round

	PH = Pagehandler()
	html = Pagehandler.opener.open('http://afltv.afl.com.au'+href).read()
	if(PH.login_needed(html)):
		PH.login() #ok login, but we do nothing else
		html = Pagehandler.opener.open('http://afltv.afl.com.au'+href).read()
		if(PH.login_needed(html)):
			d = xbmcgui.Dialog()
			d.ok('AFLTV Error', 'AFLTV login failed, check your login data.')
			return False



	#now get the rounds from the html string:
	try:
		games = []
		soup = BeautifulSoup(html)
		Roundname = soup.find('h3').text
		while(True):
			if(soup.find('h3').text != Roundname):
				break
			videolist = soup.find('div', attrs={'id':"fixture-list"})
			if(not videolist):
				d = xbmcgui.Dialog()
				d.ok('AFLTV Error', 'AFLTV something went wrong, cant buid list.')
				soup = get_next_page(soup) #we look for the next page
				if(not soup): #there is no next page
					break
				elif(soup == 0): #there was a login error exit
					return False
				else:
					continue #continue with the next page

			for listelement in videolist.find_all('div', attrs={"data-event-id":True}):
				link = None
				current_team_home = None
				current_team_guest = None
				if(len(listelement.find_all('a', attrs={'class':'video'})) > 0): #we have some videos, if not ignore it!
					teams = listelement.find('ul', attrs={'class':'teams'})
					if(not teams):
						continue
					for li in teams.find_all('li'):
						clases = li['class']
						for c in clases:
							if('first' == str(c)):
								current_team_home = str(li.text).strip()
								current_team_home = current_team_home.lower()
							elif('last' == str(c)):
								current_team_guest = str(li.text).strip()
								current_team_guest = current_team_guest.lower()

					videos = listelement.find('ul', attrs = {'class':"video-details"})
					if(not videos):
						continue
					for li in videos.find_all('li'):
						lstr = str(li).lower() 
						if("replay" in lstr or "highlights" in lstr):
							try:
								link = str(li.find('a')['href'])
								break
							except:
								continue

					if(link and current_team_home and current_team_guest):
						games.append({'name':config.TEAMS[current_team_home]+" vs "+config.TEAMS[current_team_guest], 'href':link, 'channel':'game'})

			#get the next page (if there is one)
			next = soup.find('li', attrs={'class':'next'})
			if(not next):
				break
			else:
				try:
					anext = next.find('a', attrs={"href":True})
					if(not anext):
						break
					nexthref = str(anext['href'])
					html = Pagehandler.opener.open('http://afltv.afl.com.au'+nexthref).read()
					if(PH.login_needed(html)):
						PH.login() #ok login, but we do nothing else
						html = Pagehandler.opener.open('http://afltv.afl.com.au'+nexthref).read()
						if(PH.login_needed(html)):
							d = xbmcgui.Dialog()
							d.ok('AFLTV Error', 'AFLTV login failed, check your login data.')
							return False
					soup = BeautifulSoup(html)
				except:
					break
		if(len(games) == 0):
			d = xbmcgui.Dialog()
			d.ok('AFLTV Error', "There are no games available.")
			return False

		__addon__ = xbmcaddon.Addon()

		ok = fill_media_list_replay(games)
	except:
		# oops print error message
		print "ERROR:"
		ok = False

	# send notification we're finished, successfully or unsuccessfully
	xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
	#save cookies
	PH.save_cookie()