From fe561c348b716d950f0b95af67116b572cc2353c Mon Sep 17 00:00:00 2001 From: ccf2012 Date: Sat, 4 Feb 2023 11:22:46 +0800 Subject: [PATCH] retry for TMDb --- README.md | 47 +++++------------------------ torcp/tmdbparser.py | 72 ++++++++++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index fe57e18..9431ea4 100644 --- a/README.md +++ b/README.md @@ -409,49 +409,16 @@ if __name__ == '__main__': ## 13 类型分目录 -* `genres` 可设的类型值与 `--lang` 所设语言相关,中文有: -``` -动作 -冒险 -动画 -喜剧 -犯罪 -纪录 -剧情 -家庭 -奇幻 -历史 -恐怖 -音乐 -悬疑 -爱情 -科幻 -电视电影 -惊悚 -战争 -西部 +* `--genre` 可设的类型值与 `--lang` 所设语言相关,中文有: +``` +动作 冒险 动画 喜剧 犯罪 纪录 剧情 家庭 奇幻 历史 恐怖 +音乐 悬疑 爱情 科幻 电视电影 惊悚 战争 西部 ``` * 英文有: ``` -Action -Adventure -Animation -Comedy -Crime -Documentary -Drama -Family -Fantasy -History -Horror -Music -Mystery -Romance -Science Fiction -TV Movie -Thriller -War -Western +Action Adventure Animation Comedy Crime Documentary Drama Family +Fantasy History Horror Music Mystery Romance Science Fiction TV Movie +Thriller War Western ``` --- diff --git a/torcp/tmdbparser.py b/torcp/tmdbparser.py index f7fdb4f..42187d7 100644 --- a/torcp/tmdbparser.py +++ b/torcp/tmdbparser.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import re +import time from tmdbv3api import TMDb, Movie, TV, Search, Find -# from tmdbv3api.objs.find import Find from torcp import tortitle from torcp.torcategory import TorCategory @@ -105,36 +105,54 @@ def parse(self, torname, useTMDb=False, hasIMDbId=None, hasTMDbId=None): self.tmdbcat = transFromCCFCat(self.ccfcat) if useTMDb: - if hasTMDbId: - cat, tmdbstr = parseTMDbStr(hasTMDbId) - if tmdbstr: - tmdbid, title, year = self.searchTMDbByTMDbId(cat, tmdbstr) - if tmdbid > 0: - print(tmdbid, title, self.ccfcat, self.year) - return True - if hasIMDbId: - tmdbid, title, year = self.searchTMDbByIMDbId(hasIMDbId) - if tmdbid > 0: - print(tmdbid, title, self.ccfcat, self.year) - return - if not self.checkNameContainsId(torname): - if self.tmdbcat in ['tv', 'movie', 'Other', 'HDTV']: - self.searchTMDb(self.title, self.tmdbcat, - parseYear, self.cntitle) - self.ccfcat = transToCCFCat(self.tmdbcat, self.ccfcat) + attempts = 0 + while attempts < 3: + try: + if hasTMDbId: + cat, tmdbstr = parseTMDbStr(hasTMDbId) + if tmdbstr: + tmdbid, title, year = self.searchTMDbByTMDbId(cat, tmdbstr) + if tmdbid > 0: + print(tmdbid, title, self.ccfcat, self.year) + return True + if hasIMDbId: + tmdbid, title, year = self.searchTMDbByIMDbId(hasIMDbId) + if tmdbid > 0: + print(tmdbid, title, self.ccfcat, self.year) + return + if not self.checkNameContainsId(torname): + if self.tmdbcat in ['tv', 'movie', 'Other', 'HDTV']: + self.searchTMDb(self.title, self.tmdbcat, + parseYear, self.cntitle) + self.ccfcat = transToCCFCat(self.tmdbcat, self.ccfcat) + + break + except: + attempts += 1 + print("TMDb connection failed. Trying %d " % attempts) + time.sleep(3) def getGenres(self): + attempts = 0 r = [] - if self.tmdbid > 0: - if self.tmdbcat == 'movie': - movie = Movie() - detail = movie.details(self.tmdbid) - r = detail.genres - elif self.tmdbcat == 'tv': - tv = TV() - detail = tv.details(self.tmdbid) - r = detail.genres + while attempts < 3: + try: + if self.tmdbid > 0: + if self.tmdbcat == 'movie': + movie = Movie() + detail = movie.details(self.tmdbid) + r = detail.genres + elif self.tmdbcat == 'tv': + tv = TV() + detail = tv.details(self.tmdbid) + r = detail.genres + break + except: + attempts += 1 + print("TMDb connection failed. Trying %d " % attempts) + time.sleep(3) + return r