Skip to content

Commit

Permalink
fix ytinfo [400 WEBPAGE_MEDIA_EMPTY] , remove notes case sensitivity …
Browse files Browse the repository at this point in the history
…and photo support for upload command
  • Loading branch information
rking32 committed Jul 21, 2020
1 parent 75defae commit 1c797ad
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion userge/plugins/misc/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ async def dremove_(message: Message) -> None:
await message.edit(f"path : `{path}` **removed** successfully!", del_in=5)


@userge.on_cmd('drename ([^|]+)\|([^|]+)', about={
@userge.on_cmd('drename ([^|]+)\|([^|]+)', about={ # noqa
'header': "rename a directory or file",
'usage': "{tr}drename [path / name] | [new name]"}, allow_channels=False)
async def drename_(message: Message) -> None:
Expand Down
32 changes: 32 additions & 0 deletions userge/plugins/misc/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ async def upload(message: Message, path: Path, del_path: bool = False):
await vid_upload(message, path, del_path)
elif path.name.endswith((".mp3", ".flac", ".wav", ".m4a")) and ('d' not in message.flags):
await audio_upload(message, path, del_path)
elif path.name.endswith((".jpg", ".jpeg", ".png", ".bmp")) and ('d' not in message.flags):
await photo_upload(message, path, del_path)
else:
await doc_upload(message, path, del_path)

Expand Down Expand Up @@ -332,6 +334,36 @@ async def audio_upload(message: Message, path, del_path: bool):
os.remove(str(path))


async def photo_upload(message: Message, path, del_path: bool):
strpath = str(path)
sent: Message = await message.client.send_message(
message.chat.id, f"`Uploading {path.name} as photo ...`")
start_t = datetime.now()
c_time = time.time()
await message.client.send_chat_action(message.chat.id, "upload_photo")
try:
msg = await message.client.send_photo(
chat_id=message.chat.id,
photo=strpath,
caption=path.name,
parse_mode="html",
disable_notification=True,
progress=progress,
progress_args=(
"uploading", userge, message, c_time, str(path.name)
)
)
except Exception as u_e:
await sent.edit(u_e)
raise u_e
else:
await sent.delete()
await finalize(message, msg, start_t)
finally:
if os.path.exists(str(path)) and del_path:
os.remove(str(path))


async def get_thumb(path: str = ''):
if os.path.exists(THUMB_PATH):
return THUMB_PATH
Expand Down
15 changes: 9 additions & 6 deletions userge/plugins/misc/utube.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#
# All rights reserved.

import asyncio
import os
import glob
from os import path
import asyncio
from pathlib import Path
from time import time
from math import floor

import wget
import youtube_dl as ytdl

from userge import userge, Message, Config, pool
Expand Down Expand Up @@ -45,8 +46,10 @@ async def ytinfo(message: Message):
{table}
""".format_map(_exracted)
if _exracted['thumb']:
await message.reply_photo(_exracted['thumb'], caption=out)
_tmp = wget.download(_exracted['thumb'], os.path.join(Config.DOWN_PATH, f"{time()}.jpg"))
await message.reply_photo(_tmp, caption=out)
await message.delete()
os.remove(_tmp)
else:
await message.edit(out)

Expand Down Expand Up @@ -113,7 +116,7 @@ def __progress(data: dict):
retcode = await _tubeDl(
[message.filtered_input_str], __progress, startTime, None)
if retcode == 0:
_fpath = glob.glob(path.join(Config.DOWN_PATH, str(startTime), '*'))[0]
_fpath = glob.glob(os.path.join(Config.DOWN_PATH, str(startTime), '*'))[0]
await message.edit(f"**YTDL completed in {round(time() - startTime)} seconds**\n`{_fpath}`")
if 't' in message.flags:
await upload(message, Path(_fpath))
Expand Down Expand Up @@ -182,7 +185,7 @@ def _supported(url):

@pool.run_in_thread
def _tubeDl(url: list, prog, starttime, uid=None):
_opts = {'outtmpl': path.join(Config.DOWN_PATH, str(starttime), '%(title)s-%(format)s.%(ext)s'),
_opts = {'outtmpl': os.path.join(Config.DOWN_PATH, str(starttime), '%(title)s-%(format)s.%(ext)s'),
'logger': LOGGER,
'postprocessors': [
{'key': 'FFmpegMetadata'}
Expand All @@ -205,7 +208,7 @@ def _tubeDl(url: list, prog, starttime, uid=None):

@pool.run_in_thread
def _mp3Dl(url, prog, starttime):
_opts = {'outtmpl': path.join(Config.DOWN_PATH, str(starttime), '%(title)s.%(ext)s'),
_opts = {'outtmpl': os.path.join(Config.DOWN_PATH, str(starttime), '%(title)s.%(ext)s'),
'logger': LOGGER,
'writethumbnail': True,
'postprocessors': [
Expand Down
10 changes: 7 additions & 3 deletions userge/plugins/utils/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ async def get_note(message: Message) -> None:
can_access = message.from_user.is_self or message.from_user.id in Config.SUDO_USERS
if Config.OWNER_ID:
can_access = can_access or message.from_user.id == Config.OWNER_ID
notename = message.matches[0].group(1)
if notename not in NOTES_DATA[message.chat.id]:
notename = message.matches[0].group(1).lower()
mid, is_global = (0, False)
for note in NOTES_DATA[message.chat.id]:
if note.lower() == notename:
mid, is_global = NOTES_DATA[message.chat.id][note]
break
if not mid:
return
mid, is_global = NOTES_DATA[message.chat.id][notename]
if can_access or is_global:
replied = message.reply_to_message
user_id = message.from_user.id
Expand Down

0 comments on commit 1c797ad

Please sign in to comment.