def isEnigma2Recording(self, name): try: if os.path.isfile(Utf8.utf8ToLatin(name + u".meta")): printl("Found E2 meta file: " + str(Utf8.utf8ToLatin(name + u".meta")), self) return True except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def isNfoAvailable(self, name): try: printl("Check presence of nfo file: " + Utf8.utf8ToLatin(name + u".nfo"), self, "I") if os.path.isfile(Utf8.utf8ToLatin(name + u".nfo")): return True except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def addCache(url, text): # this line should be moved to a more suitable place createCacheFolder() try: if folderSize(cacheDir) > 4.0 or freeSpace(cacheDir) < 2.0: #10mb for f in os.listdir(cacheDir): file = os.path.join(cacheDir, f) printl("RM: " + str(file), __name__) os.remove(file) cacheFile = re.sub(r'\W', "", url).strip() cacheFileName = cacheDir + u"/" + cacheFile + u".cache" if text is not None and len(text) > 0: f = Utf8.Utf8(cacheFileName, "w") f.write(text) f.close if os.path.getsize(Utf8.utf8ToLatin(cacheFileName)) == 0: os.remove(Utf8.utf8ToLatin(cacheFileName)) except Exception, ex: printl("Exception (ef): " + str(ex), __name__, "E") printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
def isNfoAvailable(self, name): try: printl( "Check presence of nfo file: " + Utf8.utf8ToLatin(name + u".nfo"), self, "I") if os.path.isfile(Utf8.utf8ToLatin(name + u".nfo")): return True except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def isEnigma2Recording(self, name): try: if os.path.isfile(Utf8.utf8ToLatin(name + u".meta")): printl( "Found E2 meta file: " + str(Utf8.utf8ToLatin(name + u".meta")), self) return True except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def removeFromCache(url): try: cacheFile = re.sub(r'\W', "", url).strip() cacheFileName = cacheDir + u"/" + cacheFile + u".cache" if os.path.isfile(Utf8.utf8ToLatin(cacheFileName)): os.remove(Utf8.utf8ToLatin(cacheFileName)) except Exception, ex: printl("Exception (ef): " + str(ex), __name__, "E") printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
def setValerieInfoLastAccessTime(self, path): try: if os.path.isfile(Utf8.utf8ToLatin(path + u"/valerie.info")): time = int(os.path.getctime(Utf8.utf8ToLatin(path + u"/valerie.info"))) f = Utf8.Utf8(path + u"/.access", "w") time = f.write(str(time) + u"\n") f.close() elif os.path.isfile(Utf8.utf8ToLatin(path + u"/.access")): os.remove(Utf8.utf8ToLatin(path + u"/.access")) except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def getValerieInfoAccessTime(self, path): time = 0 try: if os.path.isfile(Utf8.utf8ToLatin(path + u"/valerie.info")): try: time = int(os.path.getctime(Utf8.utf8ToLatin(path + u"/valerie.info"))) except Exception, ex: printl("Exception: " + str(ex), self) printl("\t" + str(Utf8.utf8ToLatin(path + u"/valerie.info")), self) except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def setValerieInfoLastAccessTime(self, path): try: if os.path.isfile(Utf8.utf8ToLatin(path + u"/valerie.info")): time = int( os.path.getctime(Utf8.utf8ToLatin(path + u"/valerie.info"))) f = Utf8.Utf8(path + u"/.access", "w") time = f.write(str(time) + u"\n") f.close() elif os.path.isfile(Utf8.utf8ToLatin(path + u"/.access")): os.remove(Utf8.utf8ToLatin(path + u"/.access")) except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def checkCache(url): try: cacheFile = re.sub(r'\W', "", url).strip() cacheFileName = cacheDir + u"/" + cacheFile + u".cache" rtv = None if os.path.isfile(Utf8.utf8ToLatin(cacheFileName)): if os.path.getsize(Utf8.utf8ToLatin(cacheFileName)) == 0: os.remove(Utf8.utf8ToLatin(cacheFileName)) return rtv f = Utf8.Utf8(cacheDir + u"/" + cacheFile + u".cache", "r") rtv = f.read() f.close() except Exception, ex: printl("Exception (ef): " + str(ex), __name__, "E") printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
def getXml(url, rawXml=None, cache=True): if rawXml is None: rawXml = getText(url, cache=cache) if rawXml is None: return None decodedXml = None try: decodedXml = minidom.parseString(rawXml.encode( "utf-8", 'ignore' )) printl("encoded utf-8") return decodedXml except Exception, ex: printl("minidom.parseString as utf-8 failed, retrieing as latin-1. Ex: " + str(ex), __name__, "W") try: decodedXml = minidom.parseString(rawXml.encode( "latin-1", 'ignore' )) printl("encoded latin-1") return decodedXml except Exception, ex: printl("minidom.parseString as utf-8 failed, retrieing as windows-1252. Ex: " + str(ex), __name__, "W") try: decodedXml = minidom.parseString(rawXml.encode( "windows-1252", 'ignore' )) printl("encoded iso8859-1") return decodedXml except Exception, ex: printl("minidom.parseString as utf-8 failed, retrieing as utf-8. Ex: " + str(ex), __name__, "W") try: decodedXml = minidom.parseString(rawXml.decode("cp1252").encode("utf-8")) printl("encoded cp1252") return decodedXml except Exception, ex: printl("minidom.parseString as utf-8 and latin-1 failed, ignoring. Ex: " + str(ex), __name__, "E") printl("URL: " + str(Utf8.utf8ToLatin(url)), __name__, "E") printl("<" + str(type(ex)) + "> Ex: " + str(ex), __name__, "E")
def getPlot(self, info, html): printl("->", self) plot = self.getDetails(html) if plot is None: printl("<- (if plot is None: a)", self, "W") return None #print "plot", plot pos = plot.find(self.DIV_PLOT_START) if pos < 0: printl("Details " + plot, self, "W") printl("<- (if pos < 0: b)", self, "W") return None plot = plot[pos + len(self.DIV_PLOT_START):] pos = plot.find(self.DIV_PLOT_END) if pos < 0: printl("<- (if pos < 0: c)", self, "W") return None plot = plot[0:pos] plot = plot.strip() info.Plot = plot info.Plot += u" [M.IMDB.COM]" printl("<- Plot: " + Utf8.utf8ToLatin(plot), self) return info
def getGenre(self, info, html): printl("->", self) genre = self.getDetails(html) if genre is None: printl("<- (if genre is None: a)", self, "W") return None #print "genre", genre pos = genre.find(self.DIV_GENRE_START) if pos < 0: printl("Details " + genre, self, "W") printl("<- (if pos < 0: b)", self, "W") return None genre = genre[pos + len(self.DIV_GENRE_START):] pos = genre.find(self.DIV_GENRE_END) if pos < 0: printl("<- (if pos < 0: c)", self, "W") return None genre = genre[0:pos] genre = genre.strip() if len(genre) < 3: printl("<- (en(genre) < 3)", self, "W") return None info.Genres = u"" genres = genre.split(", ") for genre in genres: info.Genres += genre + u"|" if len(info.Genres) > 1: info.Genres = info.Genres[:len(info.Genres) - 1] printl("<- Genres: " + Utf8.utf8ToLatin(info.Genres), self) return info
def getValerieInfoAccessTime(self, path): time = 0 try: if os.path.isfile(Utf8.utf8ToLatin(path + u"/valerie.info")): try: time = int( os.path.getctime( Utf8.utf8ToLatin(path + u"/valerie.info"))) except Exception, ex: printl("Exception: " + str(ex), self) printl( "\t" + str(Utf8.utf8ToLatin(path + u"/valerie.info")), self) except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def _fillMediaInfo(self, m, key_value_dict): printl("->", self, "S") printl(key_value_dict, self) for key in key_value_dict.keys(): try: typeOfValue = self._getTypeOfValue(key_value_dict[key]) if (typeOfValue == "int"): # To avoid null Values if key_value_dict[key] is None or key_value_dict[key] == "" or key_value_dict[key] == "None": value = None else: value = int(key_value_dict[key]) elif (typeOfValue == "none"): pass else: # check is in Utf8 if not isinstance(key_value_dict[key], unicode): try: value = Utf8.stringToUtf8(key_value_dict[key]) except Exception, ex: printl("Key conversion to Utf8 error: "+ repr(key) + " Ex: " + str(ex), self) value = key_value_dict[key] else: value = key_value_dict[key]
def parseNfo(self, name): try: printl("-> About to read from nfo-file: " + name + u".nfo", self, "I") f = Utf8.Utf8(name + u".nfo", "r") lines = f.read() f.close() if lines is not None: printl("Checking type of file...", self, "I") lines = lines.split(u"\n") if len(lines) > 1: lines[1] = lines[1].strip() if lines[1].startswith("<movie") or lines[1].startswith( "<episodedetails>"): printl("<- Found xbmc-style nfo...", self, "I") self.isXbmcNfo = True return self.parseNfoXbmc(lines) else: printl( "<- Multiple lines, but no xbmc-style nfo - checking for IMDb-ID nfo...", self, "I") return self.getImdbIdFromNfo(lines) elif len(lines) == 1: printl("<- Might be IMDb-ID nfo...", self, "I") return self.getImdbIdFromNfo(lines) else: printl("<-", self, "C") return None return None except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def cleanValuesOfMedia(self, media): if media.ImdbId == u"tt0000000": media.ImdbId = u"" if media.TheTvDbId == u"0": media.TheTvDbId = u"" if media.TmDbId == u"0": media.TmDbId = u"" if media.Year == -1: media.Year = None if media.Month == -1: media.Month = None if media.Day == -1: media.Day = None if media.Season == -1: media.Season = None if media.Episode == -1: media.Episode = None if media.Runtime == 0: media.Runtime = None if media.Popularity == 0: media.Popularity = None if media.MediaType is None: media.MediaType = MediaInfo.UNKNOWN # ERR title... don't come in UTF-8 if not isinstance(media.Path, unicode): media.Path = Utf8.stringToUtf8(media.Path) if not isinstance(media.Filename, unicode): media.Filename = Utf8.stringToUtf8(media.Filename) if not isinstance(media.Extension, unicode): media.Extension = Utf8.stringToUtf8(media.Extension) if not isinstance(media.Title, unicode): media.Title = Utf8.stringToUtf8(media.Title) if not isinstance(media.Resolution, unicode): media.Resolution = Utf8.stringToUtf8(media.Resolution) if not isinstance(media.Sound, unicode): media.Sound = Utf8.stringToUtf8(media.Sound) if not isinstance(media.Plot, unicode): media.Plot = Utf8.stringToUtf8(media.Plot) if not isinstance(media.Genres, unicode): media.Genres = Utf8.stringToUtf8(media.Genres) if not isinstance(media.Tag, unicode): media.Tag = Utf8.stringToUtf8(media.Tag) if not isinstance(media.Tag, unicode): media.Tag = Utf8.stringToUtf8(media.Tag)
def cleanValuesOfMedia(self, media): if media.ImdbId == u"tt0000000": media.ImdbId = u""; if media.TheTvDbId == u"0": media.TheTvDbId = u""; if media.TmDbId == u"0": media.TmDbId = u""; if media.Year == -1: media.Year = None; if media.Month == -1: media.Month = None; if media.Day == -1: media.Day = None; if media.Season == -1: media.Season = None; if media.Episode == -1: media.Episode = None; if media.Runtime == 0: media.Runtime = None; if media.Popularity == 0: media.Popularity = None; if media.MediaType is None: media.MediaType = MediaInfo.UNKNOWN; # ERR title... don't come in UTF-8 if not isinstance(media.Path, unicode): media.Path = Utf8.stringToUtf8(media.Path) if not isinstance(media. Filename, unicode): media.Filename = Utf8.stringToUtf8(media.Filename) if not isinstance(media.Extension, unicode): media.Extension = Utf8.stringToUtf8(media.Extension) if not isinstance(media.Title, unicode): media.Title = Utf8.stringToUtf8(media.Title) if not isinstance(media.Resolution, unicode): media.Resolution = Utf8.stringToUtf8(media.Resolution) if not isinstance(media.Sound, unicode): media.Sound = Utf8.stringToUtf8(media.Sound) if not isinstance(media.Plot, unicode): media.Plot = Utf8.stringToUtf8(media.Plot) if not isinstance(media.Genres, unicode): media.Genres = Utf8.stringToUtf8(media.Genres) if not isinstance(media.Tag, unicode): media.Tag = Utf8.stringToUtf8(media.Tag) if not isinstance(media.Tag, unicode): media.Tag = Utf8.stringToUtf8(media.Tag)
def getHtml(url, cache=True): try: rawHtml = getText(url, cache=cache) decodedHtml = None if rawHtml is not None: decodedHtml = decode_htmlentities(rawHtml) except Exception, ex: printl("Exception (ef): " + str(ex), __name__, "E") printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
def _setFileInfo(self, m): if not isinstance(m.Path, unicode): m.Path = Utf8.stringToUtf8(m.Path) if not isinstance(m.Filename, unicode): m.Filename = Utf8.stringToUtf8(m.Filename) if not isinstance(m.Extension, unicode): m.Extension = Utf8.stringToUtf8(m.Extension) path = Utf8.utf8ToLatin(str(m.Path) + u"/" + str(m.Filename) + u"." + str(m.Extension)) if os.path.exists(path): try: m.FileCreation = os.stat(path).st_mtime m.FileSize = os.stat(path).st_size #m.CRCSize = 100 #m.CRC = self.getCRC32OfMedia(m) except Exception, ex: printl("Exception(" + str(type(ex)) + "): " + str(ex), self, "W") m.FileCreation = 0
def _verifyAndDeleteMissingFiles(self, records): for m in records: # don't verify series, will remaian with episodes count =0 is needed if m.isTypeSerie(): continue path = m.Path + u"/" + m.Filename + u"." + m.Extension #printl("path: " + path, self) if os.path.exists(Utf8.utf8ToLatin(path)) is False: self.dbHandler.markAsMissing(m.Id)
def save(): global blackList if blackList is None: self.load() fconf = Utf8.Utf8(config.plugins.pvmc.configfolderpath.value + "blacklist.conf", "w") for file in blackList: fconf.write(file + u"\n") fconf.close()
def getValerieInfoLastAccessTime(self, path): time = 0 try: if os.path.isfile(Utf8.utf8ToLatin(path + u"/.access")): f = Utf8.Utf8(path + u"/.access", "r") lines = f.read() if lines is not None: lines = lines.split(u"\n") if len(lines) >= 1: try: lines = lines[0].split(".") time = int(lines[0]) except Exception, ex: printl("Exception: " + str(ex), self) printl("\t" + str(Utf8.utf8ToLatin(path + u"/.access")), self) f.close() except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def getCRC32OfMedia(self, media): media.CRCOffset = 0 if media.Extension.lower() == u"ifo": filename = Utf8.utf8ToLatin(media.Path + u"/VIDEO_TS.VOB") else: filename = Utf8.utf8ToLatin(media.Path + u"/" + media.Filename + u"." + media.Extension) if media.FileSize <= 1000: media.CRCSize = media.FileSize else: media.CRCOffset = 200 media.CRCFile = filename #filename f = file(filename, 'rb') f.seek(media.CRCOffset) x = f.read(media.CRCSize) f.close() x = binascii.crc32(x) #binascii.a2b_hex('18329a7e') return format(x & 0xFFFFFFFF, '08x')
def getValerieInfo(self, path): try: f = Utf8.Utf8(path + u"/valerie.info", "r") lines = f.read() if lines is not None: lines = lines.split(u"\n") name = None if len(lines) >= 1: name = lines[0] f.close() except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def __str__(self): printl("->", self, "S") try: rtv = unicode(self.getMediaCount(MediaInfo.MOVIE)) + \ u" " + \ unicode(self.getMediaCount(MediaInfo.SERIE)) + \ u" " + \ unicode(self.getMediaCount(MediaInfo.EPISODE)) return Utf8.utf8ToLatin(rtv) except Exception, ex: printl("Error retriving _str_: " + str(ex), self, "W") return "Error retriving _str_"
def __str__(self): printl("->", self, "S") try: rtv = unicode(self.getMediaCount(MediaInfo.MOVIE)) + \ u" " + \ unicode(self.getMediaCount(MediaInfo.SERIE)) + \ u" " + \ unicode(self.getMediaCount(MediaInfo.EPISODE)) return Utf8.utf8ToLatin(rtv) except Exception, ex: printl("Error retriving _str_: "+ str(ex), self, "W") return "Error retriving _str_"
def getValerieInfoLastAccessTime(self, path): time = 0 try: if os.path.isfile(Utf8.utf8ToLatin(path + u"/.access")): f = Utf8.Utf8(path + u"/.access", "r") lines = f.read() if lines is not None: lines = lines.split(u"\n") if len(lines) >= 1: try: lines = lines[0].split(".") time = int(lines[0]) except Exception, ex: printl("Exception: " + str(ex), self) printl( "\t" + str(Utf8.utf8ToLatin(path + u"/.access")), self) f.close() except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
def getFile(url, name, retry=3, fixurl=True, overwrite=False): #printl("overwrite => " + str(overwrite), __name__, "I") try: if name[:1] == "/": # Filename is absolut localFilename = name else: localFilename = downloadDir + "/" + name url = url.strip() # Just to be on the save side if os.path.isfile(Utf8.utf8ToLatin(localFilename)) is False or overwrite is True: for i in range(retry): try: fixedurl = Utf8.utf8ToLatin(url) if fixurl: fixedurl = url_fix(Utf8.utf8ToLatin(url)) opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.7.62 Version/11.01')] if version_info[1] >= 6: page = opener.open(fixedurl, timeout=10) else: socket.setdefaulttimeout(10) page = opener.open(fixedurl) #page = urllib2.urlopen(url_fix(Utf8.utf8ToLatin(url))) f = open(Utf8.utf8ToLatin(localFilename), 'wb') f.write(page.read()) f.close() break except Exception, ex: printl("File download failed. Ex: " + str(ex), __name__) printl("Name: " + str(Utf8.utf8ToLatin(name)), __name__) printl("Url: " + str(Utf8.utf8ToLatin(url)), __name__) printl("type(ex): " + str(type(ex)), __name__) else:
def load(): global blackList printl("loading blackList") if os.path.exists(config.plugins.pvmc.configfolderpath.value + "blacklist.conf"): try: del blackList[:] fconf = Utf8.Utf8(config.plugins.pvmc.configfolderpath.value + "blacklist.conf", "r") blackList = fconf.read().split(u"\n") printl("blacklist loaded " + str(len(blackList))+ " entries", __name__, "I") fconf.close() except Exception, ex: printl("something went wrong reading blackList.conf", __name__, "E") blackList = []
def getEnigma2RecordingName(self, name): try: e2info = None printl("Read from '" + name + u".meta" + "'", self, "I") f = Utf8.Utf8(name + u".meta", "r") lines = f.read() if lines is None: f.close() f = open(name + u".meta", "r") lines = f.read() lines = Utf8.stringToUtf8(lines) if lines is not None: lines = lines.split(u"\n") if len(lines) > 2: printl( "MovieName = '" + lines[1] + "' - EpisodeName = '" + lines[2] + "'", self, "I") e2info = self.Enimga2MetaInfo(lines[1], lines[2]) f.close() return e2info except Exception, ex: printl("Exception (ef): " + str(ex), self, "E") return None
def updateAll(self, notifyOutput=None, notifyProgress=None, notifyRange=None): episodes = self.getAll(self.TVSHOWSEPISODES) total = len(episodes) progress = 0 if notifyRange is not None: notifyRange(total) if notifyProgress is not None: notifyProgress(0) for episode in episodes: if episode.Title is None or episode.Season is None or episode.Episode is None: continue tvshow = self.getMedia(episode.ParentId) if episode.Title == tvshow.Title: printl( "Episode has same title as tvshow so probably update needed (%s %dx%d)" % (episode.Title, episode.Season, episode.Episode), self, "I") if notifyOutput is not None: notifyOutput( Utf8.utf8ToLatin( "Updating %s %dx%d" % (episode.Title, episode.Season, episode.Episode))) id = episode.Id seen = self.isMediaSeen(episode.Id) episode.setMediaType(episode.SERIE) newElement = Sync().syncWithId(episode) if newElement is not None: if len(newElement) == 2: episode = newElement[1] else: episode = newElement[0] self.deleteMedia(id) ret = self.insertMedia(episode) if seen: self.MarkAsSeen(ret["id"]) progress = progress + 1 printl( "Update progress %.2f (%d/%d)" % ((progress / total) * 100.0, progress, total), self, "I") if notifyProgress is not None: notifyProgress(progress) notifyProgress(total)
def updateAll(self, notifyOutput=None, notifyProgress=None, notifyRange=None): episodes = self.getAll(self.TVSHOWSEPISODES) total = len(episodes) progress = 0 if notifyRange is not None: notifyRange(total) if notifyProgress is not None: notifyProgress(0) for episode in episodes: if episode.Title is None or episode.Season is None or episode.Episode is None: continue tvshow = self.getMedia(episode.ParentId) if episode.Title == tvshow.Title: printl( "Episode has same title as tvshow so probably update needed (%s %dx%d)" % (episode.Title, episode.Season, episode.Episode), self, "I", ) if notifyOutput is not None: notifyOutput( Utf8.utf8ToLatin("Updating %s %dx%d" % (episode.Title, episode.Season, episode.Episode)) ) id = episode.Id seen = self.isMediaSeen(episode.Id) episode.setMediaType(episode.SERIE) newElement = Sync().syncWithId(episode) if newElement is not None: if len(newElement) == 2: episode = newElement[1] else: episode = newElement[0] self.deleteMedia(id) ret = self.insertMedia(episode) if seen: self.MarkAsSeen(ret["id"]) progress = progress + 1 printl("Update progress %.2f (%d/%d)" % ((progress / total) * 100.0, progress, total), self, "I") if notifyProgress is not None: notifyProgress(progress) notifyProgress(total)
def getEnigma2RecordingName(self, name): try: e2info = None printl("Read from '" + name + u".meta" + "'", self, "I") f = Utf8.Utf8(name + u".meta", "r") lines = f.read() if lines is None: f.close() f = open(name + u".meta", "r") lines = f.read() lines = Utf8.stringToUtf8(lines) if lines is not None: lines = lines.split(u"\n") if len(lines) > 2: printl("MovieName = '" + lines[1] + "' - EpisodeName = '" + lines[2] + "'", self, "I") e2info = self.Enimga2MetaInfo(lines[1], lines[2]) f.close() return e2info except Exception, ex: printl("Exception (ef): " + str(ex), self, "E") return None
def getTitle(self, info, html): printl("->", self) title = self.getInfo(html) if title is None: printl("<- (if title is None: a)", self, "W") return None #print "tag", tag pos = title.find(self.DIV_TITLE2_START) if pos < 0: printl("<- (if pos < 0: b)", self, "W") return None title = title[pos + len(self.DIV_TITLE2_START):] pos = title.find(self.DIV_TITLE2_END) if pos < 0: printl("<- (if pos < 0: c)", self, "W") return None title = title[0:pos] title = title.strip() info.Title = title printl("<- Title: " + Utf8.utf8ToLatin(title), self) return info
def __str__(self): return Utf8.utf8ToLatin(self.Title + u":" + self.Season + u":" + self.Episode + u":" + self.ImdbId)
def run(self): self.doAbort = False self.output(_("Loading Config")) Blacklist.load() printl(str(len(Blacklist.get())) +" entrys") self.output(_("Loading Data")) printl("Loading Data", self) db = Database().getInstance() if self.mode == self.UPDATE: from Manager import Manager Manager().updateAll(self.output, self.progress, self.range) self.output(_("Saving database")) printl("Saving database", self) db.save() self.output(_("Done")) printl("Done", self) self.output("---------------------------------------------------") self.output(_("Press Exit / Back")) self.finished(True) return #temporarly - there are only failed, missing webif #db.deleteMediaFilesNotOk() if self.mode != self.FAST and SyncConfig().getInstance().get("delete") is True: db.deleteMissingFiles() if self.mode != self.FAST: db.transformGenres() printl("Entries: " + str(db), self) self.output(_("Loading Replacements")) printl("Loading Replacements", self) replace.load() posterSize = Arts.posterResolution[0] if self.dSize.width() == 720 and self.dSize.height() == 576: posterSize = Arts.posterResolution[0] elif self.dSize.width() == 1024 and self.dSize.height() == 576: posterSize = Arts.posterResolution[1] elif self.dSize.width() == 1280 and self.dSize.height() == 720: posterSize = Arts.posterResolution[2] self.output(_("Loading Filesystem")) printl("Loading Filesystem", self) ds = DirectoryScanner.DirectoryScanner() ds.clear() if self.mode == self.FAST: ds.load() pathsConfig = PathsConfig().getInstance() filetypes = pathsConfig.getFileTypes() self.output(_("Extensions:") + ' ' + str(filetypes)) printl("Extensions: " + str(filetypes), self) self.output(_("Searching for media files")) printl("Searching for media files", self) start_time = time.time() folderList = [] elementList = [] # if there are no folder it will crash on » del elementlist #Zuki elementListFileCounter = 0 for searchpath in pathsConfig.getPaths(): if searchpath["enabled"] is False: continue path = searchpath["directory"] folderType = searchpath["type"] useFolder = searchpath["usefolder"] if os.path.isdir(path) is False: continue ds.setDirectory(Utf8.utf8ToLatin(path)) ds.listDirectory(filetypes, "(sample)|(VTS)|(^\\.)") filelist = ds.getFileList() elementListFileCounter += len(filelist) folderList.append((filelist, folderType, useFolder, )) elapsed_time = time.time() - start_time printl("Searching for media files took: " + str(elapsed_time), self) if elementListFileCounter == 0: self.output(_("Found") + ' ' + str(0) + ' ' + _("media files")) printl("Found 0 media files", self) else: self.output(_("Found") + ' ' + str(elementListFileCounter) + ' ' + _("media files")) printl("Found " + str(elementListFileCounter) + " media files", self) self.range(elementListFileCounter) i = 0 for folder in folderList: #print "folder", folder elementList = folder[0] folderType = folder[1] useFolder = folder[2] if self.doAbort: break for element in elementList: i += 1 self.progress(i) pathOrig = element[0].replace("\\", "/") filenameOrig = element[1] extensionOrig = element[2] printl("*"*100, self, "I") printl("* Next file to sync: " + str(pathOrig) + "/" + str(filenameOrig) + "." + str(extensionOrig), self, "I") printl("*"*100, self, "I") path = Utf8.stringToUtf8(pathOrig) filename = Utf8.stringToUtf8(filenameOrig) extension = Utf8.stringToUtf8(extensionOrig) if self.doAbort: break if path is None or filename is None or extension is None: printl("Path or filename or extension is None => skip!", self, "I") continue if "RECYCLE.BIN" in path or ".AppleDouble" in path: printl("Special directory => skip!", self, "I") continue if (filename + u"." + extension) in Blacklist.get(): printl("File is blacklisted => skip!", self, "I") continue #printl("testing 1", self) printl("Checking for duplicates...", self, "I") retCheckDuplicate= db.checkDuplicate(path, filename, extension) mediaInDb = retCheckDuplicate["mediafile"] # if never sync with success delete db entry and resync if mediaInDb is not None and retCheckDuplicate["mediafile"].syncErrNo == MediaInfo.STATUS_INFONOTFOUND: # exist printl("Deleting and resync FailedItem", self) db.deleteMedia(retCheckDuplicate["mediafile"].Id) mediaInDb = None if mediaInDb is not None: printl("Media exists in database...", self, "I") if retCheckDuplicate["reason"] == 1: # exist m2 = retCheckDuplicate["mediafile"] if m2.syncErrNo == 0 and m2.MediaStatus != MediaInfo.STATUS_OK: #printl("Sync - Duplicate Found :" + str(m2.Path) + "/" + str(m2.Filename) + "." + str(m2.Extension), self) key_value_dict = {} key_value_dict["Id"] = m2.Id key_value_dict["MediaStatus"] = MediaInfo.STATUS_OK #key_value_dict["syncErrNo"] = 0 key_value_dict["syncFailedCause"] = u"" printl("Sync - Update Media 1", self) if not db.updateMediaWithDict(key_value_dict): printl("Sync - Update Media 1 - Failed", self) elif retCheckDuplicate["reason"] == 2: # exist on other path, change record path m2 = retCheckDuplicate["mediafile"] if m2.syncErrNo == 0: printl("Sync - Duplicate Found on other path:" + str(m2.Path) + "/" + str(m2.Filename) + "." + str(m2.Extension), self) key_value_dict = {} key_value_dict["Id"] = m2.Id key_value_dict["Path"] = path key_value_dict["MediaStatus"] = MediaInfo.STATUS_OK #key_value_dict["syncErrNo"] = 0 key_value_dict["syncFailedCause"] = u"" printl("Sync - Update Media 2", self) if not db.updateMediaWithDict(key_value_dict): printl("Sync - Update Media 2 - Failed", self) # take lots of time to write on screen, we have the progressbar #self.output("Already in db [ " + Utf8.utf8ToLatin(filename) + " ]") #printl("testing 2", self) if Arts().isMissing(mediaInDb): printl("=> Arts missing in Db!...", self, "I") #self.output("Downloading missing poster") tmp = None if mediaInDb.isTypeMovie(): tmp = TheMovieDbProvider().getArtByImdbId(mediaInDb) elif mediaInDb.isTypeEpisode(): tvshow = db.getMediaWithTheTvDbId(mediaInDb.TheTvDbId) #printl(str(tvshow.SeasonPoster), self, "E") tvshow.SeasonPoster.clear() # Make sure that there are no residues tmp = TheTvDbProvider().getArtByTheTvDbId(tvshow) if tmp is not None: printl(str(tmp.SeasonPoster), self, "E") if tmp is not None: Arts().download(tmp) if mediaInDb.isTypeMovie(): self.info(str(mediaInDb.ImdbId) + "_poster_" + posterSize + ".png", "", "") elif mediaInDb.isTypeSerie() or mediaInDb.isTypeEpisode(): self.info(str(mediaInDb.TheTvDbId) + "_poster_" + posterSize + ".png", "", "") del tmp del mediaInDb continue outStr = "(" + str(i) + "/" + str(elementListFileCounter) + ")" self.output(outStr + " -> " + getStringShrinked(pathOrig) + " >> " + filenameOrig + "." + extensionOrig) printl("#"*30, self) printl("(" + str(i) + "/" + str(elementListFileCounter) + ")", self) printl("#"*6, self) printl(" -> " + pathOrig + "\n " + filenameOrig + "." + extensionOrig, self) elementInfo = MediaInfo(path, filename, extension) printl("FOLDERTYPE: " + str(folderType), self) printl("USEFOLDER: " + str(useFolder), self) if folderType == u"MOVIE": elementInfo.setMediaType(MediaInfo.MOVIE) elif folderType == u"TV": elementInfo.setMediaType(MediaInfo.SERIE) else: elementInfo.setMediaType(MediaInfo.UNKNOWN) result = elementInfo.parse(useFolder) if result == False: continue printl("TheTvDbId: " + elementInfo.TheTvDbId, self, "I") if elementInfo.isXbmcNfo == False: printl("isXbmcNfo == False => checking for E2 recorded TV show... ", self, "I") if elementInfo.isTypeSerie() and elementInfo.isEnigma2MetaRecording: if elementInfo.Season == None or elementInfo.Episode == None: printl("E2-recorded TV-Show => trying to get season and episode from E2 episodename... ", self, "I") tmp = GoogleProvider().getSeasonAndEpisodeFromEpisodeName(elementInfo) if (tmp[0] is True) and (tmp[1] is None): #Issue #474 => Don't fall back if foldertype is not explicitely "MOVIE_AND_TV" if folderType == u"MOVIE_AND_TV": printl("E2-recording not recognized as TV show => trying to parse as movie... ", self, "I") elementInfo.setMediaType(MediaInfo.MOVIE) else: elementInfo.MediaType = MediaInfo.UNKNOWN # avoid create serie elementInfo.MediaStatus = MediaInfo.STATUS_INFONOTFOUND elementInfo.syncErrNo = 3 elementInfo.syncFailedCause = u"Info Not Found"# cause printl("Failed to detect TV show and folder type set to 'TV' => adding media as failed...", self, "I") db.insertMedia(elementInfo) continue elif tmp[0] is True: # Issue #205, efo => use tmp[1] instead of tmp... elementInfo = tmp[1] printl("Result from google => Season=" + str(elementInfo.Season) + " / Episode=" + str(elementInfo.Episode), self, "I") else: printl("E2-recorded TV-Show: season and episode already set... ", self, "I") searchStringSplitted = elementInfo.SearchString.split("::") if len(searchStringSplitted) >= 2: elementInfo.SearchString = searchStringSplitted[0] printl("New searchString after split: " + elementInfo.SearchString, self, "I") printl("Get IMDb ID from title using searchString: " + elementInfo.SearchString, self, "I") tmp = MobileImdbComProvider().getMoviesByTitle(elementInfo) if tmp is None: # validate if user use valerie.info with imdb or tvdb if (elementInfo.isTypeSerie() and elementInfo.TheTvDbId == MediaInfo.TheTvDbIdNull) or (elementInfo.isTypeMovie() and elementInfo.ImdbId == MediaInfo.ImdbIdNull): printl("=> nothing found :-( " + elementInfo.SearchString, self, "I") #db.addFailed(FailedEntry(path, filename, extension, FailedEntry.UNKNOWN)) #elementInfo.MediaType = MediaInfo.FAILEDSYNC elementInfo.MediaType = MediaInfo.UNKNOWN # avoid create serie elementInfo.MediaStatus = MediaInfo.STATUS_INFONOTFOUND elementInfo.syncErrNo = 3 elementInfo.syncFailedCause = u"Info Not Found"# cause db.insertMedia(elementInfo) continue else: elementInfo = tmp printl("Finally about to sync element... ", self, "I") results = Sync().syncWithId(elementInfo) else: printl("isXbmcNfo == True => using data from nfo:\n" + str(elementInfo), self, "I") results = (elementInfo, ) if results is not None: printl("results: "+str(results), self) for result in results: result.MediaStatus = MediaInfo.STATUS_OK result.syncErrNo = 0 result.syncFailedCause = u"" #printl("INSERT: "+result.Filename+ " type: " + str(result.MediaType) , self, "I") ret = db.insertMedia(result) if ret["status"] > 0: #result.Title = self.encodeMe(result.Title) if result.isTypeMovie(): self.info(str(result.ImdbId) + "_poster_" + posterSize + ".png", result.Title, result.Year) printl("my_title " + result.Title, self, "I") else: self.info(str(result.TheTvDbId) + "_poster_" + posterSize + ".png", result.Title, result.Year) printl("my_title " + result.Title, self, "I") else: # ?????? #cause = db.getAddFailedCauseOf() #db.addFailed(FailedEntry(path, filename, extension, FailedEntry.ALREADY_IN_DB,cause)) #if result.syncFailedCause == u"": # result.syncFailedCause = "DB Insert Error ??" result.MediaType = MediaInfo.FAILEDSYNC try: db.insertMedia(result) except Exception, ex: printl("DB Insert Error ??", self, "W") #self.output("(" + str(i) + "/" + str(elementListFileCounter) + ")") #printl("(" + str(i) + "/" + str(elementListFileCounter) + ")", self) self.progress(i)
def parse(self, useParentFoldernameAsSearchstring=False): printl("->", self, "S") absFilename = self.Path + u"/" + self.Filename + u"." + self.Extension name = self.Filename.lower() self.SearchString = name valerieInfoSearchString = None isSeasonEpisodeFromFilename = False isE2Recording = (self.Extension == u"ts") and (self.isEnigma2Recording(absFilename)) # Avoid Null Titles if self.Title is None or self.Title == "": self.Title = self.Filename if self.isValerieInfoAvailable(self.Path) is True: valerieInfoSearchString = self.getValerieInfo(self.Path).strip() printl("Found valerie.info containing: " + str(Utf8.utf8ToLatin(valerieInfoSearchString)), self) if valerieInfoSearchString == u"ignore": printl("<- found 'ignore'... Returning to sync process and skipping!", self, "I") return False if self.searchForImdbAndTvdbId(valerieInfoSearchString): valerieInfoSearchString = None #################### DVD ##################### if self.Extension.lower() == u"ifo": dirs = self.Path.split(u"/") #vidoets = dirs[len(dirs) - 1] printl("dirs=" + str(dirs), self) self.SearchString = dirs[len(dirs) - 1] # /DVDs/title/VIDEO_TS.ifo if self.SearchString.upper() == u"VIDEO_TS": self.SearchString = dirs[len(dirs) - 2] # /DVDs/title/VIDEO_TS/VIDEO_TS.ifo self.SearchString = self.SearchString.lower() printl("DVD: " + str(Utf8.utf8ToLatin(self.SearchString)), self) #return True #################### DVD ###################### #################### BDMV ##################### if self.Extension.lower() == u"m2ts": dirs = self.Path.split(u"/") printl("dirs=" + str(dirs), self) if dirs[len(dirs) - 1] == "STREAM": if dirs[len(dirs) - 2] == "BDMV": #title/BDMV/STREAM/00000.m2ts self.SearchString = dirs[len(dirs) - 3] else: #title/STREAM/00000.m2ts self.SearchString = dirs[len(dirs) - 2] self.SearchString = self.SearchString.lower() self.Resolution = u"1080p" # Are all bluray in 1080p? self.Sound = u"dts" # Are all bluray in DTS printl("BDMV: " + str(Utf8.utf8ToLatin(self.SearchString)), self) #################### BDMV ###################### ### Replacements PRE printl("Replacements PRE on " + self.SearchString, self, "I") step = 1 for replacement in replace.replacements(u"pre"): old = self.SearchString self.SearchString = resub(replacement[0], replacement[1], self.SearchString) printl("\tStep %d: %s -> %s = %s -> %s" % (step, str(replacement[0].pattern), str(replacement[1]), old, self.SearchString), self, "I") step = step + 1 printl(":-1: " + str(Utf8.utf8ToLatin(self.SearchString)), self) ### Check for IMDb-ID in filename printl("Check for IMDb-ID in filename '" + name + "'", self, "I") self.searchForImdbAndTvdbId(name) if self.isNfoAvailable(self.Path + u"/" + self.Filename): printl("nfo File present - now parsing: " + self.Path + u"/" + self.Filename, self, "I") result = self.parseNfo(self.Path + u"/" + self.Filename) if result is not None: printl(" => nfo File successfully parsed!", self, "I") #self.isMovie = result.isMovie #self.isEpisode = result.isEpisode #self.isSerie = result.isSerie self.MediaType = result.MediaType self.TheTvDbId = result.TheTvDbId self.ImdbId = result.ImdbId self.Title = result.Title self.Plot = result.Plot self.Season = result.Season self.Episode = result.Episode self.Year = result.Year self.Genres = result.Genres self.Runtime = result.Runtime if self.isXbmcNfo == True and self.ImdbId is not None: printl("<- XBMC-style nfo found...", self, "I") return True else: printl("Something went wrong while reading from nfo :-(", self, "I") ### if (self.Year == None) and (isE2Recording == False): m = re.search(r'\s(?P<year>\d{4})\s', self.SearchString) if m and m.group("year"): year = int(m.group("year")) printl("year=" + str(year), self) if year > 1940 and year < 2012: self.Year = year # removing year from searchstring #self.SearchString = replace(str(year), u" ", self.SearchString) #self.SearchString = name[:m.start()] printl(":0: " + str(Utf8.utf8ToLatin(self.SearchString)), self) ### m = re.search(r'720p', name) if m: self.Resolution = u"720p" else: m = re.search(r'1080i', name) if m: self.Resolution = u"1080i" else: m = re.search(r'1080p', name) if m: self.Resolution = u"1080p" ### m = re.search(r'dts', name) if m: self.Sound = u"dts" else: m = re.search(r'dd5', name) if m: self.Sound = u"ac3" else: m = re.search(r'ac3', name) if m: self.Sound = u"ac3" #nameConverted = name if not self.isTypeMovie(): printl("(isMovie is False) => assuming TV show - trying to get season and episode from SearchString: " + self.SearchString, self, "I") ## trying a global expression # m = re.search(r'\W(s(?P<season>\d+))?\s?(d(?P<disc>\d+))?\s?(e(?P<episode>\d+))?([-]?\s?e?(?P<episode2>\d+))?(\D|$)' , self.SearchString) ##### ##### s03d05e01-e05 - Season 3 Disc 5 Episode 1 [to Episode 5] ##### s01d02e03 - Season 3 Disc 5 Episode 1 ##### s01d02 - Season 3 Disc 5 ##### Seinfeld.S08D03.PAL.DVDR if self.Season == None or self.Episode == None: #m =re.search(r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)\s?e(?P<episode>\d+)[-]\s?e?(?P<episode2>\d+)(\D|$)', self.SearchString) m = re.search(r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)\s?(e(?P<episode>\d+))?([-]e?(?P<episode2>\d+))?(\D|$)', self.SearchString) # m = re.search(r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)(\D|$)', self.SearchString) if m and m.group("season") and m.group("disc"): #printl("PARSE RESULT 1:"+str(str(m.group("disc")))+" "+str(m.group("episode"))+" "+str(m.group("episode2")), self) self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = int(m.group("season")) self.Disc = int(m.group("disc")) if m.group("episode") is not None: self.Episode = int(m.group("episode")) if m.group("episode2") is not None: self.EpisodeLast = int(m.group("episode2")) self.SearchString = resub(r's(?P<season>\d+)\s?d(?P<disc>\d+)\s?(e(?P<episode>\d+))?([-]e?(?P<episode2>\d+))?.*', u" ", self.SearchString) ##### ##### s03d05 - Season 3 Disc 5 ##### #if self.Season == None or self.Episode == None: # m = re.search(r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)(\D|$)', self.SearchString) # if m and m.group("season") and m.group("disc"): # printl("PARSE RESULT 3:", self) # self.setMediaType(self.SERIE) # # self.Season = int(m.group("season")) # self.Disc = int(m.group("disc")) # self.Episode = 0 # # self.SearchString = resub(r's(?P<season>\d+)\s?d(?P<disc>\d+).*', u" ", self.SearchString) # ##### ##### s03e05e06 s03e05-e06 s03e05-06 s03e05 06 ##### s03e05 ##### if self.Season == None or self.Episode == None: #m = re.search(r'\Ws(?P<season>\d+)\s?e(?P<episode>\d+)[-]?\s?e?(?P<episode2>\d+)(\D|$)', self.SearchString) #Issue #494, efo => with the "\Ws" expression PVMC doesn't detect season / episodes if pattern is #located at the beginning of string, for example like "s01e02 - title.avi" #m = re.search(r'\Ws(?P<season>\d+)\s?e(?P<episode>\d+)([-]?\s?e?(?P<episode2>\d+))?(\D|$)', self.SearchString) m = re.search(r'(?P<season>\d+)\s?e(?P<episode>\d+)([-]?\s?e?(?P<episode2>\d+))?(\D|$)', self.SearchString) if m and m.group("season") and m.group("episode"): #printl("PARSE RESULT 4:"+str(m.group("episode"))+" "+str(m.group("episode2")), self) self.setMediaType(self.SERIE) self.Season = int(m.group("season")) self.Episode = int(m.group("episode")) # Issue #474, efo isSeasonEpisodeFromFilename = True if m.group("episode2") is not None: self.EpisodeLast = int(m.group("episode2")) self.SearchString = resub(r's(?P<season>\d+)\s?e(?P<episode>\d+)([-]?\s?e?(?P<episode2>\d+))?.*', u" ", self.SearchString) ##### ##### s03e05 ##### # #if self.Season == None or self.Episode == None: # m = re.search(r'\Ws(?P<season>\d+)\s?e(?P<episode>\d+)(\D|$)', self.SearchString) # if m and m.group("season") and m.group("episode"): # printl("PARSE RESULT 5:", self) # self.setMediaType(self.SERIE) # isSeasonEpisodeFromFilename = True # # self.Season = int(m.group("season")) # self.Episode = int(m.group("episode")) # # printl("PARSE RESULT 5: " + self.SearchString, self) # self.SearchString = resub(r's(?P<season>\d+)\s?e(?P<episode>\d+).*', u" ", self.SearchString) # printl("PARSE RESULT 5: " + self.SearchString, self) # ##### ##### e05 ##### if self.Season == None or self.Episode == None: m = re.search(r'\Ws?(e(?P<episode>\d+))([-]?\s?e?(?P<episode2>\d+))?(\D|$)', self.SearchString) if m and m.group("episode"): self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = 0 self.Episode = int(m.group("episode")) if m.group("episode2") is not None: self.EpisodeLast = int(m.group("episode2")) self.SearchString = resub(r's?(e(?P<episode>\d+))([-]?\s?e?(?P<episode2>\d+))?.*', u" ", self.SearchString) ##### ##### d05 - Disc 5 ##### if self.Season == None or self.Episode == None: m = re.search(r'\Wd(?P<disc>\d+)(\D|$)', self.SearchString) if m and m.group("disc"): #printl("PARSE RESULT 3:", self) self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = 0 self.Disc = int(m.group("disc")) self.Episode = 0 self.SearchString = resub(r'd(?P<disc>\d+).*', u" ", self.SearchString) ##### ##### 3x05 ##### if self.Season == None or self.Episode == None: m = re.search(r'\D(?P<season>\d+)x(?P<episode>\d+)(\D|$)', self.SearchString) if m and m.group("season") and m.group("episode"): self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = int(m.group("season")) self.Episode = int(m.group("episode")) self.SearchString = resub(r'(?P<season>\d+)x(?P<episode>\d+).*', u" ", self.SearchString) ##### ##### part 3 ##### if self.Season == None or self.Episode == None: m = re.search(r'\W(part|pt)\s?(?P<episode>\d+)(\D|$)', self.SearchString) if m and m.group("episode"): self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = int(0) self.Episode = int(m.group("episode")) self.SearchString = resub(r'(part|pt)\s?(?P<episode>\d+).*', u" ", self.SearchString) ##### ##### 305 ##### if self.Season == None or self.Episode == None: nameConverted = u"" prevc = u"a" for c in self.SearchString: if (prevc.isdigit() and c.isdigit()) or (prevc.isdigit() is False and c.isdigit() is False): nameConverted += c else: nameConverted += " " + c prevc = c printl("[[[ " + str(Utf8.utf8ToLatin(nameConverted)), self) nameConverted = nameConverted.strip() m = re.search(r'\D(?P<seasonepisode>\d{3,4})(\D|$)', nameConverted) if m and m.group("seasonepisode"): se = int(-1) s = int(-1) e = int(-1) se = int(m.group("seasonepisode")) s = se / 100 e = se % 100 if (s == 2 and e == 64 or s == 7 and e == 20 or s == 10 and e == 80 or s == 0 or s == 19 and e >= 40 or s == 20 and e <= 14) is False: self.setMediaType(self.SERIE) self.Season = s self.Episode = e self.SearchString = resub(r'(?P<seasonepisode>\d{3,4}).*', u" ", nameConverted) if self.Disc == 0: self.Disc = None if self.Episode == 0: self.Episode = None printl(":2: " + str(Utf8.utf8ToLatin(self.SearchString)) + " " + str(self.Season) + " " + str(self.Episode) + " " + str(self.Year), self) if isE2Recording is True: printl("Extension == 'ts' and E2 meta file found => retrieving name from '" + absFilename + "'", self, "I") e2info = self.getEnigma2RecordingName(absFilename) if e2info is not None: printl("e2info: "+ str(Utf8.utf8ToLatin(e2info.MovieName)) + " - " + str(Utf8.utf8ToLatin(e2info.EpisodeName) + "," + str(e2info.IsMovie) + "," + str(e2info.IsEpisode)), self) if e2info.IsMovie: if self.getMediaType() == self.SERIE: printl("E2-Info assumes 'MOVIE' - but foldertype is set to 'TV' => using 'TV'...", self, "I") self.SearchString = "\"" + e2info.MovieName +"\"" + ":: " + "\"" + e2info.EpisodeName + "\"" else: printl("Assuming Movie...", self, "I") self.SearchString = e2info.MovieName self.setMediaType(self.MOVIE) elif e2info.IsEpisode: if self.getMediaType() == self.MOVIE: printl("E2-Info assumes 'TV' - but foldertype is set to 'MOVIE' => using 'MOVIE'...", self, "I") self.SearchString = e2info.MovieName else: # Issue #205, efo => since we have dedicated name + episode name use quotes to enhance google search result self.SearchString = "\"" + e2info.MovieName +"\"" + ":: " + "\"" + e2info.EpisodeName + "\"" printl("Assuming TV-Show...", self, "I") if isSeasonEpisodeFromFilename == False: printl("Season / episode seem not to be retrieved from filename => resetting...", self, "I") self.Season = None self.Episode = None self.setMediaType(self.SERIE) self.isEnigma2MetaRecording = True printl("<- Returning to sync process using E2 meta-file SearchString '" + str(Utf8.utf8ToLatin(self.SearchString)) + "'", self) return True if valerieInfoSearchString is not None: self.SearchString = valerieInfoSearchString printl("<- Returning to sync process using valerie.info SearchString '" + str(Utf8.utf8ToLatin(self.SearchString)) + "'", self) return True if not self.isTypeSerie(): self.setMediaType(self.MOVIE) # So we got year and season and episode # now we can delete everything after the year # but only if the year is not the first word in the string if self.Year is not None: printl("Adapt SearchString due to year...", self, "I") pos = self.SearchString.find(str(self.Year)) if pos > 0: self.SearchString = self.SearchString[:pos] printl(" => SearchString now set to '" + self.SearchString + "'", self, "I") #print ":1: ", self.SearchString ### Replacements POST printl("rpost: " + str(Utf8.utf8ToLatin(self.SearchString)), self) self.SearchString = resub(r'[-]', u" ", self.SearchString) self.SearchString = resub(r' +', u" ", self.SearchString) printl("rpost:: " + str(Utf8.utf8ToLatin(self.SearchString)), self) self.SearchString = self.SearchString.strip() post = u"post" if self.isTypeSerie(): post = u"post_tv" elif self.isTypeMovie(): post = u"post_movie" for replacement in replace.replacements(post): #print "[" + post + "] ", replacement[0], " --> ", replacement[1] self.SearchString = resub(replacement[0], replacement[1], self.SearchString) if useParentFoldernameAsSearchstring: printl("Building search string from parent folder names...", self, "I") try: folders = self.Path.split("/") self.SearchString = folders[len(folders) - 1] # /DVDs/title/VIDEO_TS.ifo if self.SearchString.upper() == u"VIDEO_TS": self.SearchString = folders[len(folders) - 2] # /DVDs/title/VIDEO_TS/VIDEO_TS.ifo self.searchForImdbAndTvdbId(self.SearchString) except Exception, ex: printl("Exception: " + str(ex), self, "E")
def getText(url, cache=True, fixurl=True): try: if cache: utfPage = checkCache(url) else: utfPage = None if utfPage is None: for i in range(RETRIES): printl("-> (" + str(i) + ") " + str(Utf8.utf8ToLatin(url)), __name__) page = None kwargs = {} try: fixedurl = Utf8.utf8ToLatin(url) if fixurl: fixedurl = url_fix(Utf8.utf8ToLatin(url)) opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.7.62 Version/11.01')] if haveGZip is False: opener.addheaders = [('Accept-encoding', 'identity')] if version_info[1] >= 6: page = opener.open(fixedurl, timeout=10) else: socket.setdefaulttimeout(10) page = opener.open(fixedurl) except IOError, ex: printl("IOError: " + str(ex), __name__) continue if page is not None: rawPage = "" #print page #print page.info() if haveGZip: if page.info().get('Content-Encoding') == 'gzip': buf = StringIO(page.read()) f = gzip.GzipFile(fileobj=buf) rawPage = f.read() else: rawPage = page.read() else: # No gzip rawPage = page.read() contenttype = page.headers['Content-type'] #print contenttype try: if contenttype.find("charset=") >= 0: encoding = page.headers['Content-type'].split('charset=')[1] # iso-8859-1 utfPage = rawPage.decode(encoding).encode('utf-8') else: utfPage = Utf8.stringToUtf8(rawPage) except Exception, ex: printl("Exception: " + str(ex), __name__, "W") printl("Fallback to us-latin-1", __name__, "W") #windows-1252 print "------ HEX -------" print toHex(rawPage) utfPage = rawPage.decode("latin-1") print "------ CONVERTED -------" print utfPage utfPage = utfPage.encode('utf-8') print "------ CONVERTED2 -------" print utfPage if cache: addCache(url, utfPage) break
def __str__(self): return Utf8.utf8ToLatin(self.Title + u":" + unicode(self.Year) + u":" + self.ImdbId + u":" + unicode(self.IsTVSeries))
printl("Building search string from parent folder names...", self, "I") try: folders = self.Path.split("/") self.SearchString = folders[len(folders) - 1] # /DVDs/title/VIDEO_TS.ifo if self.SearchString.upper() == u"VIDEO_TS": self.SearchString = folders[ len(folders) - 2] # /DVDs/title/VIDEO_TS/VIDEO_TS.ifo self.searchForImdbAndTvdbId(self.SearchString) except Exception, ex: printl("Exception: " + str(ex), self, "E") self.SearchString = self.SearchString.strip() printl( "<- eof: SearchString:" + str(Utf8.utf8ToLatin(self.SearchString)), self) return True def __str__(self): ustr = u"" try: ustr = self.Path + u" / " + self.Filename + u" . " + self.Extension ustr += u"\n\tType: " + self.strMediaType( self.getMediaType()) ustr += u"\n\tImdbId: " + self.ImdbId ustr += u"\n\tTheTvDbId: " + self.TheTvDbId ustr += u"\n\tTitle: " + self.Title ustr += u"\n\tSearchString: " + self.SearchString ustr += u"\n\tYear: " + unicode(self.Year)
def isValerieInfoAvailable(self, path): try: if os.path.isfile(Utf8.utf8ToLatin(path + u"/valerie.info")): return True except Exception, ex: printl("Exception (ef): " + str(ex), self, "E")
printl("Fallback to us-latin-1", __name__, "W") #windows-1252 print "------ HEX -------" print toHex(rawPage) utfPage = rawPage.decode("latin-1") print "------ CONVERTED -------" print utfPage utfPage = utfPage.encode('utf-8') print "------ CONVERTED2 -------" print utfPage if cache: addCache(url, utfPage) break printl("<- " + str(type(utfPage)) + " " + str(Utf8.utf8ToLatin(url)), __name__) return utfPage except Exception, ex: printl("Exception (ef): " + str(ex), __name__ , "E") printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E") return u"" def getFile(url, name, retry=3, fixurl=True, overwrite=False): #printl("overwrite => " + str(overwrite), __name__, "I") try: if name[:1] == "/": # Filename is absolut localFilename = name else: localFilename = downloadDir + "/" + name
#print "[" + post + "] ", replacement[0], " --> ", replacement[1] self.SearchString = resub(replacement[0], replacement[1], self.SearchString) if useParentFoldernameAsSearchstring: printl("Building search string from parent folder names...", self, "I") try: folders = self.Path.split("/") self.SearchString = folders[len(folders) - 1] # /DVDs/title/VIDEO_TS.ifo if self.SearchString.upper() == u"VIDEO_TS": self.SearchString = folders[len(folders) - 2] # /DVDs/title/VIDEO_TS/VIDEO_TS.ifo self.searchForImdbAndTvdbId(self.SearchString) except Exception, ex: printl("Exception: " + str(ex), self, "E") self.SearchString = self.SearchString.strip() printl("<- eof: SearchString:" + str(Utf8.utf8ToLatin(self.SearchString)), self) return True def __str__(self): ustr = u"" try: ustr = self.Path + u" / " + self.Filename + u" . " + self.Extension ustr += u"\n\tType: " + self.strMediaType(self.getMediaType()) ustr += u"\n\tImdbId: " + self.ImdbId ustr += u"\n\tTheTvDbId: " + self.TheTvDbId ustr += u"\n\tTitle: " + self.Title ustr += u"\n\tSearchString: " + self.SearchString ustr += u"\n\tYear: " + unicode(self.Year) ustr += u"\n\tMonth: " + unicode(self.Month) ustr += u"\n\tDay: " + unicode(self.Day)
def parse(self, useParentFoldernameAsSearchstring=False): printl("->", self, "S") absFilename = self.Path + u"/" + self.Filename + u"." + self.Extension name = self.Filename.lower() self.SearchString = name valerieInfoSearchString = None isSeasonEpisodeFromFilename = False isE2Recording = (self.Extension == u"ts") and (self.isEnigma2Recording(absFilename)) # Avoid Null Titles if self.Title is None or self.Title == "": self.Title = self.Filename if self.isValerieInfoAvailable(self.Path) is True: valerieInfoSearchString = self.getValerieInfo(self.Path).strip() printl( "Found valerie.info containing: " + str(Utf8.utf8ToLatin(valerieInfoSearchString)), self) if valerieInfoSearchString == u"ignore": printl( "<- found 'ignore'... Returning to sync process and skipping!", self, "I") return False if self.searchForImdbAndTvdbId(valerieInfoSearchString): valerieInfoSearchString = None #################### DVD ##################### if self.Extension.lower() == u"ifo": dirs = self.Path.split(u"/") #vidoets = dirs[len(dirs) - 1] printl("dirs=" + str(dirs), self) self.SearchString = dirs[len(dirs) - 1] # /DVDs/title/VIDEO_TS.ifo if self.SearchString.upper() == u"VIDEO_TS": self.SearchString = dirs[ len(dirs) - 2] # /DVDs/title/VIDEO_TS/VIDEO_TS.ifo self.SearchString = self.SearchString.lower() printl("DVD: " + str(Utf8.utf8ToLatin(self.SearchString)), self) #return True #################### DVD ###################### #################### BDMV ##################### if self.Extension.lower() == u"m2ts": dirs = self.Path.split(u"/") printl("dirs=" + str(dirs), self) if dirs[len(dirs) - 1] == "STREAM": if dirs[len(dirs) - 2] == "BDMV": #title/BDMV/STREAM/00000.m2ts self.SearchString = dirs[len(dirs) - 3] else: #title/STREAM/00000.m2ts self.SearchString = dirs[len(dirs) - 2] self.SearchString = self.SearchString.lower() self.Resolution = u"1080p" # Are all bluray in 1080p? self.Sound = u"dts" # Are all bluray in DTS printl("BDMV: " + str(Utf8.utf8ToLatin(self.SearchString)), self) #################### BDMV ###################### ### Replacements PRE printl("Replacements PRE on " + self.SearchString, self, "I") step = 1 for replacement in replace.replacements(u"pre"): old = self.SearchString self.SearchString = resub(replacement[0], replacement[1], self.SearchString) printl( "\tStep %d: %s -> %s = %s -> %s" % (step, str(replacement[0].pattern), str( replacement[1]), old, self.SearchString), self, "I") step = step + 1 printl(":-1: " + str(Utf8.utf8ToLatin(self.SearchString)), self) ### Check for IMDb-ID in filename printl("Check for IMDb-ID in filename '" + name + "'", self, "I") self.searchForImdbAndTvdbId(name) if self.isNfoAvailable(self.Path + u"/" + self.Filename): printl( "nfo File present - now parsing: " + self.Path + u"/" + self.Filename, self, "I") result = self.parseNfo(self.Path + u"/" + self.Filename) if result is not None: printl(" => nfo File successfully parsed!", self, "I") #self.isMovie = result.isMovie #self.isEpisode = result.isEpisode #self.isSerie = result.isSerie self.MediaType = result.MediaType self.TheTvDbId = result.TheTvDbId self.ImdbId = result.ImdbId self.Title = result.Title self.Plot = result.Plot self.Season = result.Season self.Episode = result.Episode self.Year = result.Year self.Genres = result.Genres self.Runtime = result.Runtime if self.isXbmcNfo == True and self.ImdbId is not None: printl("<- XBMC-style nfo found...", self, "I") return True else: printl("Something went wrong while reading from nfo :-(", self, "I") ### if (self.Year == None) and (isE2Recording == False): m = re.search(r'\s(?P<year>\d{4})\s', self.SearchString) if m and m.group("year"): year = int(m.group("year")) printl("year=" + str(year), self) if year > 1940 and year < 2012: self.Year = year # removing year from searchstring #self.SearchString = replace(str(year), u" ", self.SearchString) #self.SearchString = name[:m.start()] printl(":0: " + str(Utf8.utf8ToLatin(self.SearchString)), self) ### m = re.search(r'720p', name) if m: self.Resolution = u"720p" else: m = re.search(r'1080i', name) if m: self.Resolution = u"1080i" else: m = re.search(r'1080p', name) if m: self.Resolution = u"1080p" ### m = re.search(r'dts', name) if m: self.Sound = u"dts" else: m = re.search(r'dd5', name) if m: self.Sound = u"ac3" else: m = re.search(r'ac3', name) if m: self.Sound = u"ac3" #nameConverted = name if not self.isTypeMovie(): printl( "(isMovie is False) => assuming TV show - trying to get season and episode from SearchString: " + self.SearchString, self, "I") ## trying a global expression # m = re.search(r'\W(s(?P<season>\d+))?\s?(d(?P<disc>\d+))?\s?(e(?P<episode>\d+))?([-]?\s?e?(?P<episode2>\d+))?(\D|$)' , self.SearchString) ##### ##### s03d05e01-e05 - Season 3 Disc 5 Episode 1 [to Episode 5] ##### s01d02e03 - Season 3 Disc 5 Episode 1 ##### s01d02 - Season 3 Disc 5 ##### Seinfeld.S08D03.PAL.DVDR if self.Season == None or self.Episode == None: #m =re.search(r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)\s?e(?P<episode>\d+)[-]\s?e?(?P<episode2>\d+)(\D|$)', self.SearchString) m = re.search( r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)\s?(e(?P<episode>\d+))?([-]e?(?P<episode2>\d+))?(\D|$)', self.SearchString) # m = re.search(r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)(\D|$)', self.SearchString) if m and m.group("season") and m.group("disc"): #printl("PARSE RESULT 1:"+str(str(m.group("disc")))+" "+str(m.group("episode"))+" "+str(m.group("episode2")), self) self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = int(m.group("season")) self.Disc = int(m.group("disc")) if m.group("episode") is not None: self.Episode = int(m.group("episode")) if m.group("episode2") is not None: self.EpisodeLast = int(m.group("episode2")) self.SearchString = resub( r's(?P<season>\d+)\s?d(?P<disc>\d+)\s?(e(?P<episode>\d+))?([-]e?(?P<episode2>\d+))?.*', u" ", self.SearchString) ##### ##### s03d05 - Season 3 Disc 5 ##### #if self.Season == None or self.Episode == None: # m = re.search(r'\Ws(?P<season>\d+)\s?d(?P<disc>\d+)(\D|$)', self.SearchString) # if m and m.group("season") and m.group("disc"): # printl("PARSE RESULT 3:", self) # self.setMediaType(self.SERIE) # # self.Season = int(m.group("season")) # self.Disc = int(m.group("disc")) # self.Episode = 0 # # self.SearchString = resub(r's(?P<season>\d+)\s?d(?P<disc>\d+).*', u" ", self.SearchString) # ##### ##### s03e05e06 s03e05-e06 s03e05-06 s03e05 06 ##### s03e05 ##### if self.Season == None or self.Episode == None: #m = re.search(r'\Ws(?P<season>\d+)\s?e(?P<episode>\d+)[-]?\s?e?(?P<episode2>\d+)(\D|$)', self.SearchString) #Issue #494, efo => with the "\Ws" expression PVMC doesn't detect season / episodes if pattern is #located at the beginning of string, for example like "s01e02 - title.avi" #m = re.search(r'\Ws(?P<season>\d+)\s?e(?P<episode>\d+)([-]?\s?e?(?P<episode2>\d+))?(\D|$)', self.SearchString) m = re.search( r'(?P<season>\d+)\s?e(?P<episode>\d+)([-]?\s?e?(?P<episode2>\d+))?(\D|$)', self.SearchString) if m and m.group("season") and m.group("episode"): #printl("PARSE RESULT 4:"+str(m.group("episode"))+" "+str(m.group("episode2")), self) self.setMediaType(self.SERIE) self.Season = int(m.group("season")) self.Episode = int(m.group("episode")) # Issue #474, efo isSeasonEpisodeFromFilename = True if m.group("episode2") is not None: self.EpisodeLast = int(m.group("episode2")) self.SearchString = resub( r's(?P<season>\d+)\s?e(?P<episode>\d+)([-]?\s?e?(?P<episode2>\d+))?.*', u" ", self.SearchString) ##### ##### s03e05 ##### # #if self.Season == None or self.Episode == None: # m = re.search(r'\Ws(?P<season>\d+)\s?e(?P<episode>\d+)(\D|$)', self.SearchString) # if m and m.group("season") and m.group("episode"): # printl("PARSE RESULT 5:", self) # self.setMediaType(self.SERIE) # isSeasonEpisodeFromFilename = True # # self.Season = int(m.group("season")) # self.Episode = int(m.group("episode")) # # printl("PARSE RESULT 5: " + self.SearchString, self) # self.SearchString = resub(r's(?P<season>\d+)\s?e(?P<episode>\d+).*', u" ", self.SearchString) # printl("PARSE RESULT 5: " + self.SearchString, self) # ##### ##### e05 ##### if self.Season == None or self.Episode == None: m = re.search( r'\Ws?(e(?P<episode>\d+))([-]?\s?e?(?P<episode2>\d+))?(\D|$)', self.SearchString) if m and m.group("episode"): self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = 0 self.Episode = int(m.group("episode")) if m.group("episode2") is not None: self.EpisodeLast = int(m.group("episode2")) self.SearchString = resub( r's?(e(?P<episode>\d+))([-]?\s?e?(?P<episode2>\d+))?.*', u" ", self.SearchString) ##### ##### d05 - Disc 5 ##### if self.Season == None or self.Episode == None: m = re.search(r'\Wd(?P<disc>\d+)(\D|$)', self.SearchString) if m and m.group("disc"): #printl("PARSE RESULT 3:", self) self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = 0 self.Disc = int(m.group("disc")) self.Episode = 0 self.SearchString = resub(r'd(?P<disc>\d+).*', u" ", self.SearchString) ##### ##### 3x05 ##### if self.Season == None or self.Episode == None: m = re.search(r'\D(?P<season>\d+)x(?P<episode>\d+)(\D|$)', self.SearchString) if m and m.group("season") and m.group("episode"): self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = int(m.group("season")) self.Episode = int(m.group("episode")) self.SearchString = resub( r'(?P<season>\d+)x(?P<episode>\d+).*', u" ", self.SearchString) ##### ##### part 3 ##### if self.Season == None or self.Episode == None: m = re.search(r'\W(part|pt)\s?(?P<episode>\d+)(\D|$)', self.SearchString) if m and m.group("episode"): self.setMediaType(self.SERIE) # Issue #474, efo isSeasonEpisodeFromFilename = True self.Season = int(0) self.Episode = int(m.group("episode")) self.SearchString = resub( r'(part|pt)\s?(?P<episode>\d+).*', u" ", self.SearchString) ##### ##### 305 ##### if self.Season == None or self.Episode == None: nameConverted = u"" prevc = u"a" for c in self.SearchString: if (prevc.isdigit() and c.isdigit()) or (prevc.isdigit() is False and c.isdigit() is False): nameConverted += c else: nameConverted += " " + c prevc = c printl("[[[ " + str(Utf8.utf8ToLatin(nameConverted)), self) nameConverted = nameConverted.strip() m = re.search(r'\D(?P<seasonepisode>\d{3,4})(\D|$)', nameConverted) if m and m.group("seasonepisode"): se = int(-1) s = int(-1) e = int(-1) se = int(m.group("seasonepisode")) s = se / 100 e = se % 100 if (s == 2 and e == 64 or s == 7 and e == 20 or s == 10 and e == 80 or s == 0 or s == 19 and e >= 40 or s == 20 and e <= 14) is False: self.setMediaType(self.SERIE) self.Season = s self.Episode = e self.SearchString = resub( r'(?P<seasonepisode>\d{3,4}).*', u" ", nameConverted) if self.Disc == 0: self.Disc = None if self.Episode == 0: self.Episode = None printl( ":2: " + str(Utf8.utf8ToLatin(self.SearchString)) + " " + str(self.Season) + " " + str(self.Episode) + " " + str(self.Year), self) if isE2Recording is True: printl( "Extension == 'ts' and E2 meta file found => retrieving name from '" + absFilename + "'", self, "I") e2info = self.getEnigma2RecordingName(absFilename) if e2info is not None: printl( "e2info: " + str(Utf8.utf8ToLatin(e2info.MovieName)) + " - " + str( Utf8.utf8ToLatin(e2info.EpisodeName) + "," + str(e2info.IsMovie) + "," + str(e2info.IsEpisode)), self) if e2info.IsMovie: if self.getMediaType() == self.SERIE: printl( "E2-Info assumes 'MOVIE' - but foldertype is set to 'TV' => using 'TV'...", self, "I") self.SearchString = "\"" + e2info.MovieName + "\"" + ":: " + "\"" + e2info.EpisodeName + "\"" else: printl("Assuming Movie...", self, "I") self.SearchString = e2info.MovieName self.setMediaType(self.MOVIE) elif e2info.IsEpisode: if self.getMediaType() == self.MOVIE: printl( "E2-Info assumes 'TV' - but foldertype is set to 'MOVIE' => using 'MOVIE'...", self, "I") self.SearchString = e2info.MovieName else: # Issue #205, efo => since we have dedicated name + episode name use quotes to enhance google search result self.SearchString = "\"" + e2info.MovieName + "\"" + ":: " + "\"" + e2info.EpisodeName + "\"" printl("Assuming TV-Show...", self, "I") if isSeasonEpisodeFromFilename == False: printl( "Season / episode seem not to be retrieved from filename => resetting...", self, "I") self.Season = None self.Episode = None self.setMediaType(self.SERIE) self.isEnigma2MetaRecording = True printl( "<- Returning to sync process using E2 meta-file SearchString '" + str(Utf8.utf8ToLatin(self.SearchString)) + "'", self) return True if valerieInfoSearchString is not None: self.SearchString = valerieInfoSearchString printl( "<- Returning to sync process using valerie.info SearchString '" + str(Utf8.utf8ToLatin(self.SearchString)) + "'", self) return True if not self.isTypeSerie(): self.setMediaType(self.MOVIE) # So we got year and season and episode # now we can delete everything after the year # but only if the year is not the first word in the string if self.Year is not None: printl("Adapt SearchString due to year...", self, "I") pos = self.SearchString.find(str(self.Year)) if pos > 0: self.SearchString = self.SearchString[:pos] printl( " => SearchString now set to '" + self.SearchString + "'", self, "I") #print ":1: ", self.SearchString ### Replacements POST printl("rpost: " + str(Utf8.utf8ToLatin(self.SearchString)), self) self.SearchString = resub(r'[-]', u" ", self.SearchString) self.SearchString = resub(r' +', u" ", self.SearchString) printl("rpost:: " + str(Utf8.utf8ToLatin(self.SearchString)), self) self.SearchString = self.SearchString.strip() post = u"post" if self.isTypeSerie(): post = u"post_tv" elif self.isTypeMovie(): post = u"post_movie" for replacement in replace.replacements(post): #print "[" + post + "] ", replacement[0], " --> ", replacement[1] self.SearchString = resub(replacement[0], replacement[1], self.SearchString) if useParentFoldernameAsSearchstring: printl("Building search string from parent folder names...", self, "I") try: folders = self.Path.split("/") self.SearchString = folders[len(folders) - 1] # /DVDs/title/VIDEO_TS.ifo if self.SearchString.upper() == u"VIDEO_TS": self.SearchString = folders[ len(folders) - 2] # /DVDs/title/VIDEO_TS/VIDEO_TS.ifo self.searchForImdbAndTvdbId(self.SearchString) except Exception, ex: printl("Exception: " + str(ex), self, "E")
printl("Fallback to us-latin-1", __name__, "W") #windows-1252 print "------ HEX -------" print toHex(rawPage) utfPage = rawPage.decode("latin-1") print "------ CONVERTED -------" print utfPage utfPage = utfPage.encode('utf-8') print "------ CONVERTED2 -------" print utfPage if cache: addCache(url, utfPage) break printl("<- " + str(type(utfPage)) + " " + str(Utf8.utf8ToLatin(url)), __name__) return utfPage except Exception, ex: printl("Exception (ef): " + str(ex), __name__ , "E") printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E") return u"" def getXml(url, rawXml=None, cache=True): if rawXml is None: rawXml = getText(url, cache=cache) if rawXml is None: return None decodedXml = None