Skip to content

Commit

Permalink
retry for TMDb
Browse files Browse the repository at this point in the history
  • Loading branch information
ccf-2012 committed Feb 4, 2023
1 parent 0ccf7ab commit fe561c3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 67 deletions.
47 changes: 7 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

---
Expand Down
72 changes: 45 additions & 27 deletions torcp/tmdbparser.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit fe561c3

Please sign in to comment.