This repository was archived by the owner on Dec 2, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdesuonline.py
More file actions
151 lines (109 loc) · 5.2 KB
/
Copy pathdesuonline.py
File metadata and controls
151 lines (109 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import base64
from enum import Enum
import http
from os import link
from tkinter import N
from tokenize import String
from urllib import request
import falcon
import aiohttp
import re
import requests
from falcon import uri
from typing import List
from bs4 import BeautifulSoup
from interfaces.resource import ScraperResource
from models.episode import Episode
from models.matching import Matching
from utils.session import execute_proxied_request, get_proxied_response_json_get
from cda_downloader import CDA
class VideoQuality(Enum):
p480 = 480
p720 = 720
p1080 = 1080
class DesuonlineResource(ScraperResource):
def __init__(self, app: falcon.App) -> None:
super().__init__(app, "desuonline")
async def get_mp4_link(self, cda_link, quality, https) -> String:
if cda_link.endswith("/vfilm"):
cda_link = cda_link[:len(cda_link)-5]
if cda_link.endswith("/"):
cda_link = cda_link[:len(cda_link)-1]
if cda_link.startswith("http://"):
cutLink = ""
for x in range(len(cda_link)):
if x >= 7:
continue
else:
cutLink += cda_link[x]
cda_link = "https://www." + cutLink
cda_link = cda_link + f"?wersja={quality.value}p"
return CDA(use_api=False).get_video_urls(urls=cda_link, only_urls=True, quality=quality.value)[0]
async def get_possible_matchings(self, res: falcon.Response, title: str) -> List[Matching]:
matchings = []
url = f"{self.base_url}?s={uri.encode(title)}"
try:
has_ended = False
page_number = 4
while not has_ended:
page = await execute_proxied_request(self, url)
try:
show_elements = page.find("div", class_="listupd").find_all("article", class_="bs")
if len(show_elements) == 0:
raise Exception
for show_element in show_elements:
path = str(show_element.find_next("a")["href"]).replace(f"{self.base_url}/anime", "")[:-1]
match = show_element.find("div", class_="tt").find_next("h2").string
matchings.append(Matching(match, path))
if len(show_elements == 10):
url = f"{self.base_url}page/{page_number}/?s={uri.encode(title)}"
page_number = page_number + 1
else:
has_ended = True
except:
has_ended = True
except Exception as e:
print(str(e))
raise
return matchings
async def get_episode(self, res: falcon.Response, path: str, number: int) -> List[Episode]:
episodes = []
url = f"{self.base_url}{path}-odcinek-{number}"
try:
# This here works, but theres a faster method
# But in case there are any bugs with current approach u you can use this
# url = f"{self.base_url}{path}"
# page = await execute_proxied_request(self, url)
# epList = page.find("div", class_="eplister").find_next("ul").find_all("li")
# episodeList = []
# for i in reversed(range(len(epList))):
# episodeList.append(epList[i])
# episodeLink = str(episodeList[number - 1].find("a")["href"])
# episodePage = await execute_proxied_request(self, episodeLink)
episodePage = await execute_proxied_request(self, url)
sourcesList = episodePage.find("select", class_="mirror").find_all("option")
for option in sourcesList:
decodedString = base64.b64decode(str(option["value"])).decode('ascii')
if "https://drive.google.com/" in decodedString:
bs = BeautifulSoup(decodedString, 'html.parser')
embedLink = bs.find('iframe')["src"]
videoID = embedLink.split('/')[-2]
dlLink = f"https://drive.google.com/u/0/uc?id={videoID}&export=download&confirm=t"
episodes.append(Episode(f"Odcinek {number}", url, dlLink, None, "mp4"))
if "https://ebd.cda.pl/" in decodedString:
bs = BeautifulSoup(decodedString, 'html.parser')
embedLink = bs.find('iframe')["src"]
if embedLink == '':
raise Exception("Failed to get CDA Embed Link!")
videoID = embedLink.split('/')[-1]
cdaVidLink = f"https://cda.pl/video/{videoID}"
if cdaVidLink == '':
raise Exception("Failed to get CDA Link!")
for quality in VideoQuality:
dlLink = await self.get_mp4_link(cdaVidLink, quality, False)
if dlLink != None:
episodes.append(Episode(f"Odcinek {number}", url, dlLink, quality.value, "mp4"))
except Exception as e:
print(str(e))
raise
return episodes