Skip to content

Commit

Permalink
Merge pull request #288 from miyouzi/dev
Browse files Browse the repository at this point in the history
修正移動端解析
  • Loading branch information
miyouzi authored Oct 6, 2024
2 parents d91ece4 + c6777ba commit 8de20f3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 80 deletions.
92 changes: 46 additions & 46 deletions .github/workflows/Python-build.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
#anigamerplus latest python build

name: aniGamerPlus Build Artifact

on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: windows-2019
strategy:
# You can use PyPy versions in python-version.
# For example, pypy2 and pypy3
matrix:
python: [3.8.x, 3.9.x]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
- name: Build exe
run: pyinstaller --noconfirm --distpath %cd%\ --onefile --console --icon %cd%\Dashboard\static\img\aniGamerPlus.ico --clean --add-data %cd%;aniGamerPlus/ %cd%\aniGamerPlus.py
shell: cmd
- name: Upload exe
uses: actions/upload-artifact@v2
with:
name: aniGamerPlus_artifacts_${{ matrix.python }}
path: |
aniGamerPlus.exe
Dashboard/
LICENSE
README.md
DanmuTemplate.ass
sn_list-sample.txt
config-sample.json
#anigamerplus latest python build

name: aniGamerPlus Build Artifact

on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: windows-2019
strategy:
# You can use PyPy versions in python-version.
# For example, pypy2 and pypy3
matrix:
python: [3.8.x, 3.9.x]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
- name: Build exe
run: pyinstaller --noconfirm --distpath %cd%\ --onefile --console --icon %cd%\Dashboard\static\img\aniGamerPlus.ico --clean --add-data %cd%;aniGamerPlus/ %cd%\aniGamerPlus.py
shell: cmd
- name: Upload exe
uses: actions/upload-artifact@v4
with:
name: aniGamerPlus_artifacts_${{ matrix.python }}
path: |
aniGamerPlus.exe
Dashboard/
LICENSE
README.md
DanmuTemplate.ass
sn_list-sample.txt
config-sample.json
57 changes: 28 additions & 29 deletions Anime.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,14 @@ def __init_proxy(self):
# 需要使用 gost 的情况, 代理到 gost
os.environ['HTTP_PROXY'] = 'http://127.0.0.1:' + self._gost_port
os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:' + self._gost_port
self._proxies = {'https': '127.0.0.1:' + self._gost_port,
'http': '127.0.0.1:' + self._gost_port}
self._proxies = {'https': 'http://127.0.0.1:' + self._gost_port,
'http': 'http://127.0.0.1:' + self._gost_port}
else:
# 无需 gost 的情况
os.environ['HTTP_PROXY'] = self._settings['proxy']
os.environ['HTTPS_PROXY'] = self._settings['proxy']
proxy_info = Config.parse_proxy(self._settings['proxy'])
if proxy_info['proxy_user'] and proxy_info['proxy_passwd']:
auth_info = proxy_info['proxy_user'] + ":" + proxy_info['proxy_passwd'] + "@"
else:
auth_info = ''
proxy_without_protocol = auth_info + proxy_info['proxy_ip'] + ':' + proxy_info['proxy_port']
self._proxies = {'https': "https://" + proxy_without_protocol,
'http': "http://" + proxy_without_protocol}
self._proxies = {'https': self._settings['proxy'],
'http': self._settings['proxy']}

if self._settings['no_proxy_akamai']:
os.environ['NO_PROXY'] = "127.0.0.1,localhost,bahamut.akamaized.net"
Expand Down Expand Up @@ -137,7 +131,7 @@ def get_filename(self):

def __get_src(self):
if self._settings['use_mobile_api']:
self._src = self.__request_json(f'https://api.gamer.com.tw/mobile_app/anime/v2/video.php?sn={self._sn}', no_cookies=True)
self._src = self.__request_json(f'https://api.gamer.com.tw/mobile_app/anime/v4/video.php?sn={self._sn}', no_cookies=True)
else:
req = f'https://ani.gamer.com.tw/animeVideo.php?sn={self._sn}'
f = self.__request(req, no_cookies=True, use_pyhttpx=True)
Expand Down Expand Up @@ -200,18 +194,18 @@ def get_ep():

def __get_episode_list(self):
if self._settings['use_mobile_api']:
for _type in self._src['data']['anime']['volumes']:
for _sn in self._src['data']['anime']['volumes'][_type]:
for _type in self._src['data']['anime']['episodes']:
for _sn in self._src['data']['anime']['episodes'][_type]:
if _type == '0': # 本篇
self._episode_list[str(_sn['volume'])] = int(_sn["video_sn"])
self._episode_list[str(_sn['episode'])] = int(_sn["videoSn"])
elif _type == '1': # 電影
self._episode_list['電影'] = int(_sn["video_sn"])
self._episode_list['電影'] = int(_sn["videoSn"])
elif _type == '2': # 特別篇
self._episode_list[f'特別篇{_sn["volume"]}'] = int(_sn["video_sn"])
self._episode_list[f'特別篇{_sn["episode"]}'] = int(_sn["videoSn"])
elif _type == '3': # 中文配音
self._episode_list[f'中文配音{_sn["volume"]}'] = int(_sn["video_sn"])
self._episode_list[f'中文配音{_sn["episode"]}'] = int(_sn["videoSn"])
else: # 中文電影
self._episode_list['中文電影'] = int(_sn["video_sn"])
self._episode_list['中文電影'] = int(_sn["videoSn"])
else:
try:
a = self._src.find('section', 'season').find_all('a')
Expand Down Expand Up @@ -246,9 +240,9 @@ def __init_header(self):
accept_encoding = 'gzip, deflate'
cache_control = 'max-age=0'
self._mobile_header = {
"User-Agent": "Animad/1.12.5 (tw.com.gamer.android.animad; build: 222; Android 5.1.1) okHttp/4.4.0",
"User-Agent": "Animad/1.16.16 (tw.com.gamer.android.animad; build:328; Android 9) okHttp/4.4.0",
"X-Bahamut-App-Android": "tw.com.gamer.android.animad",
"X-Bahamut-App-Version": "222",
"X-Bahamut-App-Version": "328",
"Accept-Encoding": "gzip",
"Connection": "Keep-Alive"
}
Expand Down Expand Up @@ -284,11 +278,12 @@ def __request(self, req, no_cookies=False, show_fail=True, max_retry=3, addition
while True:
try:
if use_pyhttpx:
#https://github.com/miyouzi/aniGamerPlus/issues/249 pyhttpx 作者 在改動
#https://github.com/zero3301/pyhttpx/commit/4735190df741f4c00287ec948f0734fd2c21bfee 把 proxy 驗證放到了 proxies URL 裏面
# https://github.com/miyouzi/aniGamerPlus/issues/249 pyhttpx 作者 在改動
# https://github.com/zero3301/pyhttpx/commit/4735190df741f4c00287ec948f0734fd2c21bfee
# 把 proxy 驗證放到了 proxies URL 裏面
f = self._pyhttpx_session.get(req, headers=current_header, cookies=cookies, timeout=10,
proxies=self._proxies)
else:
else:
f = self._session.get(req, headers=current_header, cookies=cookies, timeout=10)
except requests.exceptions.RequestException as e:
if error_cnt >= max_retry >= 0:
Expand Down Expand Up @@ -387,7 +382,7 @@ def get_device_id():

def get_playlist():
if self._settings['use_mobile_api']:
req = f'https://api.gamer.com.tw/mobile_app/anime/v2/m3u8.php?sn={str(self._sn)}&device={self._device_id}'
req = f'https://api.gamer.com.tw/mobile_app/anime/v3/m3u8.php?videoSn={str(self._sn)}&device={self._device_id}'
else:
req = 'https://ani.gamer.com.tw/ajax/m3u8.php?sn=' + str(self._sn) + '&device=' + self._device_id
self._playlist = self.__request_json(req)
Expand Down Expand Up @@ -465,9 +460,13 @@ def check_no_ad(error_count=10):
sys.exit(1)

def parse_playlist():
req = self._playlist['src']
f = self.__request(req, no_cookies=True, addition_header={'origin': 'https://ani.gamer.com.tw'})
url_prefix = re.sub(r'playlist.+', '', self._playlist['src']) # m3u8 URL 前缀
playlist_url = ""
if self._settings['use_mobile_api']:
playlist_url = self._playlist['data']['src']
else:
playlist_url = self._playlist['src']
f = self.__request(playlist_url, no_cookies=True, addition_header={'origin': 'https://ani.gamer.com.tw'})
url_prefix = re.sub(r'playlist.+', '', playlist_url) # m3u8 URL 前缀
m3u8_list = re.findall(r'=\d+x\d+\n.+', f.content.decode()) # 将包含分辨率和 m3u8 文件提取
m3u8_dict = {}
for i in m3u8_list:
Expand Down Expand Up @@ -1370,6 +1369,6 @@ def set_resolution(self, resolution):


if __name__ == '__main__':
a = Anime('31724')
print(a.get_m3u8_dict())
a = Anime('40035')
# print(a.get_m3u8_dict())
a.download('360')
2 changes: 1 addition & 1 deletion Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sn_list_path = os.path.join(working_dir, 'sn_list.txt')
cookie_path = os.path.join(working_dir, 'cookie.txt')
logs_dir = os.path.join(working_dir, 'logs')
aniGamerPlus_version = 'v24.5'
aniGamerPlus_version = 'v24.6'
latest_config_version = 17.2
latest_database_version = 2.0
cookie = None
Expand Down
8 changes: 4 additions & 4 deletions aniGamerPlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,10 @@ def __cui(sn, cui_resolution, cui_download_mode, cui_thread_limit, ep_range,
tasks_counter = 0
for anime_db in ep_range:
if anime_db["status"] == 1:
if not anime_db["anime_name"] is None \
and not anime_db["local_file_path"] is None :
if anime_db["anime_name"] is not None \
and anime_db["local_file_path"] is not None :
a = threading.Thread(target=__get_danmu_only,args=(anime_db["sn"], anime_db["anime_name"], anime_db["local_file_path"]))
a.setDaemon(True)
a.daemon = True
thread_tasks.append(a)
a.start()
tasks_counter = tasks_counter + 1
Expand Down Expand Up @@ -801,7 +801,7 @@ def export_my_anime():

cookies = Config.read_cookie()
if not cookies:
err_print(0, f"請先設定cookie後再執行此指令", status=1, no_sn=True)
err_print(0, "請先設定cookie後再執行此指令", status=1, no_sn=True)
return

page = 1
Expand Down

0 comments on commit 8de20f3

Please sign in to comment.