Skip to content

Commit

Permalink
minor fixings on ytdl and flags for video formats
Browse files Browse the repository at this point in the history
improved help

Signed-off-by: Udith <[email protected]>
  • Loading branch information
uaudith committed Apr 25, 2020
1 parent 95d2c70 commit 25e1bd2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 25 additions & 10 deletions userge/plugins/utils/utube.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from os import path
import asyncio
from time import time

from userge.utils import time_formatter, humanbytes


Expand All @@ -21,9 +22,9 @@ def yt_getInfo(link):
formats = x.get('formats', [x])
out = "No formats found :("
if formats:
out = "--U-ID | Resolution | Extension--\n"
out = "--U-ID | Reso. | Extension--\n"
for i in formats:
out += f"`{i['format_id']} | {i.get('format_note', None)} | {i.get('ext', None)} `\n"
out += f"`{i['format_id']} | {i.get('format_note', None)} | {i.get('ext', None)}`\n"
except ytdl.utils.YoutubeDLError as e:
return e
else:
Expand All @@ -40,8 +41,8 @@ def supported(url):


def tubeDl(url: list, prog, uid=None):
_opts = {'outtmpl': path.join('downloads', '%(extractor)s-%(title)s-%(format)s.%(ext)s')}
_quality = {'format': 'bestvideo+bestaudio/best' if not uid else str(uid)}
_opts = {'outtmpl': path.join('downloads', '%(title)s-%(format)s.%(ext)s')}
_quality = {'format': 'best' if not uid else str(uid)}
_opts.update(_quality)
try:
x = ytdl.YoutubeDL(_opts)
Expand All @@ -53,7 +54,10 @@ def tubeDl(url: list, prog, uid=None):
return dloader


@userge.on_cmd("ytinfo", about={'header': "Get info from ytdl"})
@userge.on_cmd("ytinfo", about={'header': "Get info from ytdl",
'description': 'Get information of the link without downloading',
'examples': '`.ytinfo link`',
'others': 'To get info about direct links, use `.head link`'})
async def ytinfo(message: Message):
await message.edit("Hold on \u23f3 ..")
_exracted = yt_getInfo(message.input_or_reply_str)
Expand All @@ -76,27 +80,38 @@ async def ytinfo(message: Message):
await message.edit(out)


@userge.on_cmd("ytdl", about={'header': "Download from youtube"})
@userge.on_cmd("ytdl", about={'header': "Download from youtube",
'options': {'-a': 'select the audio u-id',
'-v': 'select the video u-id'},
'examples': ['.ytdl `link`',
'`.ytdl -a12 -v120 link`']}, del_pre=True)
async def ytDown(message: Message):
await message.edit("Hold on \u23f3 ..")
desiredFormat = None
startTime = time()
if bool(message.flags) & len(message.flags) <= 2:
desiredFormat = ''
if bool(message.flags):
desiredFormat1 = str(message.flags.get('a', ''))
desiredFormat2 = str(message.flags.get('v', ''))
if len(message.flags) == 2:
# 1st format must contain the video
desiredFormat = '+'.join([desiredFormat2, desiredFormat1])
elif len(message.flags) == 1:
desiredFormat = desiredFormat2 or desiredFormat1

def __progress(data: dict):
if ((time() - startTime) % 3) > 2.9:
if ((time() - startTime) % 4) > 3.9:
if data['status'] == "downloading":
eta = data['eta']
speed = data['speed']
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'
current = data['downloaded_bytes']
total = data["total_bytes"]
if current and total:
percentage = int(current) * 100 / int(total)
out += f"Progress >> {int(percentage)}%\n\n"
out += f"Progress >> {int(percentage)}%\n"
out += "[{}{}]".format(''.join(["█" for _ in range(floor(percentage / 5))]),
''.join(["░" for _ in range(20 - floor(percentage / 5))]))
if message.text != out:
Expand Down
2 changes: 1 addition & 1 deletion userge/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
__version_mjaor__ = 0
__version_minor__ = 1
__version_micro__ = 3
__version_beta__ = 12
__version_beta__ = 13

__version__ = "{}.{}.{}".format(__version_mjaor__,
__version_minor__,
Expand Down

0 comments on commit 25e1bd2

Please sign in to comment.