Genre
The genre function will allow you the specify a genre list of streams. The genrelist is not search able or indexable at the moment.
To enable the genre function use the starting code below and make sure you add ‘genre’ to the self.type variable in the general module configuration and specify genre variables to the self.genre list. See also the init section.
-
def Genre(self, genre, filter, page, totalpage):
-
"""Start your code here"""
-
-
"""End your code here"""
-
return genrelist
Receiving variables:
| Variable | Type | Description |
| genre | string | Contains the genre string passed from the user |
| filter | string | Contains the filter string passed from the user |
| 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 it will be acceable from the module section in the framework. The genre sections allows you to specify stream list with a specific genre. You can also specify for example a date as genre. As extra you can filter a genre list if you fill in the self.filter list in the init section. A filter should be in this case also specified with every stream.
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 stream item should be put into an object and the array of stream should be put in a list. An example of such an configuration is:
-
genrelist = list()
-
for item in VarA:
-
genreitem = ba.CreateEpisode()
-
genreitem.SetName(item.title)
-
genreitem.SetId(item.path)
-
genreitem.SetDescription(item.desc)
-
genreitem.SetThumbnails(item.thumb)
-
genreitem.SetDate(item.date)
-
genreitem.SetFilter(item.filter)
-
genreitem.SetPage(page)
-
genreitem.SetTotalpage(totalpage)
-
genrelist.append(genreitem)
Explanation of the code:
-
genrelist = list()
The genrelist is set as list variabe
-
for item in VarA:
A loop is started iterating the array ‘VarA’
-
genre = ba.CreateEpisode()
An instance is created for the episode item
-
genre.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.
-
genre.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.
-
genre.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.
-
genre.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.
-
genre.SetDate(item.date)
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.date to it in this case.
-
genre.SetFilter(item.filter)
The SetFilter variable will give the stream its filter variable in the app, if the user presses a filter (set in self.filter) the fra work will only show the streams that have the same filter id specified. Passing the variable item.filter to it in this case.
-
genre.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.
-
genre.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.
-
genre.append(episode)
Appending the instance to the end of the episodelist list.
-
return genrelist
returning the genrelist list to the framework
Multipage Example:
-
def Genre(self, genre, filter, page, totalpage):
-
url = self.url_base + ‘/iplayer/tv/categories/’ + self.genre_links[genre] + ‘?sort=dateavailable&page=’ + str(page)
-
data = ba.FetchUrl(url, 3600)
-
-
if data == "":
-
mc.ShowDialogNotification("No episode found for " + str(genre))
-
genrelist = list()
-
return genrelist
-
-
soup = BeautifulSoup(data, convertEntities="xml", smartQuotesTo="xml")
-
-
if totalpage == "":
-
try:
-
pagediv = soup.findAll( ‘div’, {‘class’ : ‘pagination-control’})[0]
-
apage = pagediv.findAll("li")
-
totalpage = int(len(apage))
-
except:
-
totalpage = 1
-
-
-
div_show = soup.find( ‘ul’, {‘class’ : ‘listview episodelist’})
-
-
genrelist = list()
-
for info in div_show.findAll(lambda tag: tag.name == ‘li’ and not tag.attrs) + div_show.findAll(‘li’,{‘class’:‘multi-episode’}):
-
link = info.findAll(‘a’)
-
-
if len(link) > 1:
-
title = link[1][‘title’].split(‘: ‘)
-
if len(title) > 1:
-
filters = title[1]
-
if len(title) > 2:
-
date = title[2]
-
else:
-
date = ”
-
else:
-
filters = ”
-
genreitem = ba.CreateEpisode()
-
genreitem.SetName(title[0])
-
genreitem.SetId(self.url_base + link[1][‘href’])
-
genreitem.SetDescription(str(info.find(‘p’, {‘class’:‘episode-synopsis’}).contents[0]).replace(‘\n‘,”).replace(‘\t‘,”))
-
genreitem.SetThumbnails(str(link[0].img[‘src’][:-11] + "_314_176.jpg"))
-
genreitem.SetDate(filters)
-
genreitem.SetFilter(date)
-
genreitem.SetPage(page)
-
genreitem.SetTotalpage(totalpage)
-
genrelist.append(genreitem)
-
-
return genrelist
Multipage 2 Example:
-
def Genre(self, genre, filter, page, totalpage):
-
url = self.url_base + ‘/7dagen/’ + genre
-
if filter != "": url = url + ‘,’ + str(filter)
-
url = url + ‘?weergave=detail&page=’ + str(page)
-
data = ba.FetchUrl(url, 3600)
-
if data == "":
-
mc.ShowDialogNotification("No genre found for " + str(genre))
-
genrelist = list()
-
return genrelist
-
soup = BeautifulSoup(data, convertEntities="xml", smartQuotesTo="xml")
-
if totalpage == "":
-
try:
-
pagediv = soup.findAll( ‘div’, {‘class’ : ‘pagination’})[0]
-
apage = pagediv.findAll("a")
-
totalpage = int(apage[len(apage)-2].contents[0])
-
except:
-
totalpage = 1
-
-
div_show = soup.find( ‘table’, {‘class’ : ‘broadcasts detail’})
-
-
genrelist = list()
-
for info in div_show.findAll("tr"):
-
omroep = info.findAll(attrs={"class" : "broadcaster-logo"})[0][‘alt’]
-
if omroep == "Nederland 1": omroep = "nl1"
-
elif omroep == "Nederland 2": omroep = "nl2"
-
elif omroep == "Nederland 3": omroep = "nl3"
-
try:
-
thumb = info.findAll(attrs={"class" : "thumbnail"})[0][‘src’]
-
except:
-
thumb = info.findAll(attrs={"class" : "thumbnail placeholder"})[0][‘src’]
-
path = self.url_base + info.find(attrs={"class" : "thumbnail_wrapper"})[‘href’]
-
date = info.find(attrs={"class" : "time"}).time.contents[0].replace(‘ ‘,”).replace(‘\n‘,”).replace(‘\t‘,”)
-
title = info.findAll(attrs={"class" : "series"})[0].contents[0]
-
desc = info.find(‘div’, {‘class’ : ‘description’}).p.contents[0]
-
-
genreitem = ba.CreateEpisode()
-
genreitem.SetName(title)
-
genreitem.SetId(path)
-
genreitem.SetDescription(desc)
-
genreitem.SetThumbnails(thumb)
-
genreitem.SetDate(date)
-
genreitem.SetFilter(str(omroep).upper())
-
genreitem.SetPage(page)
-
genreitem.SetTotalpage(totalpage)
-
genrelist.append(genreitem)
-
-
return genrelist
Didn't find any related posts :(
bartsidee
nl