인프런 파일명 변경 테스트

This commit is contained in:
2022-05-15 17:32:36 +09:00
parent 9f7600130b
commit cc4e4e422b
2 changed files with 32 additions and 12 deletions

View File

@@ -352,12 +352,12 @@ class LogicInflearn(object):
try:
# query = query.encode("utf-8")
_query = urllib.parse.quote(query)
url = f"{ModelSetting.get('inflearn_url')}/?s={_query}"
url = f"{ModelSetting.get('inflearn_url')}/courses?s={_query}"
logger.debug("search url::> %s", url)
html_content = LogicInflearn.get_html(url)
download_path = ModelSetting.get("download_path")
tree = html.fromstring(html_content)
tmp_items = tree.xpath('//div[@class="item"]')
tmp_items = tree.xpath('//div[contains(class, "column")]')
# logger.info('tmp_items:::', tmp_items)
data = {"ret": "success", "query": query}
@@ -373,20 +373,27 @@ class LogicInflearn(object):
for item in tmp_items:
entity = {}
entity["link"] = item.xpath(".//a/@href")[0]
entity["code"] = re.search(r"[0-9]+", entity["link"]).group()
entity["title"] = item.xpath('.//span[@class="name-film"]//text()')[
entity["link"] = item.xpath(".//a[@class='course_card_front']/@href")[0]
entity["code"] = entity["link"].split("/")[-1]
entity["_code"] = item.xpath("/div/@data-productid")
entity["title"] = item.xpath('.//div[@class="course_title"]//text()')[
0
].strip()
entity["teacher"] = item.xpath('.//div[@class="instructor"]/text()')[
0
].strip()
entity["image_link"] = item.xpath('.//img[@class="photo"]/@src')[0]
# logger.info('entity:::', entity['title'])
data["episode"].append(entity)
json_file_path = os.path.join(download_path, "airing_list.json")
logger.debug("json_file_path:: %s", json_file_path)
with open(json_file_path, "w") as outfile:
json.dump(data, outfile)
# json_file_path = os.path.join(download_path, "airing_list.json")
# logger.debug("json_file_path:: %s", json_file_path)
#
# with open(json_file_path, "w") as outfile:
# json.dump(data, outfile)
return data
@@ -946,7 +953,7 @@ class LogicInflearn(object):
title = res_data["course"]["_"]["current_unit"]["title"]
if res_data["newBOX"]["video"]["name"] is not None:
name = res_data["newBOX"]["video"]["name"]
filename = f"{title}.{name.split('.')[0]}.S{season.zfill(2)}.E{str(idx).zfill(3)}.{name.split('.')[-1]}"
filename = f"{title} - S{season.zfill(2)}.E{str(idx).zfill(3)} - {name.split('.')[0]}.{name.split('.')[-1]}"
if res_data["newBOX"]["video"]["vod_info"]["hlsUrl"] is not None:
# logger.debug(res_data["newBOX"]["video"]["vod_info"]["hlsUrl"])
m3u8_url = res_data["newBOX"]["video"]["vod_info"]["hlsUrl"]