def getEpisode(self, name, begin, end=None, service=None): # On Success: Return a single season, episode, title tuple # On Failure: Return a empty list or String or None # Check dependencies if HTMLParser is None: msg = _("Error install") + " HTMLParser" logInfo(msg) return msg if parse_date is None: msg = _("Error install") + " parse_date" logInfo(msg) return msg # Check preconditions if not name: msg = _("Skip: No show name specified") logInfo(msg) return msg if not begin: msg = _("Skip: No begin timestamp specified") logInfo(msg) return msg if not service: msg = _("Skip: No service specified") logInfo(msg) return msg logInfo("WLF: getEpisode, name, begin, end=None, service", name, begin, end, service) self.begin = begin self.end = end self.service = service self.knownids = [] self.returnvalue = None while name: ids = self.getSeries(name) while ids: idserie = ids.pop() if idserie and len(idserie) == 2: id, idname = idserie # Handle encodings self.series = str_to_utf8(idname) logInfo("WLF: Possible matched series:", self.series) result = self.getNextPage(id) if result: return result else: name = self.getAlternativeSeries(name) else: return (self.returnvalue or _("No matching series found"))
def getEpisode(self, name, begin, end=None, service=None): # On Success: Return a single season, episode, title tuple # On Failure: Return a empty list or String or None # Check dependencies if HTMLParser is None: msg = _("Error install") + " HTMLParser" logInfo(msg) return msg if parse_date is None: msg = _("Error install") + " parse_date" logInfo(msg) return msg # Check preconditions if not name: msg = _("Skip: No show name specified") logInfo(msg) return msg if not begin: msg = _("Skip: No begin timestamp specified") logInfo(msg) return msg if not service: msg = _("Skip: No service specified") logInfo(msg) return msg logInfo("WLP: getEpisode, name, begin, end=None, service", name, begin, end, service) self.begin = begin self.end = end self.service = service self.knownids = [] self.returnvalue = None while name: ids = self.getSeries(name) while ids: idserie = ids.pop() if idserie and len(idserie) == 2: id, idname = idserie # Handle encodings self.series = str_to_utf8(idname) logInfo("Possible matched series:", self.series) result = self.getNextPage(id) if result: return result else: name = self.getAlternativeSeries(name) else: return self.returnvalue or _("No matching series found")
def getEpisode(self, name, begin, end=None, service=None): # On Success: Return a single season, episode, title tuple # On Failure: Return a empty list or String or None # Check dependencies if xmlrpclib is None: msg = _("Error install") + " python-xmlrpclib" logInfo(msg) return msg # Check preconditions if not name: msg = _("Skip: No show name specified") logInfo(msg) return msg if not begin: msg = _("Skip: No begin timestamp specified") logInfo(msg) return msg if not service: msg = _("Skip: No service specified") logInfo(msg) return msg self.name = name self.begin = begin self.end = end self.service = service self.knownids = [] logInfo("SerienServer getEpisode, name, begin, end=None, service", name, begin, end, service) # Prepare parameters name = CompiledRegexpReplaceChars.sub(" ", name.lower()) webChannels = self.lookupChannelByReference(service) unixtime = str(int(mktime(begin.timetuple()))) max_time_drift = self.max_time_drift # Lookup for webChannel in webChannels: logInfo("SerienServer getSeasonEpisode():", name, webChannel, unixtime) result = self.server.sp.cache.getSeasonEpisode( name, webChannel, unixtime, max_time_drift) logDebug("SerienServer getSeasonEpisode result:", result) if result: return (result['season'], result['episode'], result['title'], result['series']) else: if unixtime < time(): return (_("Please try Fernsehserien.de")) else: return (_("No matching series found"))
def getEpisode(self, name, begin, end=None, service=None): # On Success: Return a single season, episode, title tuple # On Failure: Return a empty list or String or None # Check dependencies if xmlrpclib is None: msg = _("Error install") + " python-xmlrpclib" logInfo(msg) return msg # Check preconditions if not name: msg =_("Skip: No show name specified") logInfo(msg) return msg if not begin: msg = _("Skip: No begin timestamp specified") logInfo(msg) return msg if not service: msg = _("Skip: No service specified") logInfo(msg) return msg self.name = name self.begin = begin self.end = end self.service = service self.knownids = [] logInfo("SerienServer getEpisode, name, begin, end=None, service", name, begin, end, service) # Prepare parameters name = CompiledRegexpReplaceChars.sub(" ", name.lower()) webChannels = self.lookupChannelByReference(service) unixtime = str(int(mktime(begin.timetuple()))) max_time_drift = self.max_time_drift # Lookup for webChannel in webChannels: logInfo("SerienServer getSeasonEpisode():", name, webChannel, unixtime) result = self.server.sp.cache.getSeasonEpisode( name, webChannel, unixtime, max_time_drift ) logDebug("SerienServer getSeasonEpisode result:", result) if result: return ( result['season'], result['episode'], result['title'], result['series'] ) else: if unixtime < time(): return ( _("Please try Fernsehserien.de") ) else: return ( _("No matching series found") )
def getNextPage(self, id): logDebug("WLF: getNextPage") url = EPISODEIDURLATOM + urlencode({ 's' : id }) data = self.getPage( url ) if data and isinstance(data, basestring): data = self.parseNextPage(data) self.doCacheList(url, data) if data and isinstance(data, list): trs = data yepisode = None ydelta = maxint for tds in trs: if tds and len(tds) == 2: xtitle, xupdated = tds if xtitle is not None and xupdated is not None: #import iso8601 #http://code.google.com/p/pyiso8601/ xbegin = parse_date(xupdated) xbegin = xbegin.replace(tzinfo=None) #"2014-11-10T20:15:00+01:00" #xbegin = datetime.strptime(xupdated[0:-6], "%Y-%m-%dT%H:%M:%S"); #Py2.6 delta = abs(self.begin - xbegin) delta = delta.seconds + delta.days * 24 * 3600 #Py2.7 #delta = abs(self.begin - xbegin).total_seconds() logDebug("WLF:", self.begin, '-', xbegin, '-', delta, '-', self.max_time_drift) if delta <= self.max_time_drift: result = CompiledRegexpAtomChannel.search(xtitle) if result and len(result.groups()) >= 1: xchannel = result.group(1) logInfo("WLF: Possible match witch channel: ", xchannel) if self.compareChannels(self.service, xchannel): if delta < ydelta: # Slice string to remove channel xtitle = xtitle[:result.start()] result = CompiledRegexpAtomDate.search(xtitle) if result and len(result.groups()) >= 1: # Slice string to remove date xtitle = xtitle[:result.start()] result = CompiledRegexpAtomEpisode.search(xtitle) if result and len(result.groups()) >= 1: # Extract season and episode xepisode = result.group(1) # Slice string to remove season and episode xtitle = xtitle[:result.start()] result = CompiledRegexpEpisode.search(xepisode) if result and len(result.groups()) >= 3: xseason = result and result.group(2) or config.plugins.seriesplugin.default_season.value xepisode = result and result.group(3) or config.plugins.seriesplugin.default_episode.value else: logDebug("WLF: wrong episode format", xepisode) xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value else: logDebug("WLF: wrong title format", xtitle) xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value result = CompiledRegexpAtomTitle.search(xtitle) if result and len(result.groups()) >= 1: # Extract episode title xtitle = result.group(1) # Handle encodings xtitle = str_to_utf8(xtitle) yepisode = (xseason, xepisode, xtitle, self.series) ydelta = delta else: #if delta >= ydelta: break else: self.returnvalue = _("Check the channel name") else: if yepisode: return ( yepisode ) if delta <= 600: # Compare channels? logInfo("WLF: Max time trift exceeded", delta) if yepisode: return ( yepisode ) else: logInfo("WLF: No data returned") # Nothing found return
def getNextPage(self, id, page): url = EPISODEIDURL % (id, page) data = self.getPage(url) if data and isinstance(data, basestring): logDebug("FS: getNextPage: basestring") data = self.parseNextPage(data) self.doCacheList(url, data) if data and isinstance(data, list): logDebug("FS: getNextPage: list") trs = data # Set preconditions yepisode = None ydelta = maxint # Idea: # Sort the trs by datetime to avoid the direction handling # But the overhead of calculating the datetime and sorting them is too big first_on_page = parseDate( trs[0][COL_DATETIME] ) last_on_page = parseDate( trs[-1][COL_DATETIME] ) # Check if we got a new page # You can increment/decrement the paging number endless and You will always receive the last valid page which is never changing if page == 0: new_page = True logDebug("FS: first_on_page, last_on_page: ", first_on_page, last_on_page) else: new_page = (self.first_on_prev_page != first_on_page or self.last_on_prev_page != last_on_page) logDebug("FS: first_on_prev_page, first_on_page, last_on_prev_page, last_on_page, if: ", self.first_on_prev_page, first_on_page, self.last_on_prev_page, last_on_page, new_page) self.first_on_prev_page = first_on_page self.last_on_prev_page = last_on_page if new_page: # Check direction because the sort order (datetime) will change # True = future # False = past direction = first_on_page < last_on_page if direction: # True = future # 2015-11-04 - first_on_page # 2015-11-05 - self.begin # 2015-11-06 - last_on_page test_timespan = ( (first_on_page-self.td_max_time_drift) <= self.begin and self.begin <= (last_on_page+self.td_max_time_drift) ) else: # False = past # 2015-11-04 - first_on_page # 2015-11-05 - self.begin # 2015-11-06 - last_on_page test_timespan = ( (first_on_page+self.td_max_time_drift) >= self.begin and self.begin >= (last_on_page-self.td_max_time_drift) ) logDebug("FS: first_on_page, self.begin, last_on_page, basedirection, direction, if:", first_on_page, '-', self.begin, '-', last_on_page, '-', self.direction, '-', direction, '-', test_timespan ) if ( test_timespan ): for tds in trs: #logDebug( "FS: tds", tds ) xbegin = parseDate( tds[COL_DATETIME] ) #Py2.6 delta = abs(self.begin - xbegin) delta = delta.seconds + delta.days * 24 * 3600 #Py2.7 #delta = abs(self.begin - xbegin).total_seconds() logDebug("FS:", self.begin, '-', xbegin, '-', delta, '-', self.max_time_drift) # delta is an absolute value so we can just do a smaller than check if delta <= self.max_time_drift: logInfo("FS: Possible match witch channel: ", tds[COL_CHANNEL]) if self.compareChannels(self.service, tds[COL_CHANNEL]): if delta < ydelta: yepisode = ( tds[COL_SEASON] or config.plugins.seriesplugin.default_season.value, tds[COL_EPISODE] or config.plugins.seriesplugin.default_episode.value, str_to_utf8(tds[COL_TITLE]), self.series ) ydelta = delta # continue and check one further entry maybe we will find a closer match with a smaller delta time else: #if delta >= ydelta: return ( yepisode ) else: self.returnvalue = _("Check the channel name") + " " + tds[COL_CHANNEL] else: if yepisode: return ( yepisode ) if delta <= 600: # Compare channels? logInfo("FS: Max time trift exceeded", delta) if yepisode: return ( yepisode ) else: # Idea: # Maybe we can guess the next page using firstrow lastrow datetime if self.direction: # True = future # 2015-11-04 - first_on_page # 2015-11-05 - # 2015-11-06 - last_on_page # 2015-11-07 - self.begin if self.begin > last_on_page: return self.getNextPage(id, page+1) else: # False = past # 2015-11-03 - self.begin # 2015-11-04 - first_on_page # 2015-11-05 - # 2015-11-06 - last_on_page if first_on_page > self.begin: return self.getNextPage(id, page-1) else: logInfo("FS: No data returned") # Nothing found return
def getEpisode(self, name, begin, end=None, service=None): # On Success: Return a single season, episode, title tuple # On Failure: Return a empty list or String or None # Check dependencies if json is None: msg = _("Error install") + " python-json" logInfo(msg) return msg if BeautifulSoup is None: msg = _("Error install") + " BeautifulSoup" logInfo(msg) return msg # Check preconditions if not name: msg =_("Skip: No show name specified") logInfo(msg) return msg if not begin: msg = _("Skip: No begin timestamp specified") logInfo(msg) return msg if not service: msg = _("Skip: No service specified") logInfo(msg) return msg logInfo("FS: getEpisode, name, begin, end=None, service", name, begin, end, service) self.begin = begin #self.date = str(begin.month) + "." + str(begin.day) + "." self.year = begin.year #self.end = end self.service = service self.series = "" self.first_on_prev_page = None self.last_on_prev_page = None self.td_max_time_drift = timedelta(seconds=self.max_time_drift) self.knownids = [] self.returnvalue = None # True = future # False = past if self.begin > datetime.now(): self.direction = True else: self.direction = False logDebug("FS: getEpisode direction", self.direction) while name: ids = self.getSeries(name) while ids: idserie = ids.pop() if idserie and len(idserie) == 2: id, idname = idserie # Handle encodings self.series = str_to_utf8(idname) logInfo("FS: Possible matched series:", self.series) if self.direction: # The future starts now page = 0 else: if self.actual_year == self.year: # On realtime conditions we could start at page -1 # But the proxy is caching every page for about 24 hours, so we start at page 0 page = 0 else: # We can retrieve the offset of every year to skip several pages page = 0 # Sample #http://www.fernsehserien.de/criminal-intent-verbrechen-im-visier/sendetermine/ year_base_url = EPISODEIDURL % (id, '') logDebug("FS: year_base_url: ", year_base_url) # Increment year by one, because we want to start at the end of the year year = self.year+1 # Sample #http://www.fernsehserien.de/criminal-intent-verbrechen-im-visier/sendetermine/jahr-2014 year_url = year_base_url+"jahr-"+str(year) logDebug("FS: year_url: ", year_url) from Plugins.Extensions.SeriesPlugin.plugin import buildURL response = urlopen( buildURL(year_url) ) # Sample #http://www.fernsehserien.de/criminal-intent-verbrechen-im-visier/sendetermine/-14 redirect_url = response.geturl() logDebug("FS: redirect_url: ", redirect_url) try: # Sample -14 page = int( redirect_url.replace(year_base_url,'') ) except: page = 0 self.first_on_prev_page = None self.last_on_prev_page = None if page is not None: result = self.getNextPage(id, page) if result: return result else: name = self.getAlternativeSeries(name) else: return ( self.returnvalue or _("No matching series found") )
def getNextPage(self, id): logDebug("WLP: getNextPage") url = EPISODEIDURLPRINT + urlencode({"s": id}) data = self.getPage(url) if data and isinstance(data, basestring): data = self.parseNextPage(data) self.doCacheList(url, data) if data and isinstance(data, list): trs = data yepisode = None ydelta = maxint for tds in trs: if tds and len(tds) >= 5: # print tds xchannel, xday, xdate, xbegin, xend = tds[:5] xtitle = "".join(tds[4:]) if self.actual_month == 12 and xdate.endswith(".01."): year = str(self.actual_year + 1) else: year = str(self.actual_year) xbegin = datetime.strptime(xdate + year + xbegin, "%d.%m.%Y%H.%M Uhr") # xend = datetime.strptime( xdate+year+xend, "%d.%m.%Y%H.%M Uhr" ) # logDebug("WLP:", xchannel, xdate, xbegin, xend, xtitle) # logDebug("WLP:", datebegin, xbegin, abs((datebegin - xbegin))) # Py2.6 delta = abs(self.begin - xbegin) delta = delta.seconds + delta.days * 24 * 3600 # Py2.7 # delta = abs(self.begin - xbegin).total_seconds() logDebug("WLP:", self.begin, "-", xbegin, "-", delta, "-", self.max_time_drift) if delta <= self.max_time_drift: logInfo("WLP: Possible match witch channel: ", xchannel) if self.compareChannels(self.service, xchannel): if delta < ydelta: print len(tds), tds if len(tds) >= 7: xepisode, xtitle = tds[5:7] if xepisode: result = CompiledRegexpEpisode.search(xepisode) if result and len(result.groups()) >= 3: xseason = ( result and result.group(2) or config.plugins.seriesplugin.default_season.value ) xepisode = ( result and result.group(3) or config.plugins.seriesplugin.default_episode.value ) else: xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value else: xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value elif len(tds) == 6: xtitle = tds[5] xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value # Handle encodings xtitle = str_to_utf8(xtitle) yepisode = (xseason, xepisode, xtitle, self.series) ydelta = delta else: # if delta >= ydelta: return yepisode else: self.returnvalue = _("Check the channel name") else: if yepisode: return yepisode if delta <= 600: # Compare channels? logInfo("WLP: Max time trift exceeded", delta) if yepisode: return yepisode else: logInfo("WLP: No data returned") # Nothing found return
def getNextPage(self, id): logDebug("WLF: getNextPage") url = EPISODEIDURLATOM + urlencode({'s': id}) data = self.getPage(url) if data and isinstance(data, basestring): data = self.parseNextPage(data) self.doCacheList(url, data) if data and isinstance(data, list): trs = data yepisode = None ydelta = maxint for tds in trs: if tds and len(tds) == 2: xtitle, xupdated = tds if xtitle is not None and xupdated is not None: #import iso8601 #http://code.google.com/p/pyiso8601/ xbegin = parse_date(xupdated) xbegin = xbegin.replace(tzinfo=None) #"2014-11-10T20:15:00+01:00" #xbegin = datetime.strptime(xupdated[0:-6], "%Y-%m-%dT%H:%M:%S"); #Py2.6 delta = abs(self.begin - xbegin) delta = delta.seconds + delta.days * 24 * 3600 #Py2.7 #delta = abs(self.begin - xbegin).total_seconds() logDebug("WLF:", self.begin, '-', xbegin, '-', delta, '-', self.max_time_drift) if delta <= self.max_time_drift: result = CompiledRegexpAtomChannel.search(xtitle) if result and len(result.groups()) >= 1: xchannel = result.group(1) logInfo("WLF: Possible match witch channel: ", xchannel) if self.compareChannels( self.service, xchannel): if delta < ydelta: # Slice string to remove channel xtitle = xtitle[:result.start()] result = CompiledRegexpAtomDate.search( xtitle) if result and len( result.groups()) >= 1: # Slice string to remove date xtitle = xtitle[:result.start()] result = CompiledRegexpAtomEpisode.search( xtitle) if result and len( result.groups()) >= 1: # Extract season and episode xepisode = result.group(1) # Slice string to remove season and episode xtitle = xtitle[:result.start( )] result = CompiledRegexpEpisode.search( xepisode) if result and len( result.groups()) >= 3: xseason = result and result.group( 2 ) or config.plugins.seriesplugin.default_season.value xepisode = result and result.group( 3 ) or config.plugins.seriesplugin.default_episode.value else: logDebug( "WLF: wrong episode format", xepisode) xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value else: logDebug( "WLF: wrong title format", xtitle) xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value result = CompiledRegexpAtomTitle.search( xtitle) if result and len( result.groups()) >= 1: # Extract episode title xtitle = result.group(1) # Handle encodings xtitle = str_to_utf8(xtitle) yepisode = (xseason, xepisode, xtitle, self.series) ydelta = delta else: #if delta >= ydelta: break else: self.returnvalue = _( "Check the channel name") else: if yepisode: return (yepisode) if delta <= 600: # Compare channels? logInfo("WLF: Max time trift exceeded", delta) if yepisode: return (yepisode) else: logInfo("WLF: No data returned") # Nothing found return
def getNextPage(self, id): logDebug("WLP: getNextPage") url = EPISODEIDURLPRINT + urlencode({'s': id}) data = self.getPage(url) if data and isinstance(data, basestring): data = self.parseNextPage(data) self.doCacheList(url, data) if data and isinstance(data, list): trs = data yepisode = None ydelta = maxint for tds in trs: if tds and len(tds) >= 5: #print tds xchannel, xday, xdate, xbegin, xend = tds[:5] xtitle = "".join(tds[4:]) if self.actual_month == 12 and xdate.endswith(".01."): year = str(self.actual_year + 1) else: year = str(self.actual_year) xbegin = datetime.strptime(xdate + year + xbegin, "%d.%m.%Y%H.%M Uhr") #xend = datetime.strptime( xdate+year+xend, "%d.%m.%Y%H.%M Uhr" ) #logDebug("WLP:", xchannel, xdate, xbegin, xend, xtitle) #logDebug("WLP:", datebegin, xbegin, abs((datebegin - xbegin))) #Py2.6 delta = abs(self.begin - xbegin) delta = delta.seconds + delta.days * 24 * 3600 #Py2.7 #delta = abs(self.begin - xbegin).total_seconds() logDebug("WLP:", self.begin, '-', xbegin, '-', delta, '-', self.max_time_drift) if delta <= self.max_time_drift: logInfo("WLP: Possible match witch channel: ", xchannel) if self.compareChannels(self.service, xchannel): if delta < ydelta: print len(tds), tds if len(tds) >= 7: xepisode, xtitle = tds[5:7] if xepisode: result = CompiledRegexpEpisode.search( xepisode) if result and len( result.groups()) >= 3: xseason = result and result.group( 2 ) or config.plugins.seriesplugin.default_season.value xepisode = result and result.group( 3 ) or config.plugins.seriesplugin.default_episode.value else: xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value else: xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value elif len(tds) == 6: xtitle = tds[5] xseason = config.plugins.seriesplugin.default_season.value xepisode = config.plugins.seriesplugin.default_episode.value # Handle encodings xtitle = str_to_utf8(xtitle) yepisode = (xseason, xepisode, xtitle, self.series) ydelta = delta else: #if delta >= ydelta: return (yepisode) else: self.returnvalue = _("Check the channel name") else: if yepisode: return (yepisode) if delta <= 600: # Compare channels? logInfo("WLP: Max time trift exceeded", delta) if yepisode: return (yepisode) else: logInfo("WLP: No data returned") # Nothing found return