def loadEpisodes(self, lang="en", updateNow=False): try: downloadAll = updateNow or self.loadTvdbInfo(lang=lang) if downloadAll: ff = FileLoader.load( "http://thetvdb.com/api/1D62F2F90030C444/series/{0}/all/en.zip".format(self.tvdbId), loadData=False ) if ff.state != FileLoader.idOk: return False zf = zipfile.ZipFile(ff.target) root = et.fromstring(zf.read("en.xml")) for ndEpisode in root.findall("Episode"): season = int(ndEpisode.find("./SeasonNumber").text) episode = int(ndEpisode.find("./EpisodeNumber").text) name = ndEpisode.find("./EpisodeName").text # airdate = ndEpisode.find('./FirstAired').text if not ndEpisode.find("./FirstAired").text == None: airdate = ndEpisode.find("./FirstAired").text else: airdate = "" self.episodes.append(EpisodeInfo(self, season, episode, name, airdate)) return True else: pass except Exception, ee: Log.log(Text.formatException(ee))
def save(self, dirTarget, langid=7, withThumb=False, streamMode=StreamMode.Exodus): added = 0 episodes = 0 base = File.cleanName(u"{0} ({1})".format(self.name.lower(), self.year)) dirSeries = os.path.join(dirTarget, base) self.saveTvdbInfo() if os.path.exists(dirSeries) == False: added += 1 self.saveTvshow(dirSeries, langid=langid) episodes = 0 for episode in self.episodes: try: if episode.season == 0: continue if episode.name == "TBA": continue dirSeason = os.path.join( dirSeries, File.cleanName(u"{0}.S{1:02}".format(self.findNameClean(), episode.season)) ) self.saveTvshow(dirSeason, langid=langid) name = u"{3}.S{0:02}E{1:02}.{2}".format(episode.season, episode.episode, episode.name, self.name) part0 = dirSeason part1 = self.name part2 = ".S{0:02}E{1:02}.".format(episode.season, episode.episode) part3 = episode.name[: 256 - -len(part0) - len(part1) - len(part2) - 10] base = File.cleanName(u"{0}{1}{2}".format(part1, part2, part3)) links = [] if streamMode == StreamMode.Exodus: links.append([name, episode.asExodus()]) if streamMode == StreamMode.Pulsar: links.append([name, episode.asPulsar()]) if streamMode == StreamMode.Salts: links.append([name, episode.asSalts()]) if streamMode == StreamMode.Quasar: links.append([name, episode.asQuasar()]) strm = os.path.join(dirSeason, u"{0}.{1}".format(base, "strm")) if os.path.exists(strm) == False: episodes += 1 with codecs.open(strm, "w") as ff: ff.write("#EXTM3U\n") for xx in links: ff.write(u"#EXTINF:{0},{1}\n".format(0, xx[0])) ff.write(u"{0}\n".format(xx[1])) except Exception, ee: Log.log(Text.formatException(ee))
def loadTmdbId(self): if self.tmdbId != None: return True if self.imdbId == None: self.loadImdb(self) # Log.log('http://api.themoviedb.org/3/find/' + self.imdbId + '?api_key=e675b61c515daa2b18932147aa0653ec&external_source=imdb_id') request = Request( "http://api.themoviedb.org/3/find/" + self.imdbId + "?api_key=e675b61c515daa2b18932147aa0653ec&external_source=imdb_id" ) try: response = urlopen(request) except Exception, ee: Log.log(Text.formatException(ee)) return False
def loadTraktId(self): if self.traktId != None: return True if self.imdbId == None: self.loadImdb(self) headers = { "Content-Type": "application/json", "trakt-api-version": "2", "trakt-api-key": "9732c09aadf88f287e38cab293fe5732facbb236595ac93d6036b3ce459eb1f2", } request = Request("https://api-v2launch.trakt.tv/search?id_type=imdb&id=" + self.imdbId, headers=headers) try: response = urlopen(request) except Exception, ee: Log.log(Text.formatException(ee)) return False
def loadTraktId(self): if self.traktId != None: return True if self.idImdb == None: return False headers = { 'Content-Type': 'application/json', 'trakt-api-version': '2', 'trakt-api-key': '9732c09aadf88f287e38cab293fe5732facbb236595ac93d6036b3ce459eb1f2' } request = Request('https://api-v2launch.trakt.tv/search?id_type=imdb&id=' + self.idImdb, headers=headers) try: response = urlopen(request) except Exception, ee: Log.log(Text.formatException(ee)) return False
def loadImdb(self): try: if self.imdbInfo != {}: return True params = {} if self.imdbId != None: params["i"] = self.imdbId else: params["t"] = self.name params["y"] = self.year ff = FileLoader.load("http://www.omdbapi.com/", params=params) info = json.loads(ff.data) if info.get("Response") == "False": return False self.initImdbInfo(info) self.loadTraktId() self.loadTmdbId() return True except Exception, ee: Log.log(Text.formatException(ee)) return False