Episode
The Episode function will allow you to scrape a detailed episode page if you specify episode ‘true’ in the init section.
-
def Episode(self, stream_name, stream_id, page, totalpage):
-
"""Start your code here"""
-
-
"""End your code here"""
-
return episodelist
Receiving variables:
| Variable | Type | Description |
| stream_name | string | Contains the name of the stream |
| stream_id | string | Contains the id of the stream |
| page | string | Returns the current page |
| totalpage | string | Returns the total of pages |
If this function is specified and set probably in the init configuration the framework will call this function after the users has selected an item from the ‘list‘ or ‘search‘ function. The variables stream_name and stream_id are passed in te state they where set in the function ‘search’ or ‘list’. You can fetch extra episode information, like episode number, serie number and/or a thumb to the episode list specified as output.
There is an option to specify a control to browse multiple pages, this can be handy if the episode list is very long (enhance speed) or spread over multiple web pages. The page variable will give the current requested page from the user with a number as string with the default of 1. The total page number will give a string variable with the total number of pages available, default is set to 1. You don’t need to specify the totalpage and page string if you don’t need it.
To return the path information in the correct way the frameworks expects the returned information in a specific output. A single episode item should be put into an object and the array of episodes should be put in a list. An example of such an configuration is:
-
episodelist = list()
-
for item in VarA:
-
episode = ba.CreateEpisode()
-
episode.SetName(item.title)
-
episode.SetId(item.path)
-
episode.SetDescription(item.desc)
-
episode.SetThumbnails(item.thumb)
-
episode.SetDate(item.pup)
-
episode.SetPage(page)
-
episode.SetTotalpage(totalpage)
-
episodelist.append(episode)
-
-
return episodelist
Explanation of the code:
-
episodelist = list()
The episodelist is set as list variabe
-
for item in VarA:
A loop is started iterating the array ‘VarA’
-
episode = ba.CreateEpisode()
An instance is created for the episode item
-
episode.SetName(item.title)
The SetName variable will give the stream its visible name in the app. Passing the variable item.title to it in this case.
-
episode.SetId(item.path)
The SetId variable will give the stream its id parameter, this will be passed to play function. It can be a path or a id to be processed later. The content should be set as string. Passing the variable item.path to it in this case.
-
episode.SetDescription(item.desc)
The SetDescription variable will give the stream its visible description in the app. Passing the variable item.desc to it in this case.
-
episode.SetThumbnails(item.thumb)
The SetThumbnails variable will give the stream its visible thumbnail in the app. Passing the variable with path item.thumb to it in this case.
-
episode.SetDate(item.pup)
The SetDat variable will give the stream its visible date in the app, you can also pass other info in this string for example the episode number. Passing the variable item.pup to it in this case.
-
episode.SetPage(page)
The SetPage variable will pass the current page number to the framework, only needed if you use multiple pages. Passing the variable page to it in this case.
-
episode.SetTotalpage(totalpage)
The SetTotalpage variable will pass the total number of pages to the framework, only needed if you use multiple pages. Passing the variable totalpage to it in this case.
-
episodelist.append(episode)
Appending the instance to the end of the episodelist list.
-
return episodelist
returning the episodelist list to the framework
Multipage Example:
-
def Episode(self, stream_name, stream_id, page, totalpage):
-
url = str(stream_id) + ‘/page=’ + str(page)
-
data = ba.FetchUrl(url, 3600)
-
-
if data == "":
-
mc.ShowDialogNotification("Geen afleveringen gevonden voor " + str(stream_name))
-
return
-
-
soup = BeautifulSoup(data, convertEntities="xml", smartQuotesTo="xml")
-
-
if totalpage == "":
-
try:
-
pages = soup.findAll( ‘div’, {‘class’ : ‘paginator’})[0]
-
pages = pages.findAll(‘span’)
-
totalpage = len(pages) – 1
-
except:
-
totalpage = 1
-
-
div_main = soup.findAll(‘div’, {‘class’ : ‘mo-c double’})[0]
-
div_show = div_main.findAll(‘div’, {‘class’ : ‘wrapper’})[0]
-
-
info = div_show.findAll(‘div’, {‘class’ : ‘thumb’})
-
airtime = div_show.findAll(‘div’, {‘class’ : ‘airtime’})
-
-
episodelist = list()
-
for info_i, airtime_i in izip(info, airtime):
-
episode = ba.CreateEpisode()
-
episode.SetName(stream_name)
-
episode.SetId(self.url_base + info_i.a[‘href’])
-
episode.SetThumbnails(self.url_base + info_i.find(‘img’)[‘src’])
-
episode.SetDate(airtime_i.a.span.contents[0])
-
episode.SetPage(page)
-
episode.SetTotalpage(totalpage)
-
episodelist.append(episode)
-
-
return episodelist
Singlepage Example:
-
def Episode(self, stream_name, stream_id, page, totalpage):
-
url = self.url_base + ‘/iplayer/search?q=’ + quote_plus(stream_id)
-
data = ba.FetchUrl(url, 3600)
-
-
if data == "":
-
mc.ShowDialogNotification("No episode found for " + str(stream_name))
-
episodelist = list()
-
return episodelist
-
-
soup = BeautifulSoup(data, convertEntities="xml", smartQuotesTo="xml")
-
-
div_show = soup.find( ‘ul’, {‘class’ : ‘result-list listview episodelist’})
-
-
episodelist = list()
-
for info in div_show.findAll(lambda tag: tag.name == ‘li’ and not tag.attrs) + div_show.findAll(‘li’,{‘class’:‘audio’}):
-
link = info.findAll(‘a’)
-
if len(link) > 1:
-
title = link[1][‘title’].split(‘: ‘)
-
if len(title) > 2:
-
date = title[2]
-
else:
-
date = ”
-
episode = ba.CreateEpisode()
-
episode.SetName(title[0])
-
episode.SetId(self.url_base + link[1][‘href’])
-
episode.SetDescription(str(info.find(‘p’, {‘class’:‘additional’}).contents[0] + ‘ – ‘ + info.find(‘p’, {‘class’:‘episode-synopsis’}).contents[0]).replace(‘\n‘,”).replace(‘\t‘,”))
-
episode.SetThumbnails(str(link[0].img[‘src’][:-11] + "_314_176.jpg"))
-
episode.SetDate(date)
-
episode.SetPage(page)
-
episode.SetTotalpage(totalpage)
-
episodelist.append(episode)
-
-
return episodelist
Didn't find any related posts :(
bartsidee
nl