diff --git a/robot.py b/robot.py index 966ba39..08120b4 100755 --- a/robot.py +++ b/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))