-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增bangumiID,添加番剧信息时可以自动从bangumi补全部分信息
- Loading branch information
Showing
6 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# bangumi API | ||
import datetime | ||
import json | ||
from urllib.parse import quote | ||
from cPython import cPython as cp | ||
|
||
default_ua = 'xiaoc/AnimeMusic/1.0.0 (Web) (https://github.com/JxiaoC/animeMusic)' | ||
host = 'https://api.bgm.tv' | ||
|
||
|
||
def search(keywords: str): | ||
url = '%s/search/subject/%s?type=2&max_results=25&responseGroup=large' % (host, quote(keywords)) | ||
html = cp.get_html(url, headers={'user-agent': default_ua}) | ||
json_data = json.loads(html) | ||
res = [] | ||
for f in json_data.get('list', []): | ||
if f.get('air_date').startswith('0000'): | ||
air_date = datetime.datetime(1970, 1, 1) | ||
else: | ||
air_date = datetime.datetime.strptime(f.get('air_date'), '%Y-%m-%d') | ||
res.append({ | ||
'id': f['id'], | ||
'name': f.get('name', ''), | ||
'name_cn': f.get('name_cn', ''), | ||
'desc': f.get('summary', ''), | ||
'year': air_date.year, | ||
'month': air_date.month, | ||
'img': f.get('images', {}).get('medium', ''), | ||
}) | ||
return res | ||
|
||
|
||
if __name__ == '__main__': | ||
print(search('缘之空')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters