Skip to content

Commit

Permalink
Fix yt-dlp request issue
Browse files Browse the repository at this point in the history
other minor chnages
fix #1622

Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Nov 22, 2023
1 parent c1066f5 commit 17cb95f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 98 deletions.
34 changes: 5 additions & 29 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
from pymongo import MongoClient
from asyncio import Lock
from dotenv import load_dotenv, dotenv_values
from threading import Thread
from time import sleep, time
from time import time
from subprocess import Popen, run as srun
from os import remove as osremove, path as ospath, environ, getcwd
from aria2p import API as ariaAPI, Client as ariaClient
from qbittorrentapi import Client as qbClient

# from faulthandler import enable as faulthandler_enable
from socket import setdefaulttimeout
from uvloop import install
from logging import (
getLogger,
FileHandler,
Expand All @@ -24,9 +22,10 @@
warning as log_warning,
ERROR,
)
from uvloop import install

# from faulthandler import enable as faulthandler_enable
# faulthandler_enable()

install()
setdefaulttimeout(600)

Expand Down Expand Up @@ -454,36 +453,13 @@
osremove("accounts.zip")
if not ospath.exists("accounts"):
config_dict["USE_SERVICE_ACCOUNTS"] = False
sleep(0.5)

aria2 = ariaAPI(ariaClient(host="http://localhost", port=6800, secret=""))


def get_client():
return qbClient(
host="localhost",
port=8090,
VERIFY_WEBUI_CERTIFICATE=False,
REQUESTS_ARGS={"timeout": (30, 60)},
)


def aria2c_init():
try:
log_info("Initializing Aria2c")
link = "https://linuxmint.com/torrents/lmde-5-cinnamon-64bit.iso.torrent"
dire = DOWNLOAD_DIR.rstrip("/")
aria2.add_uris([link], {"dir": dire})
sleep(3)
downloads = aria2.get_downloads()
sleep(10)
aria2.remove(downloads, force=True, files=True, clean=True)
except Exception as e:
log_error(f"Aria2c initializing error: {e}")

return qbClient(host="localhost", port=8090)

Thread(target=aria2c_init).start()
sleep(1.5)

aria2c_global = [
"bt-max-open-files",
Expand Down
3 changes: 2 additions & 1 deletion bot/helper/ext_utils/files_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def clean_target(path):
try:
if await aiopath.isdir(path):
await aiormtree(path)
elif await aiopath.isfile(path):
else:
await aioremove(path)
except Exception as e:
LOGGER.error(str(e))
Expand All @@ -90,6 +90,7 @@ async def clean_download(path):


async def start_cleanup():
aria2.remove_all(True)
get_client().torrents_delete(torrent_hashes="all")
try:
await aiormtree(DOWNLOAD_DIR)
Expand Down
1 change: 0 additions & 1 deletion bot/helper/ext_utils/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
non_queued_dl,
queue_dict_lock,
LOGGER,
DOWNLOAD_DIR,
)
from bot.helper.mirror_utils.gdrive_utils.search import gdSearch
from bot.helper.ext_utils.files_utils import get_base_name
Expand Down
72 changes: 11 additions & 61 deletions bot/helper/mirror_utils/download_utils/direct_link_generator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Copyright (C) 2019 The Raphielscape Company LLC.
#
# Licensed under the Raphielscape Public License, Version 1.c (the "License");
# you may not use this file except in compliance with the License.
#
""" Helper Module containing various sites direct links generators. This module is copied and modified as per need
from https://github.com/AvinashReddy3108/PaperplaneExtended . I hereby take no credit of the following code other
than the modifications. See https://github.com/AvinashReddy3108/PaperplaneExtended/commits/master/userbot/modules/direct_links.py
for original authorship. """
from hashlib import sha256
from http.cookiejar import MozillaCookieJar
from json import loads
Expand All @@ -15,9 +6,7 @@
from time import sleep
from urllib.parse import parse_qs, urlparse
from uuid import uuid4

from cloudscraper import create_scraper
from lk21 import Bypass
from lxml.etree import HTML
from requests import Session, post
from requests import session as req_session
Expand Down Expand Up @@ -130,27 +119,6 @@ def direct_link_generator(link):
]
):
return terabox(link)
elif any(
x in domain
for x in [
"fembed.net",
"fembed.com",
"femax20.com",
"fcdn.stream",
"feurl.com",
"layarkacaxxi.icu",
"naniplay.nanime.in",
"naniplay.nanime.biz",
"naniplay.com",
"mm9842.com",
]
):
return fembed(link)
elif any(
x in domain
for x in ["sbembed.com", "watchsb.com", "streamsb.net", "sbplay.org"]
):
return sbembed(link)
elif any(
x in domain
for x in [
Expand Down Expand Up @@ -287,32 +255,6 @@ def hxfile(url):
raise DirectDownloadLinkException("ERROR: Direct download link not found")


def fembed(link):
"""Fembed direct link generator
Based on https://github.com/zevtyardt/lk21
"""
try:
dl_url = Bypass().bypass_fembed(link)
count = len(dl_url)
lst_link = [dl_url[i] for i in dl_url]
return lst_link[count - 1]
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")


def sbembed(link):
"""Sbembed direct link generator
Based on https://github.com/zevtyardt/lk21
"""
try:
dl_url = Bypass().bypass_sbembed(link)
count = len(dl_url)
lst_link = [dl_url[i] for i in dl_url]
return lst_link[count - 1]
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")


def onedrive(link):
"""Onedrive direct link generator
By https://github.com/junedkh"""
Expand Down Expand Up @@ -1378,7 +1320,14 @@ def filelions_and_streamwish(url):
scheme = parsed_url.scheme
if any(
x in hostname
for x in ["filelions.co", "filelions.live", "filelions.to", "filelions.site", "cabecabean.lol", "filelions.online"]
for x in [
"filelions.co",
"filelions.live",
"filelions.to",
"filelions.site",
"cabecabean.lol",
"filelions.online",
]
):
apiKey = config_dict["FILELION_API"]
apiUrl = "https://api.filelions.co"
Expand Down Expand Up @@ -1513,12 +1462,13 @@ def streamhub(url):
raise DirectDownloadLinkException(f"ERROR: {error[0]}")
raise DirectDownloadLinkException("ERROR: direct link not found!")


def pcloud(url):
with create_scraper() as session:
try:
res = session.get(url)
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")
if link := findall(r'.downloadlink.:..(https:.*)..', res.text):
return link[0].replace('\/', '/')
if link := findall(r".downloadlink.:..(https:.*)..", res.text):
return link[0].replace("\/", "/")
raise DirectDownloadLinkException("ERROR: Direct link not found")
1 change: 0 additions & 1 deletion bot/helper/mirror_utils/download_utils/yt_dlp_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def __init__(self, listener):
"overwrites": True,
"writethumbnail": True,
"trim_file_name": 220,
"compat_opts": {"prefer-legacy-http-handler": "urllib"},
"retry_sleep_functions": {
"http": lambda n: 3,
"fragment": lambda n: 3,
Expand Down
1 change: 0 additions & 1 deletion bot/modules/ytdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ async def newEvent(self):
options[key] = value

options["playlist_items"] = "0"
options["compat_opts"] = {"prefer-legacy-http-handler": "urllib"}

try:
result = await sync_to_async(extract_info, self.link, options)
Expand Down
6 changes: 2 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ google-api-python-client
google-auth-httplib2
google-auth-oauthlib
gunicorn
git+https://github.com/zevtyardt/lk21.git
httpx
lxml
motor
mutagen
natsort
pillow
psutil
pybase64
pymongo
pyrogram
python-dotenv
Expand All @@ -32,6 +29,7 @@ requests
telegraph
tenacity
tgcrypto
urllib3
uvloop
xattr
yt-dlp
yt-dlp

0 comments on commit 17cb95f

Please sign in to comment.