def get_download_url(self): """Get the download url, and return a dict of episode and the url. Download url also can be magnet link. For example: ``` { 1: 'http://example.com/Bangumi/1/1.mp4' 2: 'http://example.com/Bangumi/1/2.mp4' 3: 'http://example.com/Bangumi/1/3.mp4' } ``` The keys `1`, `2`, `3` is the episode, the value is the url of bangumi. :return: dict """ if self.source is not None: source = DATA_SOURCE_MAP.get(self.source, None)() if source is None: raise Exception('Script data source is invalid, usable sources: {}' .format(', '.join(DATA_SOURCE_MAP.keys()))) ret = {} data = source.fetch_episode_of_bangumi(**self._data) for i in data: if int(i['episode']) not in data: ret[int(i['episode'])] = i['download'] return ret else: return {}
def get_download_url(self): """Get the download url, and return a dict of episode and the url. Download url also can be magnet link. For example: ``` { 1: 'http://example.com/Bangumi/1/1.mp4' 2: 'http://example.com/Bangumi/1/2.mp4' 3: 'http://example.com/Bangumi/1/3.mp4' } ``` The keys `1`, `2`, `3` is the episode, the value is the url of bangumi. :return: dict """ if self.source is not None: source = DATA_SOURCE_MAP.get(self.source, None)() if source is None: raise Exception( "Script data source is invalid, usable sources: {}".format( ", ".join(DATA_SOURCE_MAP.keys()))) ret = {} data = source.fetch_episode_of_bangumi(**self._data) for i in data: if int(i["episode"]) not in data: ret[int(i["episode"])] = i["download"] return ret else: return {}
def get_download_url(self) -> Dict[int, str]: """Get the download url, and return a dict of episode and the url. Download url also can be magnet link. For example: ... code-block:: python { 1: 'https://example.com/Bangumi/1/1.mp4' 2: 'https://example.com/Bangumi/1/2.mp4' 3: 'https://example.com/Bangumi/1/3.mp4' } The keys `1`, `2`, `3` is the episode, the value is the url of bangumi. :return: dict """ if self.source is not None: try: source = DATA_SOURCE_MAP[self.source]() except KeyError: raise Exception( "Script data source is invalid, usable sources: {}".format( ", ".join(DATA_SOURCE_MAP.keys()))) ret = {} data = source.fetch_episode_of_bangumi(**self._data) for i in data: if int(i.episode) not in data: ret[int(i.episode)] = i.download return ret else: return {}
def get_download_url(self): """Get the download url, and return a dict of episode and the url. Download url also can be magnet link. For example: ``` { 1: 'http://example.com/Bangumi/1/1.mp4' 2: 'http://example.com/Bangumi/1/2.mp4' 3: 'http://example.com/Bangumi/1/3.mp4' } ``` The keys `1`, `2`, `3` is the episode, the value is the url of bangumi. :return: dict """ if self.source is not None: source = DATA_SOURCE_MAP.get(self.source, None)() if source is None: raise Exception( 'Script data source is invalid, usable sources: {}'.format( ', '.join(DATA_SOURCE_MAP.keys()))) ret = {} data = source.fetch_episode_of_bangumi(**self._data) if TEST_RUN: print(data) for i in data: if TEST_RUN: print(i['title']) if not re.search(r'(BIG5|繁体|繁體)', i['title']): if TEST_RUN: print('filter by cond.1') continue if re.search(r'(HEVC|MKV|H265)', i['title']): if TEST_RUN: print('filter by cond.2') continue if int(i['episode']) > 2000: if TEST_RUN: print('filter by cond.3') continue if int(i['episode']) not in data: if TEST_RUN: print('pass all cond.') ret[int(i['episode'])] = i['download'] return ret else: return {}
def get_source(self, source): try: source_instance = DATA_SOURCE_MAP.get(source, None)() return source_instance except Exception as e: source_instance = None try: source_instance = importlib.import_module('search_source.%s' % (source)) source_instance = getattr(source_instance, source)() except Exception as e: source_instance = None if source_instance is None: raise Exception( 'Script data source is invalid, usable subscript sources: {}; search sources: {}' .format((', '.join(DATA_SOURCE_MAP.keys())), (',').join(search_base.sources()))) return source_instance
import pytest from bgmi.lib.fetch import DATA_SOURCE_MAP from bgmi.website import mikan from bgmi.website.base import BaseWebsite from bgmi.website.model import Episode, SubtitleGroup, WebsiteBangumi @pytest.mark.parametrize("source", DATA_SOURCE_MAP.keys()) def test_info(source, data_source_bangumi_name): w = DATA_SOURCE_MAP[source]() # type: BaseWebsite bangumi_result = w.fetch_bangumi_calendar() assert bangumi_result, f"website {source} should return bangumi list" for bangumi in bangumi_result: assert bangumi.cover.startswith("https://") or bangumi.cover.startswith( "http://" ), "cover not starts with https:// or http://" assert isinstance(bangumi, WebsiteBangumi) for s in bangumi.subtitle_group: assert isinstance(s, SubtitleGroup) b = bangumi_result[0] w.fetch_episode_of_bangumi(b.keyword, max_page=3) w.fetch_single_bangumi(b.keyword) @pytest.mark.parametrize("source", DATA_SOURCE_MAP.keys()) def test_search(source, data_source_bangumi_name): w = DATA_SOURCE_MAP[source]() search_result = w.search_by_keyword(data_source_bangumi_name[source][0], count=1) assert search_result