Skip to content

Commit

Permalink
changed default quality for yt
Browse files Browse the repository at this point in the history
audio upload
now possible delete default thumb

Signed-off-by: Udith <[email protected]>
  • Loading branch information
uaudith committed Apr 26, 2020
1 parent 1e45952 commit 03bdbce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
53 changes: 46 additions & 7 deletions userge/plugins/misc/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ async def explorer(path: Path, chatid, flags):
async def upload(path: Path, chat_id: int, flags):
if path.name.endswith((".mkv", ".mp4", ".webm")) and ('d' not in flags):
await vid_upload(chat_id, path)

elif path.name.endswith((".mp3", ".flac", ".wav", ".m4a")) and ('d' not in flags):
await audio_upload(chat_id, path)
else:
await doc_upload(chat_id, path)

Expand All @@ -88,9 +89,12 @@ async def doc_upload(chat_id, path):
)
)

await finalize(chat_id, message, msg, start_t)


async def finalize(chat_id, message, msg, start_t):
await CHANNEL.fwd_msg(msg)
await userge.send_chat_action(chat_id, "cancel")

if message.process_is_canceled:
await message.edit("`Process Canceled!`", del_in=5)

Expand All @@ -106,7 +110,7 @@ async def vid_upload(chat_id, path):
metadata = extractMetadata(createParser(strpath))

message: Message = await userge.send_message(
chat_id, f"`Uploading {path.name} ...` as a video")
chat_id, f"`Uploading {path.name} as a video ..`")

start_t = datetime.now()
c_time = time.time()
Expand All @@ -124,9 +128,8 @@ async def vid_upload(chat_id, path):
"uploading", userge, message, c_time
)
)

await CHANNEL.fwd_msg(msg)
await userge.send_chat_action(chat_id, "cancel")
await CHANNEL.fwd_msg(msg)
await remove_thumb(thumb)

if message.process_is_canceled:
Expand All @@ -138,7 +141,41 @@ async def vid_upload(chat_id, path):
await message.edit(f"Uploaded in {ms} seconds")


async def get_thumb(path: str = '') -> str:
async def audio_upload(chat_id, path):
title = None
artist = None
message: Message = await userge.send_message(
chat_id, f"`Uploading {path.name} as audio ...`")
strpath = str(path)
start_t = datetime.now()
c_time = time.time()
thumb = await get_thumb()
metadata = extractMetadata(createParser(strpath))
if metadata.has("title"):
title = metadata.get("title")
if metadata.has("artist"):
artist = metadata.get("artist")
await userge.send_chat_action(chat_id, "upload_audio")
msg = await userge.send_audio(
chat_id=chat_id,
audio=strpath,
thumb=thumb,
caption=path.name,
title=title,
performer=artist,
duration=metadata.get("duration").seconds,
parse_mode="html",
disable_notification=True,
progress=progress,
progress_args=(
"uploading", userge, message, c_time
)
)

await finalize(chat_id, message, msg, start_t)


async def get_thumb(path: str = ''):
if os.path.exists(THUMB_PATH):
return THUMB_PATH

Expand All @@ -149,7 +186,9 @@ async def get_thumb(path: str = '') -> str:
return await take_screen_shot(
path, metadata.get("duration").seconds)

return LOGO_PATH
if os.path.exists(LOGO_PATH):
return LOGO_PATH
return None


async def remove_thumb(thumb: str) -> None:
Expand Down
6 changes: 4 additions & 2 deletions userge/plugins/utils/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ async def clear_thumb_nail(message: Message):

if os.path.exists(THUMB_PATH):
os.remove(THUMB_PATH)

await message.edit("✅ Custom thumbnail deleted succesfully.", del_in=3)
await message.edit("✅ Custom thumbnail deleted succesfully.", del_in=3)
elif os.path.exists('resources/userge.png'):
os.remove('resources/userge.png')
await message.edit("✅ Default thumbnail deleted succesfully.", del_in=3)


@userge.on_cmd('vthumb', about={'header': "View thumbnail"})
Expand Down
4 changes: 2 additions & 2 deletions userge/plugins/utils/utube.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def supported(url):

def tubeDl(url: list, prog, uid=None):
_opts = {'outtmpl': path.join('downloads', '%(title)s-%(format)s.%(ext)s')}
_quality = {'format': 'best' if not uid else str(uid)}
_quality = {'format': 'bestvideo+bestaudio/best' if not uid else str(uid)}
_opts.update(_quality)
try:
x = ytdl.YoutubeDL(_opts)
Expand Down Expand Up @@ -109,7 +109,7 @@ def __progress(data: dict):
if not (eta and speed):
return
out = "**Speed** >> {}/s\n**ETA** >> {}\n".format(humanbytes(speed), time_formatter(eta))
out += f'**File Name** >> __{data["filename"]}__\n\n'
out += f'**File Name** >> `{data["filename"]}`\n\n'
current = data['downloaded_bytes']
total = data["total_bytes"]
if current and total:
Expand Down

0 comments on commit 03bdbce

Please sign in to comment.