Skip to content

Commit

Permalink
pylint: auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
InukaAsith committed Feb 1, 2021
1 parent 92c999b commit 8737ef4
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 117 deletions.
1 change: 1 addition & 0 deletions virtualuserbot/modules/crack_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async def vypr(event):
)
os.remove("hits.txt")


@friday.on(friday_on_cmd(pattern="combogen"))
async def byekanger(event):
url = "http://devsexpo.me/combogen/"
Expand Down
81 changes: 43 additions & 38 deletions virtualuserbot/modules/upload_dl.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# @UniBorg
from urllib.parse import urlparse
import asyncio
import json
import math
import requests
import os
import subprocess
import time
from datetime import datetime
from urllib.parse import urlparse

import requests
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser
from pySmartDL import SmartDL
from telethon.tl.types import DocumentAttributeVideo
from virtualuserbot.function.FastTelethon import upload_file

from virtualuserbot import CMD_HELP, LOGS, TEMP_DOWNLOAD_DIRECTORY
from virtualuserbot.events import register
from virtualuserbot.function.FastTelethon import upload_file
from virtualuserbot.utils import edit_or_reply, friday_on_cmd, sudo_cmd


Expand Down Expand Up @@ -43,7 +43,6 @@ async def progress(current, total, event, start, type_of_ps, file_name=None):
try:
await event.edit(
"{}\n**File Name:** `{}`\n{}".format(type_of_ps, file_name, tmp)

)
except:
pass
Expand Down Expand Up @@ -106,18 +105,18 @@ async def download(target_file):
try:
c_time = time.time()
downloaded_file_name = await target_file.client.download_media(
await target_file.get_reply_message(),
TEMP_DOWNLOAD_DIRECTORY,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(d, t, target_file, c_time, "Downloading This Media...")
),
)
await target_file.get_reply_message(),
TEMP_DOWNLOAD_DIRECTORY,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(d, t, target_file, c_time, "Downloading This Media...")
),
)
except Exception as e: # pylint:disable=C0103,W0703
await friday.edit(str(e))
else:
await friday.edit(
"Downloaded to `{}` successfully !!".format(downloaded_file_name)
)
"Downloaded to `{}` successfully !!".format(downloaded_file_name)
)


@friday.on(friday_on_cmd(pattern=r"uploadir (.*)"))
Expand Down Expand Up @@ -380,7 +379,8 @@ async def uploadas(uas_event):
else:
await uas_event.edit("404: File Not Found")

@borg.on(friday_on_cmd(pattern='smartdl'))

@borg.on(friday_on_cmd(pattern="smartdl"))
async def lul(event):
if event.fwd_from:
return
Expand All @@ -402,19 +402,22 @@ async def lul(event):
now = time.time()
diff = now - c_time
percentage = downloader.get_progress() * 100
speed = downloader.get_speed()
elapsed_time = round(diff) * 1000
downloader.get_speed()
round(diff) * 1000
progress_str = "[{0}{1}]\nProgress: {2}%".format(
''.join(["▰" for i in range(math.floor(percentage / 5))]),
''.join(["▱" for i in range(20 - math.floor(percentage / 5))]),
round(percentage, 2))
"".join(["▰" for i in range(math.floor(percentage / 5))]),
"".join(["▱" for i in range(20 - math.floor(percentage / 5))]),
round(percentage, 2),
)
estimated_total_time = downloader.get_eta(human=True)
try:
current_message = f"trying to download\n"
current_message += f"URL: {url}\n"
current_message += f"File Name: {file_name}\n"
current_message += f"{progress_str}\n"
current_message += f"{humanbytes(downloaded)} of {humanbytes(total_length)}\n"
current_message += (
f"{humanbytes(downloaded)} of {humanbytes(total_length)}\n"
)
current_message += f"ETA: {estimated_total_time}"
if round(diff % 10.00) == 0 and current_message != display_message:
await mone.edit(current_message)
Expand All @@ -425,46 +428,48 @@ async def lul(event):
ms = (end - start).seconds
if downloader.isSuccessful():
c_time = time.time()
lul = await mone.edit("Downloaded to `{}` in {} seconds.".format(downloaded_file_name, ms))
lul = await mone.edit(
"Downloaded to `{}` in {} seconds.".format(downloaded_file_name, ms)
)
lol_m = await upload_file(
file_name=file_name,
client=borg,
file=open(downloaded_file_name, 'rb'),
file=open(downloaded_file_name, "rb"),
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d, t, event, c_time, "Uploading This File.", downloaded_file_name
)
),
)
await borg.send_file(event.chat_id,
lol_m,
caption=file_name,
force_document=False,
allow_cache=False,
)
await borg.send_file(
event.chat_id,
lol_m,
caption=file_name,
force_document=False,
allow_cache=False,
)
await lul.delete()
os.remove(downloaded_file_name)
else:
await mone.edit("Incorrect URL\n {}".format(input_str))



@friday.on(friday_on_cmd(pattern="zeelink"))
async def lol_kangers(event):
input_str = event.raw_text.split(" ", maxsplit=1)[1]
if 'zee' in input_str:
if "zee" in input_str:
url = "http://devsexpo.me/zee/"
sed = {
'url': input_str
}
sed = {"url": input_str}
lmao = requests.get(url=url, headers=sed).json()
else:
await event.edit("Only Zee Videos Supported.")
return
if lmao['success'] is False:
await event.edit("Task Failed Due To " + str(lmao['error']))
if lmao["success"] is False:
await event.edit("Task Failed Due To " + str(lmao["error"]))
return
await event.edit("Direct Link Fetched \nURL : " + str(lmao['url']))
await event.edit("Direct Link Fetched \nURL : " + str(lmao["url"]))


CMD_HELP.update(
{
"download": ".dl <link|filename> or reply to media\
Expand Down
139 changes: 60 additions & 79 deletions virtualuserbot/modules/ytmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,18 @@

import asyncio
import os

import wget
from youtubesearchpython import SearchVideos
import asyncio
import math
import os
import time

import wget
from telethon.tl.types import DocumentAttributeAudio
from uniborg.util import edit_or_reply, friday_on_cmd, sudo_cmd
from youtube_dl import YoutubeDL
from youtube_dl.utils import (
ContentTooShortError,
DownloadError,
ExtractorError,
GeoRestrictedError,
MaxDownloadsReached,
PostProcessingError,
UnavailableVideoError,
XAttrMetadataError,
)
from virtualuserbot.function import progress, humanbytes, time_formatter
from virtualuserbot.function.FastTelethon import upload_file
from youtubesearchpython import SearchVideos

from virtualuserbot import CMD_HELP
from virtualuserbot.Configs import Config
from virtualuserbot.function import progress
from virtualuserbot.function.FastTelethon import upload_file
from virtualuserbot.utils import edit_or_reply, friday_on_cmd, sudo_cmd


Expand Down Expand Up @@ -65,24 +52,24 @@ async def _(event):
url = mo
sedlyf = wget.download(kekme, out=path)
opts = {
"format": "bestaudio",
"addmetadata": True,
"key": "FFmpegMetadata",
"writethumbnail": True,
"prefer_ffmpeg": True,
"geo_bypass": True,
"nocheckcertificate": True,
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "480",
}
],
"outtmpl": "%(title)s.mp3",
"quiet": True,
"logtostderr": False,
}
"format": "bestaudio",
"addmetadata": True,
"key": "FFmpegMetadata",
"writethumbnail": True,
"prefer_ffmpeg": True,
"geo_bypass": True,
"nocheckcertificate": True,
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "480",
}
],
"outtmpl": "%(title)s.mp3",
"quiet": True,
"logtostderr": False,
}
try:
with YoutubeDL(opts) as ytdl:
ytdl_data = ytdl.extract_info(url)
Expand All @@ -93,15 +80,13 @@ async def _(event):
c_time = time.time()
file_stark = f"{ytdl_data['title']}.mp3"
lol_m = await upload_file(
file_name=file_stark,
client=borg,
file=open(file_stark, 'rb'),
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d, t, event, c_time, "Uploading Your Song!", file_stark
)
),
)
file_name=file_stark,
client=borg,
file=open(file_stark, "rb"),
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(d, t, event, c_time, "Uploading Your Song!", file_stark)
),
)
capy = f"**Song Name ➠** `{thum}` \n**Requested For ➠** `{urlissed}` \n**Channel ➠** `{thums}` \n**Link ➠** `{mo}`"
await event.delete()
await borg.send_file(
Expand All @@ -112,18 +97,19 @@ async def _(event):
caption=capy,
thumb=sedlyf,
attributes=[
DocumentAttributeAudio(
duration=int(ytdl_data["duration"]),
title=str(ytdl_data["title"]),
performer=str(ytdl_data["uploader"]),
)
],
DocumentAttributeAudio(
duration=int(ytdl_data["duration"]),
title=str(ytdl_data["title"]),
performer=str(ytdl_data["uploader"]),
)
],
supports_streaming=True,
)
for files in (sedlyf, file_stark):
if files and os.path.exists(files):
os.remove(files)



@friday.on(friday_on_cmd(pattern="utubevid ?(.*)"))
@friday.on(sudo_cmd(pattern="utubevid ?(.*)", allow_sudo=True))
async def _(event):
Expand All @@ -148,19 +134,17 @@ async def _(event):
url = mo
sedlyf = wget.download(kekme, out=path)
opts = {
"format": "best",
"addmetadata": True,
"key": "FFmpegMetadata",
"prefer_ffmpeg": True,
"geo_bypass": True,
"nocheckcertificate": True,
"postprocessors": [
{"key": "FFmpegVideoConvertor", "preferedformat": "mp4"}
],
"outtmpl": "%(title)s.mp4",
"logtostderr": False,
"quiet": True,
}
"format": "best",
"addmetadata": True,
"key": "FFmpegMetadata",
"prefer_ffmpeg": True,
"geo_bypass": True,
"nocheckcertificate": True,
"postprocessors": [{"key": "FFmpegVideoConvertor", "preferedformat": "mp4"}],
"outtmpl": "%(title)s.mp4",
"logtostderr": False,
"quiet": True,
}
try:
with YoutubeDL(opts) as ytdl:
ytdl_data = ytdl.extract_info(url)
Expand All @@ -170,15 +154,13 @@ async def _(event):
c_time = time.time()
file_stark = f"{ytdl_data['title']}.mp4"
lol_m = await upload_file(
file_name=file_stark,
client=borg,
file=open(file_stark, 'rb'),
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d, t, event, c_time, "Uploading Your Video!", file_stark
)
),
)
file_name=file_stark,
client=borg,
file=open(file_stark, "rb"),
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(d, t, event, c_time, "Uploading Your Video!", file_stark)
),
)
capy = f"**Video Name ➠** `{thum}` \n**Requested For ➠** `{urlissed}` \n**Channel ➠** `{thums}` \n**Link ➠** `{mo}`"
await event.delete()
await borg.send_file(
Expand All @@ -189,17 +171,16 @@ async def _(event):
caption=capy,
thumb=sedlyf,
attributes=[
DocumentAttributeAudio(
duration=int(ytdl_data["duration"]),
)
],
DocumentAttributeAudio(
duration=int(ytdl_data["duration"]),
)
],
supports_streaming=True,
)
for files in (sedlyf, file_stark):
if files and os.path.exists(files):
os.remove(files)



CMD_HELP.update(
{
Expand Down

0 comments on commit 8737ef4

Please sign in to comment.