Skip to content

Commit

Permalink
✨ 新增下載封面照
Browse files Browse the repository at this point in the history
  • Loading branch information
tasi788 committed Sep 6, 2023
1 parent d91ece4 commit a32c0d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Anime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,15 @@ def download(self, resolution='', save_dir='', bangumi_tag='', realtime_show_fil
except:
err_print(self._sn, 'Plex auto Refresh UNKNOWN ERROR', 'Exception: ' + str(e), status=1)

# 下載封面照
if self._settings['download_poster']:
url = self.get_thumbnail()
full_filename = os.path.join(self._bangumi_dir, 'poster.jpg')
if url:
with requests.get(url, stream=True) as r:
with open(full_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)

def upload(self, bangumi_tag='', debug_file=''):
first_connect = True # 标记是否是第一次连接, 第一次连接会删除临时缓存目录
tmp_dir = str(self._sn) + '-uploading-by-aniGamerPlus'
Expand Down Expand Up @@ -1362,6 +1371,19 @@ def get_info(self):
err_print(0, indent+'参考檔名:', '\"' + self.get_filename() + '\"', no_sn=True, display_time=False)
err_print(0, indent+'可用解析度', 'P '.join(self.get_m3u8_dict().keys()) + 'P\n', no_sn=True, display_time=False)

def get_thumbnail(self):
if self._settings['use_mobile_api']:
return self._src['data']['anime']['cover']
else:
soup = self._src
# return soup.find('meta', property='og:image')['content']
try:
return soup.find('div', 'data-file').img['data-src']
except (TypeError, AttributeError, KeyError):
# 该sn下没有动画
err_print(self._sn, 'ERROR: 該 sn 下真的有動畫?', status=1)
sys.exit(1)

def enable_danmu(self):
self._danmu = True

Expand Down
4 changes: 3 additions & 1 deletion Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def __init_settings():
'save_logs': True,
'quantity_of_logs': 7,
'config_version': latest_config_version,
'database_version': latest_database_version
'database_version': latest_database_version,
'download_poster': True,
'generate_nfo': True,
}
with open(config_path, 'w', encoding='utf-8') as f:
json.dump(settings, f, ensure_ascii=False, indent=4)
Expand Down
2 changes: 1 addition & 1 deletion config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@
},
"save_logs": true,
"quantity_of_logs": 7,
"config_version": 13.0,
"config_version": 13.1,
"database_version": 2.0
}

0 comments on commit a32c0d3

Please sign in to comment.