minor fixes, added result processing
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
from playwright.sync_api import Playwright
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from src.core.result import Result, ResultTypeEnum
|
||||
from src.exceptions.download_exceptions import FileAlreadyExistException
|
||||
from src.parsers.base_parser import BaseParser
|
||||
|
||||
|
||||
@ -33,7 +31,7 @@ class MyMailParser(BaseParser):
|
||||
link, title, cookies = self.get_video_link(playwright)
|
||||
|
||||
if os.path.exists(os.path.join(os.getcwd() + f"/downloads/MyMailRu/{title}.mp4")):
|
||||
return f"MyMailRu/{title}.mp4"#Result(result_type=ResultTypeEnum.EXIST)
|
||||
raise FileAlreadyExistException(message=f"MyMailRu/{title}.mp4")
|
||||
|
||||
self.make_sure_path_exists()
|
||||
video_response = requests.get(link, cookies=cookies)
|
||||
|
@ -1,11 +1,9 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from src.core.result import ResultTypeEnum, Result
|
||||
from src.exceptions.download_exceptions import FileAlreadyExistException
|
||||
from src.parsers.base_parser import BaseParser
|
||||
|
||||
|
||||
@ -26,7 +24,7 @@ class YappyParser(BaseParser):
|
||||
link, title = self.get_video_link()
|
||||
|
||||
if os.path.exists(os.path.join(os.getcwd() + f"/downloads/Yappy/{title}.mp4")):
|
||||
return f"Yappy/{title}.mp4"
|
||||
raise FileAlreadyExistException(message=f"Yappy/{title}.mp4")
|
||||
|
||||
video_response = requests.get(link)
|
||||
self.make_sure_path_exists()
|
||||
|
@ -1,11 +1,8 @@
|
||||
import errno
|
||||
import os
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from src.core.result import ResultTypeEnum, Result
|
||||
from src.core.ydl import VideoDownloader
|
||||
from src.exceptions.download_exceptions import SiteNotImplementedException
|
||||
from src.exceptions.download_exceptions import FileAlreadyExistException
|
||||
|
||||
|
||||
class BaseParser:
|
||||
@ -24,20 +21,12 @@ class BaseParser:
|
||||
}
|
||||
downloader = VideoDownloader(link=self.params["link"], ydl_opts=ydl_opts)
|
||||
video_info = downloader.get_info()
|
||||
#TODO Добавить динамеческое имя директории сервиса для проверки дублирования
|
||||
if os.path.exists(
|
||||
os.path.join(os.getcwd() + f"Youtube/{video_info['id']}_{video_info['width']}.{video_info['ext']}")
|
||||
):
|
||||
return Result(result_type=ResultTypeEnum.EXIST)
|
||||
try:
|
||||
downloader.ydl_opts["quiet"] = False
|
||||
result = downloader.download()
|
||||
return f"{video_info['extractor_key']}/{result['id']}_{result['width']}p.{result['ext']}"
|
||||
except SiteNotImplementedException as ex:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=ex.message
|
||||
)
|
||||
path_to_video = f"{video_info['extractor_key']}/{video_info['id']}_{video_info['width']}p.{video_info['ext']}"
|
||||
if os.path.exists(os.path.join(os.getcwd() + "/downloads/" + path_to_video)):
|
||||
raise FileAlreadyExistException(message=path_to_video)
|
||||
downloader.ydl_opts["quiet"] = False
|
||||
downloader.download()
|
||||
return path_to_video
|
||||
|
||||
def make_sure_path_exists(self,):
|
||||
try:
|
||||
|
Reference in New Issue
Block a user