iterate through all services and fetch the data 从网站上查询片名解析JSON返回元数据 :param file_number: 影片名称 :param open_cc: 简繁转换器 :param specified_source: 指定的媒体数据源 :param specified_url: 指定的数据查询地址, 目前未使用 :return 给定影片名称的具体信息
(
file_number: str,
open_cc: opencc.OpenCC,
specified_source: str, specified_url: str)
| 19 | |
| 20 | |
| 21 | def get_data_from_json( |
| 22 | file_number: str, |
| 23 | open_cc: opencc.OpenCC, |
| 24 | specified_source: str, specified_url: str) -> typing.Optional[dict]: |
| 25 | """ |
| 26 | iterate through all services and fetch the data 从网站上查询片名解析JSON返回元数据 |
| 27 | :param file_number: 影片名称 |
| 28 | :param open_cc: 简繁转换器 |
| 29 | :param specified_source: 指定的媒体数据源 |
| 30 | :param specified_url: 指定的数据查询地址, 目前未使用 |
| 31 | :return 给定影片名称的具体信息 |
| 32 | """ |
| 33 | try: |
| 34 | actor_mapping_data = etree.parse(str(Path.home() / '.local' / 'share' / 'mdc' / 'mapping_actor.xml')) |
| 35 | info_mapping_data = etree.parse(str(Path.home() / '.local' / 'share' / 'mdc' / 'mapping_info.xml')) |
| 36 | except: |
| 37 | actor_mapping_data = etree.fromstring("<html></html>", etree.HTMLParser()) |
| 38 | info_mapping_data = etree.fromstring("<html></html>", etree.HTMLParser()) |
| 39 | |
| 40 | conf = config.getInstance() |
| 41 | # default fetch order list, from the beginning to the end |
| 42 | sources = conf.sources() |
| 43 | |
| 44 | # TODO 准备参数 |
| 45 | # - 清理 ADC_function, webcrawler |
| 46 | proxies: dict = None |
| 47 | config_proxy = conf.proxy() |
| 48 | if config_proxy.enable: |
| 49 | proxies = config_proxy.proxies() |
| 50 | |
| 51 | ca_cert = None |
| 52 | if conf.cacert_file(): |
| 53 | ca_cert = conf.cacert_file() |
| 54 | |
| 55 | json_data = search(file_number, sources, proxies=proxies, verify=ca_cert, |
| 56 | morestoryline=conf.is_storyline(), |
| 57 | specifiedSource=specified_source, specifiedUrl=specified_url, |
| 58 | debug = conf.debug()) |
| 59 | # Return if data not found in all sources |
| 60 | if not json_data: |
| 61 | print('[-]Movie Number not found!') |
| 62 | return None |
| 63 | |
| 64 | # 增加number严格判断,避免提交任何number |
| 65 | if str(json_data.get('number')).upper() != file_number.upper(): |
| 66 | try: |
| 67 | if json_data.get('allow_number_change'): |
| 68 | pass |
| 69 | except: |
| 70 | print('[-]Movie number has changed! [{}]->[{}]'.format(file_number, str(json_data.get('number')))) |
| 71 | return None |
| 72 | |
| 73 | # ================================================网站规则添加结束================================================ |
| 74 | |
| 75 | if json_data.get('title') == '': |
| 76 | print('[-]Movie Number or Title not found!') |
| 77 | return None |
| 78 |
no test coverage detected