#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys sys.path.append('../') import json import re from urllib.parse import urlencode from lxml import etree from ADC_function import * # import sys # import io # sys.stdout = io.TextIOWrapper(sys.stdout.buffer, errors = 'replace', line_buffering = True) def getTitle(text): html = etree.fromstring(text, etree.HTMLParser()) result = html.xpath('//*[starts-with(@id, "title")]/text()')[0] return result def getActor(text): # //*[@id="center_column"]/div[2]/div[1]/div/table/tbody/tr[1]/td/text() html = etree.fromstring(text, etree.HTMLParser()) result = ( str( html.xpath( "//td[contains(text(),'出演者')]/following-sibling::td/span/a/text()" ) ) .strip(" ['']") .replace("', '", ",") ) return result def getStudio(text): html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() try: result = html.xpath( "//td[contains(text(),'メーカー')]/following-sibling::td/a/text()" )[0] except: result = html.xpath( "//td[contains(text(),'メーカー')]/following-sibling::td/text()" )[0] return result def getRuntime(text): html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() result = html.xpath("//td[contains(text(),'収録時間')]/following-sibling::td/text()")[0] return re.search(r"\d+", str(result)).group() def getLabel(text): html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() try: result = html.xpath( "//td[contains(text(),'レーベル:')]/following-sibling::td/a/text()" )[0] except: result = html.xpath( "//td[contains(text(),'レーベル:')]/following-sibling::td/text()" )[0] return result def getNum(text): html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() try: result = html.xpath( "//td[contains(text(),'品番:')]/following-sibling::td/a/text()" )[0] except: result = html.xpath( "//td[contains(text(),'品番:')]/following-sibling::td/text()" )[0] return result def getYear(getRelease): try: result = str(re.search(r"\d{4}", getRelease).group()) return result except: return getRelease def getRelease(text): html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() try: result = html.xpath( "//td[contains(text(),'発売日:')]/following-sibling::td/a/text()" )[0].lstrip("\n") except: try: result = html.xpath( "//td[contains(text(),'発売日:')]/following-sibling::td/text()" )[0].lstrip("\n") except: result = "----" if result == "----": try: result = html.xpath( "//td[contains(text(),'配信開始日:')]/following-sibling::td/a/text()" )[0].lstrip("\n") except: try: result = html.xpath( "//td[contains(text(),'配信開始日:')]/following-sibling::td/text()" )[0].lstrip("\n") except: pass return result.replace("/", "-") def getTag(text): html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() try: result = html.xpath( "//td[contains(text(),'ジャンル:')]/following-sibling::td/a/text()" ) total = [] for i in result: try: total.append(translateTag_to_sc(i)) except: pass return total except: result = html.xpath( "//td[contains(text(),'ジャンル:')]/following-sibling::td/text()" ) total = [] for i in result: try: total.append(translateTag_to_sc(i)) except: pass return total return result def getCover(text, number): html = etree.fromstring(text, etree.HTMLParser()) cover_number = number try: result = html.xpath('//*[@id="' + cover_number + '"]/@href')[0] except: # sometimes fanza modify _ to \u0005f for image id if "_" in cover_number: cover_number = cover_number.replace("_", r"\u005f") try: result = html.xpath('//*[@id="' + cover_number + '"]/@href')[0] except: # (TODO) handle more edge case # print(html) # raise exception here, same behavior as before # people's major requirement is fetching the picture raise ValueError("can not find image") return result def getDirector(text): html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() try: result = html.xpath( "//td[contains(text(),'監督:')]/following-sibling::td/a/text()" )[0] except: result = html.xpath( "//td[contains(text(),'監督:')]/following-sibling::td/text()" )[0] return result def getOutline(text): html = etree.fromstring(text, etree.HTMLParser()) try: result = str(html.xpath("//div[@class='mg-b20 lh4']/text()")[0]).replace( "\n", "" ) if result == "": result = str(html.xpath("//div[@class='mg-b20 lh4']//p/text()")[0]).replace( "\n", "" ) except: # (TODO) handle more edge case # print(html) return "" return result def getSeries(text): try: html = etree.fromstring(text, etree.HTMLParser()) # //table/tr[1]/td[1]/text() try: result = html.xpath( "//td[contains(text(),'シリーズ:')]/following-sibling::td/a/text()" )[0] except: result = html.xpath( "//td[contains(text(),'シリーズ:')]/following-sibling::td/text()" )[0] return result except: return "" def getExtrafanart(htmlcode): # 获取剧照 html_pather = re.compile(r'
') html = html_pather.search(htmlcode) if html: html = html.group() extrafanart_pather = re.compile(r'