added okru parser

This commit is contained in:
Dantenerosas 2023-09-27 02:31:46 +03:00 committed by nikili0n
parent c66ef29069
commit 2f7ba6b24e
3 changed files with 31 additions and 3 deletions

View File

@ -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),

View File

@ -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()

View File

@ -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