From a14d4f1e5d894d5862a59cd5007f9af5f1ce962f Mon Sep 17 00:00:00 2001 From: Dantenerosas Date: Wed, 27 Sep 2023 02:31:46 +0300 Subject: [PATCH] added okru parser --- src/core/master_service.py | 3 ++- src/parsers/Okru/ok_parser.py | 27 +++++++++++++++++++++++++++ src/parsers/base_parser.py | 4 ++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/parsers/Okru/ok_parser.py diff --git a/src/core/master_service.py b/src/core/master_service.py index 6cc50f7..63913f6 100644 --- a/src/core/master_service.py +++ b/src/core/master_service.py @@ -12,6 +12,7 @@ from src.core.redis_client import RedisClient from src.core.result import Result, ResultTypeEnum from src.exceptions.download_exceptions import FileAlreadyExistException, SiteNotImplementedException 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.base_parser import BaseParser @@ -82,7 +83,7 @@ class MasterService: "www.youtube.com": BaseParser(params), "youtu.be": BaseParser(params), "vk.com": BaseParser(params), - "ok.ru": BaseParser(params), + "ok.ru": BaseParser(params) if "topic" not in params["link"] else OkParser(params), "likee.video": BaseParser(params), "dzen.ru": BaseParser(params), "yappy.media": YappyParser(params), diff --git a/src/parsers/Okru/ok_parser.py b/src/parsers/Okru/ok_parser.py new file mode 100644 index 0000000..fd04576 --- /dev/null +++ b/src/parsers/Okru/ok_parser.py @@ -0,0 +1,27 @@ +import os + +import requests + +from bs4 import BeautifulSoup + +from src.parsers.base_parser import BaseParser + + +class OkParser(BaseParser): + BASE_DIR = os.path.abspath(f"downloads/Odnoklassniki") + + def get_video_link(self): + try: + resp = requests.get(self.params["link"]) + resp.encoding = self.BASE_ENCODING + soup = BeautifulSoup(resp.text, 'lxml') + required_div = [div for div in soup.find_all('div', {'class': 'invisible'}) if len(div['class']) < 2][0] + link = required_div.find('span').find('span').find('a').get("href") + self.params["link"] = link + return link + except Exception as ex: + raise + + def video_download(self): + self.get_video_link() + super().video_download() diff --git a/src/parsers/base_parser.py b/src/parsers/base_parser.py index 0b5c1f8..fecd537 100644 --- a/src/parsers/base_parser.py +++ b/src/parsers/base_parser.py @@ -1,7 +1,7 @@ import errno import os -# from loguru import logger +from loguru import logger from src.core.ydl import VideoDownloader from src.exceptions.download_exceptions import FileAlreadyExistException @@ -17,7 +17,7 @@ class BaseParser: def video_download(self): ydl_opts = { "format": self.params["format"], - # "logger": logger, + "logger": logger, "merge_output_format": self.params["merge_output_format"], 'outtmpl': self.params["outtmpl"], "quiet": True