Esempio n. 1
0
def download_songs_from_file(file_name: str) -> None:
    '''
    downloads all songs from the given file
    '''
    if not os.path.isfile(file_name):
        print('File not exists')
        return

    with open(file_name, 'r') as file:
        for line in file:
            print('\n' + line.strip())
            download_audio(line.strip())
def download(bot, update):
	try:
		try:
			text = update.callback_query.data
			update = update.callback_query
		except:
			text = update.message.text

		if not helpers.check(text):
			bot_msg = bot.send_message(chat_id=update.message.chat_id, text=usage_msg)
			time.sleep(20)
			bot.delete_message(chat_id=update.message.chat_id, message_id=bot_msg.message_id)
		else:
			sent_msg = bot.send_message(chat_id=update.message.chat_id, text=dwn_msg)
			url = helpers.get_url(text)
			vId = helpers.get_vId(url)
			sys.stdout.write("New song request client username %s\n" % update.message.chat.username)
			audio_info = downloader.download_audio(vId, url)
			bot.delete_message(chat_id=update.message.chat_id, message_id=sent_msg.message_id)

			try:
				bot.delete_message(chat_id=update.message.chat_id, message_id=update.message.message_id)
			except:
				pass

			if not audio_info["status"]:
				msg = "Something went wrong: %s" % audio_info["error"]
				return bot.send_message(chat_id=update.message.chat_id, text=msg)

			audio = open(audio_info["path"], 'rb')
			bot.send_audio(chat_id=update.message.chat_id, audio=audio, duration=audio_info["duration"], title=audio_info["title"], timeout=999)
	except:
		pass
Esempio n. 3
0
    def get(self):
        link = self.get_argument('link')
        path = os.path.join('mp3cache/', sha_hash(link))
        if not os.path.exists(path):
            try:
                downloader.download_audio(link)
            except Exception:
                self.set_status(404, 'Not Found')
                self.set_header('Content-Type', 'text/html')
                with open('web/404-video.html') as fin:
                    self.smart_write(fin.read())
                self.finish()
                return

        self.set_status(200, 'OK')
        self.set_header('Content-Type', 'application/octet-stream')
        with open(path, 'rb') as fin:
            self.smart_write(fin.read())
        self.finish()
Esempio n. 4
0
    def get(self):
        link = self.get_argument('link')
        path = os.path.join('mp3cache/', sha_hash(link))
        if not os.path.exists(path):
            try:
                downloader.download_audio(link)
            except Exception:
                self.set_status(404, 'Not Found')
                self.set_header('Content-Type', 'text/html')
                with open('web/404-video.html') as fin:
                    self.smart_write(fin.read())
                self.finish()
                return

        self.set_status(200, 'OK')
        self.set_header('Content-Type', 'application/octet-stream')
        with open(path, 'rb') as fin:
            self.smart_write(fin.read())
        self.finish()
Esempio n. 5
0
def download_video(update: Update, context: CallbackContext) -> None:
    update.message.reply_chat_action(ChatAction.RECORD_AUDIO)
    audio_file, display_name = download_audio(update.message.text)

    update.message.reply_chat_action(ChatAction.UPLOAD_AUDIO)
    update.message.reply_audio(audio_file,
                               title=display_name,
                               filename=f'{display_name}.mp3',
                               quote=True,
                               timeout=180)

    os.remove(audio_file.name)