Update backend.py

Cleaned up code
This commit is contained in:
Arctic4161 2021-10-14 10:03:27 -05:00 committed by GitHub
parent a3a5ca7ecd
commit 01562f595b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ from dataclasses import dataclass
from colorama import Fore
from random import choice
@dataclass(init=True)
class Download:
name: str
@ -45,8 +46,8 @@ class Download:
else:
# Episode link == 404
episode_link = f"{episode_link}-"
with req.get(episode_link) as res:
soup = BeautifulSoup(res.content, "html.parser")
with req.get(episode_link) as find:
soup = BeautifulSoup(find.content, "html.parser")
exist = soup.find("h1", {"class": "entry-title"})
if exist is None:
episode_link = soup.find("li", {"class": "dowloads"})
@ -71,9 +72,9 @@ class Download:
if link is None:
episode_quality = "360P"
link = soup.find("div", {"class": "dowload"}, text=re.compile(episode_quality))
CustomMessage(None, self.episode_quality).qual_not_found()
CustomMessage('None', self.episode_quality).qual_not_found()
self.episode_quality = link.text.split()[1][1:]
CustomMessage(None, self.episode_quality).use_default_qual()
CustomMessage('None', self.episode_quality).use_default_qual()
self.printed = True
return [
download_link.split("+")[-1],
@ -98,11 +99,11 @@ class Download:
"Connection": "keep-alive"}
def download_episodes(self, url):
with req.get(url[1], headers=self.random_headers(), stream=True) as res:
with req.get(url[1], headers=self.random_headers(), stream=True) as workingurl:
episode_name = f"EP.{url[0]}.mp4"
file_loc = os.path.join(self.folder, episode_name)
with open(file_loc, "wb") as file:
shutil.copyfileobj(res.raw, file, 8192)
shutil.copyfileobj(workingurl.raw, file, 8192)
@dataclass(init=True)