mirror of
https://github.com/karl0ss/GoGoDownloader.git
synced 2025-04-26 11:39:22 +01:00
Added a feature that will print if the desired quality is not found then use a default quality.
This commit is contained in:
parent
7b23113f8b
commit
6b59251753
@ -3,8 +3,10 @@ import requests as req
|
||||
import shutil
|
||||
import re
|
||||
import os
|
||||
import colorama
|
||||
from bs4 import BeautifulSoup
|
||||
from dataclasses import dataclass
|
||||
from colorama import Fore
|
||||
|
||||
|
||||
@dataclass(init=True)
|
||||
@ -15,6 +17,7 @@ class Download:
|
||||
all_episodes: int
|
||||
episode_start: int
|
||||
episode_end: int
|
||||
printed: bool = False
|
||||
|
||||
def get_links(self, source=None) -> list[str]:
|
||||
if source is not None:
|
||||
@ -64,8 +67,15 @@ class Download:
|
||||
link = soup.find("div", {"class": "mirror_link"}).find(
|
||||
"div", {"class": "dowload"}
|
||||
)
|
||||
# episode_name: int, episode_link: str
|
||||
return [download_link.split("+")[-1], link.a.get("href")]
|
||||
if not self.printed:
|
||||
CustomMessage(None, self.episode_quality).qual_not_found()
|
||||
self.episode_quality = link.text.split()[1][1:]
|
||||
CustomMessage(None, self.episode_quality).use_default_qual()
|
||||
self.printed = True
|
||||
return [
|
||||
download_link.split("+")[-1],
|
||||
link.a.get("href"),
|
||||
] # episode_name: str, episode_link: str
|
||||
|
||||
def download_episodes(self, url) -> object:
|
||||
header = {
|
||||
@ -83,10 +93,21 @@ class Download:
|
||||
|
||||
|
||||
@dataclass(init=True)
|
||||
class CustomError(Exception):
|
||||
"""Custom exception that will accept message as a parameter and it will print it on the console."""
|
||||
class CustomMessage(Exception):
|
||||
"""Custom message that will accept message as a parameter and it will print it on the console."""
|
||||
|
||||
message: str
|
||||
message: str = None
|
||||
episode_quality: str = None
|
||||
|
||||
def print_error(self) -> str:
|
||||
print(self.message)
|
||||
|
||||
def qual_not_found(self) -> str:
|
||||
print(
|
||||
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTCYAN_EX}{self.episode_quality}{Fore.RESET} quality not found."
|
||||
)
|
||||
|
||||
def use_default_qual(self) -> str:
|
||||
print(
|
||||
f"[{Fore.GREEN}+{Fore.RESET}] Using {Fore.LIGHTCYAN_EX}{self.episode_quality}{Fore.RESET} as a default quality."
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user