From d1e50c0f496bbffc8f75c391a0e59e738cebf198 Mon Sep 17 00:00:00 2001 From: Ryan#4332 <48479346+RyanL-29@users.noreply.github.com> Date: Sun, 6 Oct 2024 23:41:03 +0800 Subject: [PATCH] Fix mobile api issue. (#285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正移動端解析 #285 #281 --- .github/workflows/Python-build.yml | 92 +++++++++++++++--------------- Anime.py | 32 ++++++----- aniGamerPlus.py | 8 +-- 3 files changed, 68 insertions(+), 64 deletions(-) diff --git a/.github/workflows/Python-build.yml b/.github/workflows/Python-build.yml index 10bfcd3..079cad1 100644 --- a/.github/workflows/Python-build.yml +++ b/.github/workflows/Python-build.yml @@ -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 diff --git a/Anime.py b/Anime.py index 5d3001a..aa389ce 100644 --- a/Anime.py +++ b/Anime.py @@ -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) @@ -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') @@ -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" } @@ -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) @@ -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: diff --git a/aniGamerPlus.py b/aniGamerPlus.py index 9de509e..fa9c618 100644 --- a/aniGamerPlus.py +++ b/aniGamerPlus.py @@ -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 @@ -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