From 5061236b5895d9372003801441cae6ec0c000d56 Mon Sep 17 00:00:00 2001 From: thezero Date: Sat, 19 Jun 2021 20:52:59 +0200 Subject: [PATCH] logging --- src/main.py | 2 +- src/vid_utils.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 9120b1c..41fe769 100644 --- a/src/main.py +++ b/src/main.py @@ -35,7 +35,7 @@ def download_choosen_format(update, context): with video.send() as files: for f in files: - logger.log("Sending... {} ".format(f)) + logger.info("Sending... {} ".format(f)) context.bot.send_document(chat_id=query.message.chat_id, document=open(f, 'rb')) context.bot.delete_message(chat_id=query.message.chat_id, diff --git a/src/vid_utils.py b/src/vid_utils.py index 5022eb2..0f42758 100644 --- a/src/vid_utils.py +++ b/src/vid_utils.py @@ -1,4 +1,5 @@ import os +import logging from glob import glob, escape from subprocess import Popen, PIPE from contextlib import contextmanager @@ -7,6 +8,9 @@ from telegram import InlineKeyboardButton from db import VidDatabase +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) +logger = logging.getLogger(__name__) + class BadLink(Exception): pass @@ -57,6 +61,7 @@ class Video: key = '{},{}'.format(extension, resolution) index = self.db.insert_vid(self.link, format_code) formats[key] = index + logger.info("Fromats: {}".format(formats)) return formats def generate_keyboard(self): @@ -69,9 +74,11 @@ class Video: return kb def download(self): + logger.info("Downloading {}".format(self.link)) p = Popen(["youtube-dl", "-f", self.code, self.link], stdout=PIPE, stderr=PIPE).communicate() for line in str(p[0], 'utf-8').split('\n'): + logger.info(line) if "[download] Destination:" in line: self.file_name = line[24:] # name of the file