mirror of
https://github.com/tgbot-collection/ytdlbot.git
synced 2025-02-24 15:24:03 +08:00
fix filename too long bug, change log formatter
This commit is contained in:
parent
bdfd24b97c
commit
2c3e102cee
4 changed files with 32 additions and 7 deletions
|
@ -20,9 +20,11 @@ from youtube_dl import DownloadError
|
|||
|
||||
from config import ENABLE_VIP
|
||||
from limit import VIP, Redis
|
||||
from utils import apply_log_formatter
|
||||
|
||||
r = fakeredis.FakeStrictRedis()
|
||||
EXPIRE = 5
|
||||
apply_log_formatter()
|
||||
|
||||
|
||||
def sizeof_fmt(num: int, suffix='B'):
|
||||
|
@ -103,7 +105,7 @@ def convert_to_mp4(resp: dict):
|
|||
def ytdl_download(url, tempdir, bm) -> dict:
|
||||
chat_id = bm.chat.id
|
||||
response = {"status": True, "error": "", "filepath": []}
|
||||
output = os.path.join(tempdir, '%(title)s.%(ext)s')
|
||||
output = os.path.join(tempdir, '%(title).50s.%(ext)s')
|
||||
ydl_opts = {
|
||||
'progress_hooks': [lambda d: download_hook(d, bm)],
|
||||
'outtmpl': output,
|
||||
|
|
3
limit.py
3
limit.py
|
@ -25,6 +25,9 @@ from beautifultable import BeautifulTable
|
|||
|
||||
from config import (AFD_TOKEN, AFD_USER_ID, COFFEE_TOKEN, ENABLE_VIP, EX,
|
||||
MULTIPLY, OWNER, QUOTA, REDIS, USD2CNY)
|
||||
from utils import apply_log_formatter
|
||||
|
||||
apply_log_formatter()
|
||||
|
||||
|
||||
class Redis:
|
||||
|
|
24
utils.py
Normal file
24
utils.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/local/bin/python3
|
||||
# coding: utf-8
|
||||
|
||||
# ytdlbot - utils.py
|
||||
# 9/1/21 22:50
|
||||
#
|
||||
|
||||
__author__ = "Benny <benny.think@gmail.com>"
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
def apply_log_formatter():
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='[%(asctime)s %(filename)s:%(lineno)d %(levelname).1s] %(message)s',
|
||||
datefmt="%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
|
||||
|
||||
def customize_logger(logger: "list"):
|
||||
apply_log_formatter()
|
||||
for log in logger:
|
||||
logging.getLogger(log).setLevel(level=logging.WARNING)
|
8
ytdl.py
8
ytdl.py
|
@ -24,12 +24,7 @@ from config import APP_HASH, APP_ID, ENABLE_VIP, OWNER, TOKEN, WORKERS
|
|||
from constant import BotText
|
||||
from downloader import convert_flac, sizeof_fmt, upload_hook, ytdl_download
|
||||
from limit import Redis, verify_payment
|
||||
|
||||
|
||||
def customize_logger(logger: "list"):
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(filename)s [%(levelname)s]: %(message)s')
|
||||
for log in logger:
|
||||
logging.getLogger(log).setLevel(level=logging.WARNING)
|
||||
from utils import customize_logger
|
||||
|
||||
|
||||
def create_app(session="ytdl", workers=WORKERS):
|
||||
|
@ -42,6 +37,7 @@ def create_app(session="ytdl", workers=WORKERS):
|
|||
customize_logger(["pyrogram.client", "pyrogram.session.session", "pyrogram.client", "pyrogram.connection.connection"])
|
||||
app = create_app()
|
||||
bot_text = BotText()
|
||||
logging
|
||||
|
||||
|
||||
def get_metadata(video_path):
|
||||
|
|
Loading…
Reference in a new issue