Added bing_parser.py, minor fixes

This commit is contained in:
nikili0n 2023-10-11 00:04:51 +03:00
parent 3675695922
commit 7f4e661ea6
3 changed files with 32 additions and 0 deletions

View 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 BingParser(BaseParser):
BASE_DIR = os.path.abspath(f"downloads/Bing")
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/Bing/%(id)s_%(resolution)s.%(ext)s"
file_path = super().video_download()
self.params["link"] = base_link
return file_path

View File

@ -33,6 +33,8 @@ class BaseParser:
path_to_video = f"Yahoo/{downloader.info['id']}_{resolution}.{downloader.info['ext']}" path_to_video = f"Yahoo/{downloader.info['id']}_{resolution}.{downloader.info['ext']}"
elif "ZenYandex" in ydl_opts["outtmpl"]["default"]: elif "ZenYandex" in ydl_opts["outtmpl"]["default"]:
path_to_video = f"ZenYandex/{downloader.info['id']}_{resolution}.{downloader.info['ext']}" path_to_video = f"ZenYandex/{downloader.info['id']}_{resolution}.{downloader.info['ext']}"
elif "Bing" in ydl_opts["outtmpl"]["default"]:
path_to_video = f"Bing/{downloader.info['id']}_{resolution}.{downloader.info['ext']}"
else: else:
path_to_video = f"{downloader.info['extractor_key']}/{downloader.info['id']}_{resolution}.{downloader.info['ext']}" 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)): if os.path.exists(os.path.join(os.getcwd() + "/downloads/" + path_to_video)):

View File

@ -1,6 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
import re import re
from src.parsers.Bing.bing_parser import BingParser
from src.parsers.Dzen.dzen_parser import DzenParser from src.parsers.Dzen.dzen_parser import DzenParser
from src.parsers.MyMail.my_mail_parser import MyMailParser from src.parsers.MyMail.my_mail_parser import MyMailParser
from src.parsers.Okru.ok_parser import OkParser from src.parsers.Okru.ok_parser import OkParser
@ -27,6 +28,7 @@ parser_mapping = OrderedDict(
compile_regex(r"^.*\.yahoo.com/"): YahooParser, compile_regex(r"^.*\.yahoo.com/"): YahooParser,
compile_regex(r"^.*\.livejournal.com/"): BaseParser, compile_regex(r"^.*\.livejournal.com/"): BaseParser,
compile_regex(r"^.*\.dzen.ru/"): BaseParser, compile_regex(r"^.*\.dzen.ru/"): BaseParser,
compile_regex(r"^.*\.bing.com/"): BingParser,
} }
) )