upgrade yt-dlp, fix filetype guess issue

This commit is contained in:
BennyThink 2022-01-02 22:51:33 +08:00
parent 01b7214e83
commit 2961fb22a8
No known key found for this signature in database
GPG key ID: 6CD0DBDA5235D481
3 changed files with 11 additions and 8 deletions

View file

@ -1,6 +1,6 @@
pyrogram==1.2.20
tgcrypto==1.2.2
yt-dlp==2021.12.1
yt-dlp==2021.12.27
youtube-dl==2021.6.6
APScheduler==3.7.0
beautifultable==1.0.1

View file

@ -17,6 +17,8 @@ import time
import fakeredis
import filetype
from utils import current_time
if os.getenv("downloader") == "youtube-dl":
import youtube_dl as ytdl
from youtube_dl import DownloadError
@ -100,9 +102,10 @@ def convert_to_mp4(resp: dict, bot_msg):
if resp["status"]:
# all_converted = []
for path in resp["filepath"]:
mime = filetype.guess(path).mime
# if we can't guess file type, we assume it's video/mp4
mime = getattr(filetype.guess(path), "mime", "video/mp4")
if mime in default_type:
edit_text(bot_msg, f"Converting {os.path.basename(path)} to mp4. Please wait patiently.")
edit_text(bot_msg, f"{current_time()}: Converting {os.path.basename(path)} to mp4. Please wait.")
new_name = os.path.basename(path).split(".")[0] + ".mp4"
new_file_path = os.path.join(os.path.dirname(path), new_name)
cmd = ["ffmpeg", "-i", path, new_file_path]
@ -195,5 +198,3 @@ def convert_flac(flac_name, tmp):
def add_instagram_cookies(url: "str", opt: "dict"):
if url.startswith("https://www.instagram.com"):
opt["cookiefile"] = os.path.join(os.path.dirname(__file__), "instagram.com_cookies.txt")

View file

@ -9,6 +9,7 @@ __author__ = "Benny <benny.think@gmail.com>"
import logging
import pathlib
import time
import uuid
import ffmpeg
@ -92,6 +93,7 @@ def get_metadata(video_path):
return dict(height=height, width=width, duration=duration, thumb=thumb)
if __name__ == '__main__':
v = "/Users/benny/Movies/vlc-record-2021-02-27-21h17m53s-逃避可耻却有用 人类加油!新春特别篇!!.NIGERUHA.HAJIDAGA.YAKUNITATSU.Ganbare.Jinrui.Shinshun.Special.SP.Chi_Jap.HDTVrip.1280X720.mp4-.mp4"
get_metadata(v)
def current_time():
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())