audio extraction capabilities
This commit is contained in:
parent
2cfacc76b5
commit
de6fc16044
1 changed files with 16 additions and 3 deletions
19
robot.py
19
robot.py
|
@ -46,13 +46,19 @@ def ytdl_has(url):
|
|||
return False
|
||||
|
||||
|
||||
def download_ydl(urls, subdir, date):
|
||||
def download_ydl(urls, subdir, date, extract=False):
|
||||
ydl_opts = {
|
||||
'noplaylist': True,
|
||||
'restrictfilenames': True,
|
||||
'download_archive': DIR + '/downloaded.lst',
|
||||
'outtmpl': f'{TMP_DIR}/' + datestr(date) + '__%(title)s__%(id)s.%(ext)s'
|
||||
}
|
||||
if extract:
|
||||
ydl_opts['format'] = 'bestaudio'
|
||||
ydl_opts['postprocessors'] = [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'wav'
|
||||
}]
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download(urls)
|
||||
out_dir = f'{OUT_DIR}/{subdir}/'
|
||||
|
@ -98,10 +104,17 @@ def handle_url(bot, update):
|
|||
try:
|
||||
logger.info("Downloading %s" % ytdl_urls)
|
||||
hashtag = get_first_hashtag(update.message)
|
||||
|
||||
reply = 'Downloading'
|
||||
if hashtag:
|
||||
mkdir_p(f'{OUT_DIR}/{hashtag}')
|
||||
update.message.reply_text('Downloading%s...' % f' to "{hashtag}"' if hashtag else '')
|
||||
download_ydl(ytdl_urls, hashtag or '.', update.message.date)
|
||||
reply += f' to "{hashtag}"'
|
||||
reply += '...'
|
||||
|
||||
if hashtag == 'AUDIO':
|
||||
reply += ' (And also guessing you want to extract the audio)'
|
||||
update.message.reply_text(reply)
|
||||
download_ydl(ytdl_urls, hashtag or '.', update.message.date, extract=hashtag == 'AUDIO')
|
||||
except:
|
||||
type, value, _ = sys.exc_info()
|
||||
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
||||
|
|
Loading…
Reference in a new issue