#NEWLINE# def trakt_list2( self , url , lang ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# url += '?extended=full' #NEWLINE# result = trakt . getTrakt ( url ) #NEWLINE# result = json . loads ( result ) #NEWLINE# items = [ ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# for item in result : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# num_1 = 0 #NEWLINE# for i in range ( 0 , len ( item [ 'seasons' ] ) ) : #NEWLINE# #INDENT# num_1 += len ( item [ 'seasons' ] [ i ] [ 'episodes' ] ) #NEWLINE# #UNINDENT# num_2 = int ( item [ 'show' ] [ 'aired_episodes' ] ) #NEWLINE# if ( num_1 >= num_2 ) : #NEWLINE# #INDENT# raise Exception ( ) #NEWLINE# #UNINDENT# season = str ( item [ 'seasons' ] [ ( - 1 ) ] [ 'number' ] ) #NEWLINE# season = season . encode ( 'utf-8' ) #NEWLINE# episode = str ( item [ 'seasons' ] [ ( - 1 ) ] [ 'episodes' ] [ ( - 1 ) ] [ 'number' ] ) #NEWLINE# episode = episode . encode ( 'utf-8' ) #NEWLINE# tvshowtitle = item [ 'show' ] [ 'title' ] #NEWLINE# if ( ( tvshowtitle == None ) or ( tvshowtitle == '' ) ) : #NEWLINE# #INDENT# raise Exception ( ) #NEWLINE# #UNINDENT# tvshowtitle = client . replaceHTMLCodes ( tvshowtitle ) #NEWLINE# tvshowtitle = tvshowtitle . encode ( 'utf-8' ) #NEWLINE# year = item [ 'show' ] [ 'year' ] #NEWLINE# year = re . sub ( '[^0-9]' , '' , str ( year ) ) #NEWLINE# if ( int ( year ) > int ( self . datetime . strftime ( '%Y' ) ) ) : #NEWLINE# #INDENT# raise Exception ( ) #NEWLINE# #UNINDENT# imdb = item [ 'show' ] [ 'ids' ] [ 'imdb' ] #NEWLINE# if ( ( imdb == None ) or ( imdb == '' ) ) : #NEWLINE# #INDENT# raise Exception ( ) #NEWLINE# #UNINDENT# imdb = ( 'tt' + re . sub ( '[^0-9]' , '' , str ( imdb ) ) ) #NEWLINE# imdb = imdb . encode ( 'utf-8' ) #NEWLINE# tvdb = item [ 'show' ] [ 'ids' ] [ 'tvdb' ] #NEWLINE# if ( ( tvdb == None ) or ( tvdb == '' ) ) : #NEWLINE# #INDENT# raise Exception ( ) #NEWLINE# #UNINDENT# tvdb = re . sub ( '[^0-9]' , '' , str ( tvdb ) ) #NEWLINE# tvdb = tvdb . encode ( 'utf-8' ) #NEWLINE# tmdb = self [ 'show' ] [ 'ids' ] [ 'tmdb' ] #NEWLINE# if ( ( tmdb == None ) or ( tmdb == '' ) ) : #NEWLINE# #INDENT# tmdb = '0' #NEWLINE# #UNINDENT# tmdb = re . sub ( '[^0-9]' , '' , str ( tmdb ) ) #NEWLINE# tmdb = tmdb . encode ( 'utf-8' ) #NEWLINE# tvrage = item [ 'show' ] [ 'ids' ] [ 'tvrage' ] #NEWLINE# if ( ( tvrage == None ) or ( tvrage == '' ) ) : #NEWLINE# #INDENT# tvrage = '0' #NEWLINE# #UNINDENT# tvrage = re . sub ( '[^0-9]' , '' , str ( tvrage ) ) #NEWLINE# tvrage = tvrage . encode ( 'utf-8' ) #NEWLINE# items . append ( { #NEWLINE# #INDENT# 'imdb' : imdb , #NEWLINE# 'tmdb' : tmdb , #NEWLINE# 'tvdb' : tvdb , #NEWLINE# 'tvrage' : tvrage , #NEWLINE# 'tvshowtitle' : tvshowtitle , #NEWLINE# 'year' : year , #NEWLINE# 'season' : season , #NEWLINE# 'episode' : episode , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# def items_list( i ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# tvdb_lang = re . sub ( 'bg' , 'en' , lang ) #NEWLINE# url = ( self . tvdb_info_link % ( i [ 'tvdb' ] , tvdb_lang ) ) #NEWLINE# data = urllib2 . urlopen ( url , timeout = 10 ) . read ( ) #NEWLINE# zip = zipfile . ZipFile ( StringIO . StringIO ( data ) ) #NEWLINE# result = zip . read ( ( '%s.xml' % tvdb_lang ) ) #NEWLINE# artwork = zip . read ( 'banners.xml' ) #NEWLINE# zip . close ( ) #NEWLINE# result = result . split ( '<Episode>' ) #NEWLINE# item = [ x for x in result if ( '<EpisodeNumber>' in x ) ] #NEWLINE# item2 = result [ 0 ] #NEWLINE# num = [ x for ( x , y ) in enumerate ( item ) if ( ( re . compile ( '<SeasonNumber>(.+?)</SeasonNumber>' ) . findall ( y ) [ 0 ] == str ( i [ 'season' ] ) ) and ( re . compile ( '<EpisodeNumber>(.+?)</EpisodeNumber>' ) . findall ( y ) [ 0 ] == str ( i [ 'episode' ] ) ) ) ] [ ( - 1 ) ] #NEWLINE# item = [ y for ( x , y ) in enumerate ( item ) if ( x > num ) ] [ 0 ] #NEWLINE# premiered = client . parseDOM ( item , 'FirstAired' ) [ 0 ] #NEWLINE# if ( ( premiered == '' ) or ( '-00' in premiered ) ) : #NEWLINE# #INDENT# premiered = '0' #NEWLINE# #UNINDENT# premiered = client . replaceHTMLCodes ( premiered ) #NEWLINE# premiered = premiered . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# status = client . parseDOM ( item2 , 'Status' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# status = '' #NEWLINE# #UNINDENT# if ( status == '' ) : #NEWLINE# #INDENT# status = 'Ended' #NEWLINE# #UNINDENT# status = client . replaceHTMLCodes ( status ) #NEWLINE# status = status . encode ( 'utf-8' ) #NEWLINE# if ( status == 'Ended' ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( premiered == '0' ) : #NEWLINE# #INDENT# raise Exception ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( int ( re . sub ( '[^0-9]' , '' , str ( premiered ) ) ) > int ( re . sub ( '[^0-9]' , '' , str ( self . today_date ) ) ) ) : #NEWLINE# #INDENT# raise Exception ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# title = client . parseDOM ( item , 'EpisodeName' ) [ 0 ] #NEWLINE# if ( title == '' ) : #NEWLINE# #INDENT# title = '0' #NEWLINE# #UNINDENT# title = client . replaceHTMLCodes ( title ) #NEWLINE# title = title . encode ( 'utf-8' ) #NEWLINE# season = client . parseDOM ( item , 'SeasonNumber' ) [ 0 ] #NEWLINE# season = ( '%01d' % int ( season ) ) #NEWLINE# season = season . encode ( 'utf-8' ) #NEWLINE# episode = client . parseDOM ( item , 'EpisodeNumber' ) [ 0 ] #NEWLINE# episode = re . sub ( '[^0-9]' , '' , ( '%01d' % int ( episode ) ) ) #NEWLINE# episode = episode . encode ( 'utf-8' ) #NEWLINE# tvshowtitle = i [ 'tvshowtitle' ] #NEWLINE# ( imdb , tmdb , tvdb , tvrage ) = ( i [ 'imdb' ] , i [ 'tmdb' ] , i [ 'tvdb' ] , i [ 'tvrage' ] ) #NEWLINE# year = i [ 'year' ] #NEWLINE# try : #NEWLINE# #INDENT# year = year . encode ( 'utf-8' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# name = ( '%s S%02dE%02d' % ( tvshowtitle , int ( season ) , int ( episode ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# name = name . encode ( 'utf-8' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# poster = client . parseDOM ( item2 , 'poster' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# poster = '' #NEWLINE# #UNINDENT# if ( not ( poster == '' ) ) : #NEWLINE# #INDENT# poster = ( self . tvdb_image + poster ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# poster = '0' #NEWLINE# #UNINDENT# poster = client . replaceHTMLCodes ( poster ) #NEWLINE# poster = poster . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# banner = client . parseDOM ( item2 , 'banner' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# banner = '' #NEWLINE# #UNINDENT# if ( not ( banner == '' ) ) : #NEWLINE# #INDENT# banner = ( self . tvdb_image + banner ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# banner = '0' #NEWLINE# #UNINDENT# banner = client . replaceHTMLCodes ( banner ) #NEWLINE# banner = banner . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# fanart = client . parseDOM ( item2 , 'fanart' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# fanart = '' #NEWLINE# #UNINDENT# if ( not ( fanart == '' ) ) : #NEWLINE# #INDENT# fanart = ( self . tvdb_image + fanart ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fanart = '0' #NEWLINE# #UNINDENT# fanart = client . replaceHTMLCodes ( fanart ) #NEWLINE# fanart = fanart . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# thumb = client . parseDOM ( item , 'filename' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# thumb = '' #NEWLINE# #UNINDENT# if ( not ( thumb == '' ) ) : #NEWLINE# #INDENT# thumb = ( self . tvdb_image + thumb ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# thumb = '0' #NEWLINE# #UNINDENT# thumb = client . replaceHTMLCodes ( thumb ) #NEWLINE# thumb = thumb . encode ( 'utf-8' ) #NEWLINE# if ( not ( poster == '0' ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( fanart == '0' ) ) : #NEWLINE# #INDENT# poster = fanart #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( banner == '0' ) ) : #NEWLINE# #INDENT# poster = banner #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not ( banner == '0' ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( fanart == '0' ) ) : #NEWLINE# #INDENT# banner = fanart #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( poster == '0' ) ) : #NEWLINE# #INDENT# banner = poster #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not ( thumb == '0' ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( fanart == '0' ) ) : #NEWLINE# #INDENT# thumb = fanart . replace ( self . tvdb_image , self . tvdb_poster ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( poster == '0' ) ) : #NEWLINE# #INDENT# thumb = poster #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# studio = client . parseDOM ( item2 , 'Network' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# studio = '' #NEWLINE# #UNINDENT# if ( studio == '' ) : #NEWLINE# #INDENT# studio = '0' #NEWLINE# #UNINDENT# studio = client . replaceHTMLCodes ( studio ) #NEWLINE# studio = studio . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# alter = client . parseDOM ( item2 , 'Genre' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# alter = '0' #NEWLINE# #UNINDENT# if any ( ( ( x in alter ) for x in [ 'Documentary' , 'Reality' , 'Game Show' , 'Talk Show' ] ) ) : #NEWLINE# #INDENT# alter = '1' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# alter = '0' #NEWLINE# #UNINDENT# alter = alter . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# genre = client . parseDOM ( item2 , 'Genre' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# genre = '' #NEWLINE# #UNINDENT# genre = [ x for x in genre . split ( '|' ) if ( not ( x == '' ) ) ] #NEWLINE# genre = ' / ' . join ( genre ) #NEWLINE# if ( genre == '' ) : #NEWLINE# #INDENT# genre = '0' #NEWLINE# #UNINDENT# genre = client . replaceHTMLCodes ( genre ) #NEWLINE# genre = genre . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# duration = client . parseDOM ( item2 , 'Runtime' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# duration = '' #NEWLINE# #UNINDENT# if ( duration == '' ) : #NEWLINE# #INDENT# duration = '0' #NEWLINE# #UNINDENT# duration = client . replaceHTMLCodes ( duration ) #NEWLINE# duration = duration . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# rating = client . parseDOM ( item , 'Rating' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# rating = '' #NEWLINE# #UNINDENT# if ( rating == '' ) : #NEWLINE# #INDENT# rating = '0' #NEWLINE# #UNINDENT# rating = client . replaceHTMLCodes ( rating ) #NEWLINE# rating = rating . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# votes = client . parseDOM ( item2 , 'RatingCount' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# votes = '0' #NEWLINE# #UNINDENT# if ( votes == '' ) : #NEWLINE# #INDENT# votes = '0' #NEWLINE# #UNINDENT# votes = client . replaceHTMLCodes ( votes ) #NEWLINE# votes = votes . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# mpaa = client . parseDOM ( item2 , 'ContentRating' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# mpaa = '' #NEWLINE# #UNINDENT# if ( mpaa == '' ) : #NEWLINE# #INDENT# mpaa = '0' #NEWLINE# #UNINDENT# mpaa = client . replaceHTMLCodes ( mpaa ) #NEWLINE# mpaa = mpaa . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# director = client . parseDOM ( item , 'Director' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# director = '' #NEWLINE# #UNINDENT# director = [ x for x in director . split ( '|' ) if ( not ( x == '' ) ) ] #NEWLINE# director = ' / ' . join ( director ) #NEWLINE# if ( director == '' ) : #NEWLINE# #INDENT# director = '0' #NEWLINE# #UNINDENT# director = client . replaceHTMLCodes ( director ) #NEWLINE# director = director . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# writer = client . parseDOM ( item , 'Writer' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# writer = '' #NEWLINE# #UNINDENT# writer = [ x for x in writer . split ( '|' ) if ( not ( x == '' ) ) ] #NEWLINE# writer = ' / ' . join ( writer ) #NEWLINE# if ( writer == '' ) : #NEWLINE# #INDENT# writer = '0' #NEWLINE# #UNINDENT# writer = client . replaceHTMLCodes ( writer ) #NEWLINE# writer = writer . encode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# cast = client . parseDOM ( item2 , 'Actors' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# cast = '' #NEWLINE# #UNINDENT# cast = [ x for x in cast . split ( '|' ) if ( not ( x == '' ) ) ] #NEWLINE# try : #NEWLINE# #INDENT# cast = [ ( x . encode ( 'utf-8' ) , '' ) for x in cast ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# cast = [ ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# plot = client . parseDOM ( item , 'Overview' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# plot = '' #NEWLINE# #UNINDENT# if ( plot == '' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# plot = client . parseDOM ( item2 , 'Overview' ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# plot = '' #NEWLINE# #UNINDENT# #UNINDENT# if ( plot == '' ) : #NEWLINE# #INDENT# plot = '0' #NEWLINE# #UNINDENT# plot = client . replaceHTMLCodes ( plot ) #NEWLINE# plot = plot . encode ( 'utf-8' ) #NEWLINE# self . list . append ( { #NEWLINE# #INDENT# 'title' : title , #NEWLINE# 'season' : season , #NEWLINE# 'episode' : episode , #NEWLINE# 'tvshowtitle' : tvshowtitle , #NEWLINE# 'year' : year , #NEWLINE# 'premiered' : premiered , #NEWLINE# 'status' : status , #NEWLINE# 'alter' : alter , #NEWLINE# 'studio' : studio , #NEWLINE# 'genre' : genre , #NEWLINE# 'duration' : duration , #NEWLINE# 'rating' : rating , #NEWLINE# 'votes' : votes , #NEWLINE# 'mpaa' : mpaa , #NEWLINE# 'director' : director , #NEWLINE# 'writer' : writer , #NEWLINE# 'cast' : cast , #NEWLINE# 'plot' : plot , #NEWLINE# 'name' : name , #NEWLINE# 'code' : imdb , #NEWLINE# 'imdb' : imdb , #NEWLINE# 'tmdb' : tmdb , #NEWLINE# 'tvdb' : tvdb , #NEWLINE# 'tvrage' : tvrage , #NEWLINE# 'poster' : poster , #NEWLINE# 'banner' : banner , #NEWLINE# 'fanart' : fanart , #NEWLINE# 'thumb' : thumb , #NEWLINE# 'action' : 'episodes' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# items = items [ : 30 ] #NEWLINE# threads = [ ] #NEWLINE# for i in items : #NEWLINE# #INDENT# threads . append ( workers . Thread ( items_list , i ) ) #NEWLINE# #UNINDENT# [ i . start ( ) for i in threads ] #NEWLINE# [ i . join ( ) for i in threads ] #NEWLINE# try : #NEWLINE# #INDENT# self . list = sorted ( self . list , key = ( lambda k : k [ 'premiered' ] ) , reverse = True ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return self . list