fix square video

This commit is contained in:
BennyThink 2021-08-24 22:34:52 +08:00
parent c835585a05
commit 839bbfd975
No known key found for this signature in database
GPG key ID: 6CD0DBDA5235D481
2 changed files with 28 additions and 6 deletions

View file

@ -1,11 +1,13 @@
pyrogram==1.2.9
tgcrypto==1.2.2
youtube-dl==2021.6.6
APScheduler==3.7.0
beautifultable==1.0.1
ffmpeg-python==0.2.0
supervisor
tgbot-ping
fakeredis
filetype
redis
requests
APScheduler==3.7.0
beautifultable==1.0.1
supervisor
requests

24
ytdl.py
View file

@ -15,6 +15,7 @@ import tempfile
import time
import typing
import ffmpeg
from apscheduler.schedulers.background import BackgroundScheduler
from pyrogram import Client, filters, types
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
@ -24,6 +25,20 @@ from constant import BotText
from downloader import convert_flac, sizeof_fmt, upload_hook, ytdl_download
from limit import VIP, Redis, verify_payment
def get_metadata(video_path):
height, width, duration = 1280, 720, 0
try:
video_streams = ffmpeg.probe(video_path, select_streams="v")
for item in video_streams.get("streams", []):
height = item["height"]
width = item["width"]
duration = int(float(video_streams["format"]["duration"]))
except Exception as e:
logging.error(e)
return dict(height=height, width=width, duration=duration)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(filename)s [%(levelname)s]: %(message)s')
@ -34,6 +49,7 @@ def create_app(session="ytdl", workers=100):
_app = Client(session, api_id, api_hash,
bot_token=token, workers=workers)
return _app
@ -158,10 +174,14 @@ def download_handler(client: "Client", message: "types.Message"):
bot_msg.edit_text('Download complete. Sending now...')
remain = bot_text.remaining_quota_caption(chat_id)
size = sizeof_fmt(os.stat(video_path).st_size)
client.send_video(chat_id, video_path, supports_streaming=True,
meta = get_metadata(video_path)
client.send_video(chat_id, video_path,
supports_streaming=True,
caption=f"`{filename}`\n\n{url}\n\nsize: {size}\n\n{remain}",
progress=upload_hook, progress_args=(bot_msg,),
reply_markup=markup)
reply_markup=markup,
**meta
)
Redis().update_metrics("video_success")
bot_msg.edit_text('Download success!✅')
else: