Added collab
This commit is contained in:
0
modules/anonfiles/__init__.py
Normal file
0
modules/anonfiles/__init__.py
Normal file
35
modules/anonfiles/anonfiles.py
Normal file
35
modules/anonfiles/anonfiles.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import requests
|
||||
from dataclasses import dataclass
|
||||
from Direct_Download import Direct
|
||||
|
||||
|
||||
@dataclass
|
||||
class File:
|
||||
url: str | None
|
||||
id: str | None
|
||||
name: str | None
|
||||
|
||||
|
||||
class Anonfiles:
|
||||
@staticmethod
|
||||
def upload(path: str) -> File | None:
|
||||
try:
|
||||
r = requests.post("https://api.anonfiles.com/upload", files={'file': open(path, 'rb')}).json()
|
||||
if not r["status"]:
|
||||
return
|
||||
|
||||
return File(url=r["data"]["file"]["url"]["full"],
|
||||
id=r["data"]["file"]["metadata"]["id"],
|
||||
name=r["data"]["file"]["metadata"]["name"])
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return File(None, None, None)
|
||||
|
||||
@staticmethod
|
||||
def get_direct(url: str) -> str | None:
|
||||
try:
|
||||
return Direct().anonfiles(url)['directDownload']
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -22,3 +22,12 @@ class PathsModel:
|
||||
first_browser_path: str
|
||||
second_browser_path: str
|
||||
collections_list: List[str]
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass(frozen=True)
|
||||
class PusherModel:
|
||||
app_id: str
|
||||
key: str
|
||||
secret: str
|
||||
cluster: str
|
||||
|
||||
45
modules/config/pusher.py
Normal file
45
modules/config/pusher.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from modules.config.model import PusherModel
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class PusherConfig:
|
||||
@staticmethod
|
||||
def default():
|
||||
return {
|
||||
"app_id": str(),
|
||||
"key": str(),
|
||||
"secret": str(),
|
||||
"cluster": str()
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fix() -> None:
|
||||
try:
|
||||
with open("data/config.pusher", "w") as file:
|
||||
json.dump(PusherConfig.default(), file)
|
||||
except FileNotFoundError:
|
||||
if not os.path.exists('data'):
|
||||
os.mkdir('data')
|
||||
PusherConfig.fix()
|
||||
|
||||
@staticmethod
|
||||
def get() -> PusherModel:
|
||||
try:
|
||||
with open("data/config.pusher", "r") as file:
|
||||
return PusherModel.from_dict(json.load(file))
|
||||
except:
|
||||
PusherConfig.fix()
|
||||
return PusherConfig.get()
|
||||
|
||||
@staticmethod
|
||||
def update(key: str, value: str | list | None) -> dict:
|
||||
with open("data/config.pusher", "r") as file:
|
||||
settings = json.load(file)
|
||||
|
||||
settings[key] = value
|
||||
|
||||
with open("data/config.pusher", "w") as file:
|
||||
json.dump(settings, file)
|
||||
|
||||
return settings
|
||||
@@ -6,17 +6,19 @@ import pafy
|
||||
import hashlib
|
||||
import os
|
||||
from modules.spotify.spotify_dl import Spotify
|
||||
from modules.anonfiles.anonfiles import Anonfiles
|
||||
import requests
|
||||
import urllib.parse
|
||||
|
||||
|
||||
def get_raw_link(url):
|
||||
if validators.url(url):
|
||||
if 'spotify' in url:
|
||||
if 'spotify' in url.lower():
|
||||
url = Spotify().get_youtube_url(url)
|
||||
print(url)
|
||||
if 'youtu' in url:
|
||||
if 'youtu' in url.lower():
|
||||
url = pafy.new(url).getbestaudio().url
|
||||
print(url)
|
||||
if 'anonfiles' in url.lower():
|
||||
url = urllib.parse.quote(Anonfiles.get_direct(url), safe=':/')
|
||||
|
||||
return url
|
||||
|
||||
|
||||
Reference in New Issue
Block a user