update check_dimension and webm supports
This commit is contained in:
parent
63c8751cc0
commit
81943166d5
15
main.py
15
main.py
@ -4,9 +4,9 @@ from glob import glob
|
|||||||
|
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
from telegram.ext import Updater, MessageHandler, Filters
|
from telegram.ext import Updater, MessageHandler, Filters
|
||||||
|
from vid_utils import check_dimension
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||||
level=logging.INFO)
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
updater = Updater(token='TOKEN') # put here the bot's token
|
updater = Updater(token='TOKEN') # put here the bot's token
|
||||||
@ -17,16 +17,21 @@ ydl_opts = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def download(bot, update):
|
def download(bot, update):
|
||||||
for f in glob('*.mp4'):
|
for f in glob('*.mp4*') + glob('*.webm*'): # with glob it isn't possible to check multiple extension in one regex
|
||||||
os.remove(f) # remove old video(s)
|
os.remove(f) # remove old video(s)
|
||||||
try:
|
try:
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
ydl.download([update.message.text])
|
ydl.download([update.message.text])
|
||||||
|
|
||||||
for f in glob('*.mp4'): # TODO this way for find the file(s) IMHO is not elegant
|
for f in glob('*.mp4*') + glob('*.webm*'): # if the video is bigger than 50MB split it
|
||||||
|
check_dimension(f)
|
||||||
|
break # check first file
|
||||||
|
|
||||||
|
for f in glob('*.mp4*') + glob('*.webm*'): # send document(s)
|
||||||
bot.send_document(chat_id=update.message.chat_id, document=open(f, 'rb'))
|
bot.send_document(chat_id=update.message.chat_id, document=open(f, 'rb'))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
bot.sendMessage(chat_id=update.message.chat_id, text='Error')
|
bot.sendMessage(chat_id=update.message.chat_id, text='Error: {}'.format(e))
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
|
|
||||||
download_handler = MessageHandler(Filters.text, download)
|
download_handler = MessageHandler(Filters.text, download)
|
||||||
|
Loading…
Reference in New Issue
Block a user