formate file by date of message
This commit is contained in:
parent
2d1b968780
commit
4798507629
1 changed files with 8 additions and 9 deletions
17
robot.py
17
robot.py
|
@ -2,7 +2,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
|
@ -27,25 +26,25 @@ def ytdl_has(url):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def date():
|
def datestr(date):
|
||||||
return datetime.now().strftime("%Y-%m-%d@%H%M")
|
return date.strftime("%Y-%m-%d@%H%M")
|
||||||
|
|
||||||
|
|
||||||
def download_ydl(urls):
|
def download_ydl(urls, date):
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'noplaylist': True,
|
'noplaylist': True,
|
||||||
'download_archive': DIR + '/downloaded.lst',
|
'download_archive': DIR + '/downloaded.lst',
|
||||||
'outtmpl': OUT_DIR + '/' + date() + '__%(title)s__%(id)s.%(ext)s'
|
'outtmpl': OUT_DIR + '/' + datestr(date) + '__%(title)s__%(id)s.%(ext)s'
|
||||||
}
|
}
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
ydl.download(urls)
|
ydl.download(urls)
|
||||||
|
|
||||||
|
|
||||||
def download_raw(url):
|
def download_raw(url, date):
|
||||||
ext = ''
|
ext = ''
|
||||||
if 'api.telegram.org' in url and 'animation' in url and "mp4" not in url:
|
if 'api.telegram.org' in url and 'animation' in url and "mp4" not in url:
|
||||||
ext = '.mp4'
|
ext = '.mp4'
|
||||||
local_filename = OUT_DIR + '/' + date() + '__' + url.split('/')[-1] + ext
|
local_filename = OUT_DIR + '/' + datestr(date) + '__' + url.split('/')[-1] + ext
|
||||||
r = requests.get(url, stream=True)
|
r = requests.get(url, stream=True)
|
||||||
with open(local_filename, 'wb') as f:
|
with open(local_filename, 'wb') as f:
|
||||||
for chunk in r.iter_content(chunk_size=1024):
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
|
@ -63,7 +62,7 @@ def handle_url(bot, update):
|
||||||
try:
|
try:
|
||||||
logger.info("Downloading %s" % ytdl_urls)
|
logger.info("Downloading %s" % ytdl_urls)
|
||||||
update.message.reply_text('Downloading now...')
|
update.message.reply_text('Downloading now...')
|
||||||
download_ydl(ytdl_urls)
|
download_ydl(ytdl_urls, update.message.date)
|
||||||
except:
|
except:
|
||||||
type, value, _ = sys.exc_info()
|
type, value, _ = sys.exc_info()
|
||||||
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
||||||
|
@ -86,7 +85,7 @@ def handle_rest(bot, update):
|
||||||
url = bot.getFile(file).file_path
|
url = bot.getFile(file).file_path
|
||||||
update.message.reply_text('Downloading now...')
|
update.message.reply_text('Downloading now...')
|
||||||
logger.info("Downloading '%s'" % url)
|
logger.info("Downloading '%s'" % url)
|
||||||
download_raw(url)
|
download_raw(url, update.message.date)
|
||||||
except:
|
except:
|
||||||
type, value, _ = sys.exc_info()
|
type, value, _ = sys.exc_info()
|
||||||
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
||||||
|
|
Loading…
Reference in a new issue