added yahoo parser
This commit is contained in:
parent
1ddab9a964
commit
120e2bd514
28
src/parsers/Yahoo/yahoo_parser.py
Normal file
28
src/parsers/Yahoo/yahoo_parser.py
Normal file
@ -0,0 +1,28 @@
|
||||
import os
|
||||
|
||||
from playwright.sync_api import Playwright
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from src.parsers.base_parser import BaseParser
|
||||
|
||||
|
||||
class YahooParser(BaseParser):
|
||||
BASE_DIR = os.path.abspath(f"downloads/Yahoo")
|
||||
|
||||
def get_video_link(self, playwright: Playwright):
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
context = browser.new_context()
|
||||
page = context.new_page()
|
||||
page.goto(url=self.params["link"], wait_until='domcontentloaded')
|
||||
link = page.get_attribute("xpath=//iframe", "src")
|
||||
return link
|
||||
|
||||
def video_download(self, link: str = None, title: str = None):
|
||||
base_link = self.params["link"]
|
||||
with sync_playwright() as playwright:
|
||||
link = self.get_video_link(playwright)
|
||||
self.params["link"] = link
|
||||
self.params['outtmpl'] = f"downloads/Yahoo/%(id)s_%(resolution)s.%(ext)s"
|
||||
file_path = super().video_download()
|
||||
self.params["link"] = base_link
|
||||
return file_path
|
@ -29,7 +29,9 @@ class BaseParser:
|
||||
resolution = downloader.info['resolution']
|
||||
else:
|
||||
resolution = "NA"
|
||||
|
||||
if "Yahoo" in ydl_opts["outtmpl"]["default"]:
|
||||
path_to_video = f"Yahoo/{downloader.info['id']}_{resolution}.{downloader.info['ext']}"
|
||||
else:
|
||||
path_to_video = f"{downloader.info['extractor_key']}/{downloader.info['id']}_{resolution}.{downloader.info['ext']}"
|
||||
if os.path.exists(os.path.join(os.getcwd() + "/downloads/" + path_to_video)):
|
||||
raise FileAlreadyExistException(message=path_to_video)
|
||||
|
@ -3,7 +3,7 @@ import re
|
||||
|
||||
from src.parsers.MyMail.my_mail_parser import MyMailParser
|
||||
from src.parsers.Okru.ok_parser import OkParser
|
||||
from src.parsers.Yappy.yappy_parser import YappyParser
|
||||
from src.parsers.Yahoo.yahoo_parser import YahooParser
|
||||
from src.parsers.base_parser import BaseParser
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ parser_mapping = OrderedDict(
|
||||
compile_regex(r"^dzen.ru/"): BaseParser,
|
||||
compile_regex(r"^yappy.media/"): BaseParser,
|
||||
compile_regex(r"^yandex.ru/"): BaseParser,
|
||||
compile_regex(r"^.*\.yahoo.com/"): YahooParser,
|
||||
compile_regex(r"^.*\.livejournal.com/"): BaseParser,
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user