Skip to content

Commit

Permalink
處理個別中間劇集sn比後面劇集更高的問題
Browse files Browse the repository at this point in the history
新增 largest-sn 模式, latest 模式修正為番劇最後一集而不是最近上傳的一集
提高讀取用戶配置穩定性
update readme
  • Loading branch information
miyouzi committed Jan 11, 2019
1 parent 5d411f6 commit 5dde84a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ requirements.txt
.idea/modules.xml
.idea/workspace.xml
test.py
releases/
releases/
.idea/dataSources.local.xml
6 changes: 6 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
config_path = os.path.join(working_dir, 'config.json')
sn_list_path = os.path.join(working_dir, 'sn_list.txt')
cookies_path = os.path.join(working_dir, 'cookies.txt')
aniGamerPlus_version = 'v5.0'
aniGamerPlus_version = 'v5.1'
latest_config_version = 1.1


Expand Down Expand Up @@ -60,6 +60,8 @@ def read_settings():
settings['check_frequency'] = int(settings['check_frequency'])
settings['download_resolution'] = str(settings['download_resolution'])
settings['multi-thread'] = int(settings['multi-thread'])
if not re.match(r'^(all|latest|largest-sn)$', settings['default_download_mode']):
settings['default_download_mode'] = 'latest' # 如果输入非法模式, 将重置为 latest 模式
# 如果用户没有有自定番剧目录或目录不存在,则保存在本地 bangumi 目录
if not (settings['bangumi_dir'] and os.path.exists(settings['bangumi_dir'])):
settings['bangumi_dir'] = os.path.join(working_dir, 'bangumi')
Expand All @@ -76,11 +78,18 @@ def read_sn_list():
sn_dict = {}
for i in f.readlines():
i = re.sub(r'#.+\n', '', i).strip()
a = [l for l in i.split(" ")]
try:
sn_dict[int(a[0])] = a[1]
except IndexError:
sn_dict[int(a[0])] = settings['default_download_mode']
i = re.sub(r' +', ' ', i) # 去除多余空格
a = i.split(" ")
if not a[0]: # 跳过纯注释行
continue
if re.match(r'^\d+$',a[0]):
if len(a) > 1: # 如果有特別指定下载模式
if re.match(r'^(all|latest|largest-sn)$', a[1]): # 仅认可合法的模式
sn_dict[int(a[0])] = a[1]
else:
sn_dict[int(a[0])] = settings['default_download_mode'] # 非法模式一律替换成默认模式
else: # 没有指定下载模式则使用默认设定
sn_dict[int(a[0])] = settings['default_download_mode']
return sn_dict


Expand All @@ -96,5 +105,5 @@ def read_cookies():
return {}


if __name__=='__main__':
pass
if __name__ == '__main__':
pass
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# aniGamerPlus
巴哈姆特動畫瘋自動下載工具

windows 用戶可以[**點擊這裡**](https://github.com/miyouzi/aniGamerPlus/releases/tag/v5.0)下載exe文件使用.
windows 用戶可以[**點擊這裡**](https://github.com/miyouzi/aniGamerPlus/releases/tag/v5.1)下載exe文件使用.

ffmpeg 需要另外下載, [**點擊這裡前往下載頁**](https://ffmpeg.zeranoe.com/builds/). 若不知道如何將 ffmpeg 放入 PATH 則直接將 **ffmpeg.exe** 放在和本程式同一個文件夾下即可.

Expand Down Expand Up @@ -42,6 +42,8 @@ pip3 install requests beautifulsoup4 lxml termcolor

:warning: **以下所有配置請使用UTF-8無BOM編碼** :warning:

**推薦使用 [notepad++](https://notepad-plus-plus.org/) 進行編輯**

### config.json

**config-sample.json**为范例配置文件, 可以将其修改后改名为**config.json**.
Expand All @@ -62,12 +64,22 @@ pip3 install requests beautifulsoup4 lxml termcolor
}
```

模式僅支持在 **latest**, **all**, **largest-sn** 三個中選一個, 錯詞及其他詞將會重置為**latest**模式

### cookies.txt

用戶cookie文件, 將瀏覽器的cookie字段複製, 已**cookies.txt**為文件名保存在程序目錄下即可

:warning: **登陸時請勾選"保持登入狀態", 并且不更換瀏覽器登陸, 不異地登陸, 否則cookie將可能被刷新**

#### 使用Chrome舉例如何獲取 Cookie:

- 按 F12 調出開發者工具, 前往動畫瘋, 切換到 Network 標簽, 在下方選中 "ani.gamer.com.tw" 在右側即可看到 Cookie, 如圖:
![](screenshot/WhereIsCookie.png)

- 在程序所在目錄新建一個名爲**cookies.txt**的文本文件, 打開將上面的Cookie複製貼上保存即可
![](screenshot/CookiesFormat.png)

### sn_list.txt

需要自動下載的番劇列表,一個番劇中選任一sn填入即可
Expand All @@ -76,6 +88,8 @@ pip3 install requests beautifulsoup4 lxml termcolor

支持注釋 **#** 後面的所有字符程序均不會讀取, 可以標記番劇名

模式僅支持在 **latest**, **all**, **largest-sn** 三個中選一個, 錯詞及其他詞將會重置為**config.json**定義的默認下載模式

格式:
```
sn碼 下載模式(可空) #注釋(可空)
Expand Down Expand Up @@ -105,9 +119,9 @@ sqlite3資料庫, 可以使用 [SQLite Expert](http://www.sqliteexpert.com/) 等
參數:
```
>python3 aniGamerPlus.py -h
當前aniGamerPlus版本: v5.0
當前aniGamerPlus版本: v5.1
usage: aniGamerPlus.py [-h] --sn SN [--resolution {360,480,540,720,1080}]
[--download_mode {single,latest,all,range}]
[--download_mode {single,latest,largest-sn,all,range}]
[--thread_limit THREAD_LIMIT] [--current_path]
[--episodes EPISODES]
Expand All @@ -116,7 +130,7 @@ optional arguments:
--sn SN, -s SN 視頻sn碼(數字)
--resolution {360,480,540,720,1080}, -r {360,480,540,720,1080}
指定下載清晰度(數字)
--download_mode {single,latest,all,range}, -m {single,latest,all,range}
--download_mode {single,latest,largest-sn,all,range}, -m {single,latest,largest-sn,all,range}
下載模式
--thread_limit THREAD_LIMIT, -t THREAD_LIMIT
最高并發下載數(數字)
Expand All @@ -135,13 +149,15 @@ optional arguments:

- **all** 下載此番劇所有劇集

- **latest** 下載此番劇最新一集
- **latest** 下載此番劇最後一集(即網頁上顯示排最後的一集)

- **largest-sn** 下載此番劇最近上傳的一集(即sn最大的一集)

- **range** 下載此番指定的劇集

- **-t** 接最大并發下載數, 可空, 空則讀取**config.json**中的定義

- **-e** 下載此番劇指定劇集, 支持範圍輸入, 支持多個不連續聚集下載, 僅支持數字命名的劇集
- **-e** 下載此番劇指定劇集, 支持範圍輸入, 支持多個不連續聚集下載, 僅支持整數命名的劇集

- -e 參數優先于 -m 參數, 使用 -e 參數時, 强制為 range 模式

Expand Down
25 changes: 17 additions & 8 deletions aniGamerPlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def check_tasks():
anime = Anime(sn)
if sn_dict[sn] == 'all':
# 如果用户选择全部下载 download_mode = 'all'
for ep in anime.get_episode_list().values():
for ep in anime.get_episode_list().values(): # 遍历剧集列表
try:
db = read_db(ep)
if db['status'] == 0 and ep not in queue:
Expand All @@ -136,10 +136,12 @@ def check_tasks():
insert_db(new_anime)
queue.append(ep)
else:
# 如果用户选择仅下载最新 download_mode = 'latest'
latest_sn = list(anime.get_episode_list().values()) # 本番剧剧集列表
latest_sn.sort()
latest_sn = latest_sn[-1] # 选出 sn 值最高的,即最新的
if sn_dict[sn] == 'largest-sn':
# 如果用户选择仅下载最新上传, download_mode = 'largest_sn', 则对 sn 进行排序
latest_sn.sort()
# 否则用户选择仅下载最后剧集, download_mode = 'latest', 即下载网页上显示在最右的剧集
latest_sn = latest_sn[-1]
try:
db = read_db(latest_sn)
if db['status'] == 0 and latest_sn not in queue:
Expand Down Expand Up @@ -191,11 +193,18 @@ def __cui(sn, cui_resolution, cui_download_mode, cui_thread_limit, ep_range, cui
print('當前下載模式: 僅下載本集\n')
Anime(sn).download(cui_resolution, cui_save_dir, True) # True 是实时显示文件大小, 仅一个下载任务时适用

elif cui_download_mode == 'latest':
print('當前下載模式: 下載本番劇最新一集\n')
elif cui_download_mode == 'latest' or cui_download_mode == 'largest-sn':
if cui_download_mode == 'latest':
print('當前下載模式: 下載本番劇最後一集\n')
else:
print('當前下載模式: 下載本番劇最近上傳的一集\n')

anime = Anime(sn)
bangumi_list = list(anime.get_episode_list().values())
bangumi_list.sort()

if cui_download_mode == 'largest-sn':
bangumi_list.sort()

if bangumi_list[-1] == sn:
anime.download(cui_resolution, cui_save_dir, True)
else:
Expand Down Expand Up @@ -266,7 +275,7 @@ def user_exit(signum, frame):
parser.add_argument('--sn', '-s', type=int, help='視頻sn碼(數字)', required=True)
parser.add_argument('--resolution', '-r', type=int, help='指定下載清晰度(數字)', choices=[360, 480, 540, 720, 1080])
parser.add_argument('--download_mode', '-m', type=str, help='下載模式', default='single',
choices=['single', 'latest', 'all', 'range'])
choices=['single', 'latest', 'largest-sn', 'all', 'range'])
parser.add_argument('--thread_limit', '-t', type=int, help='最高并發下載數(數字)')
parser.add_argument('--current_path', '-c', action='store_true', help='下載到當前工作目錄')
parser.add_argument('--episodes', '-e', type=str, help='僅下載指定劇集')
Expand Down
Binary file added screenshot/CookiesFormat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot/WhereIsCookie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5dde84a

Please sign in to comment.