Skip to content

Commit

Permalink
Fix mobile api issue. (#285)
Browse files Browse the repository at this point in the history
修正移動端解析 #285 #281
  • Loading branch information
RyanL-29 authored Oct 6, 2024
1 parent 073b022 commit d1e50c0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 64 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
32 changes: 18 additions & 14 deletions Anime.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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 +200,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 +246,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 @@ -387,7 +387,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 +465,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
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 d1e50c0

Please sign in to comment.