コード例 #1
0
def Audio(audio, chat_id):
    global spo
    global goes
    goes = 1
    file = local + "/Songs/" + audio + ".ogg"
    bot.download_file(audio, file)
    audio = acrcloud.recognizer(config, file)
    try:
        os.remove(file)
    except FileNotFoundError:
        None
    if audio['status']['msg'] != "Success":
        bot.sendMessage(
            chat_id, "Sorry cannot detect the song from audio :(, retry...")
    else:
        artist = audio['metadata']['music'][0]['artists'][0]['name']
        track = audio['metadata']['music'][0]['title']
        album = audio['metadata']['music'][0]['album']['name']
        try:
            date = audio['metadata']['music'][0]['release_date']
        except KeyError:
            None
        try:
            label = audio['metadata']['music'][0]['label']
        except KeyError:
            None
        try:
            genre = audio['metadata']['music'][0]['genres'][0]['name']
        except KeyError:
            None
        try:
            album += ">" + date
        except NameError:
            None
        try:
            album += ">" + label
        except NameError:
            None
        try:
            album += ">" + genre
        except NameError:
            None
        if len(album) > 64:
            album = "Infos with too many bytes"
        if len(album.split(">")) == 1:
            album = "No informations"
        url = json.loads(
            requests.get("https://api.deezer.com/search/track/?q=" +
                         track.replace("#", "") + " + " +
                         artist.replace("#", "")).text)
        try:
            for a in range(url['total'] + 1):
                if url['data'][a]['title'] == track or url['data'][a][
                        'title_short'] in track:
                    id = url['data'][a]['link']
                    image = url['data'][a]['album']['cover_xl']
                    break
        except IndexError:
            try:
                url = json.loads(
                    requests.get("https://api.deezer.com/search/track/?q=" +
                                 track.replace("#", "").split(" ")[0] + " + " +
                                 artist.replace("#", "")).text)
                for a in range(url['total'] + 1):
                    if track.split(" ")[0] in url['data'][a]['title']:
                        id = url['data'][a]['link']
                        image = url['data'][a]['album']['cover_xl']
                        break
            except IndexError:
                try:
                    id = "https://open.spotify.com/track/" + \
                        audio['metadata']['music'][0]['external_metadata']['spotify']['track']['id']
                    try:
                        url = spo.track(id)
                    except:
                        token = generate_token()
                        spo = spotipy.Spotify(auth=token)
                        url = spo.track(id)
                    image = url['album']['images'][0]['url']
                except KeyError:
                    None
                try:
                    id = "https://www.deezer.com/track/" + \
                        str(audio['metadata']['music'][0]
                            ['external_metadata']['deezer']['track']['id'])
                    url = json.loads(
                        requests.get("http://api.deezer.com/track/" +
                                     id.split("/")[-1]).text)
                    image = url['album']['cover_xl']
                except KeyError:
                    None
        try:
            bot.sendPhoto(
                chat_id,
                image,
                caption=track + " - " + artist,
                reply_markup=InlineKeyboardMarkup(inline_keyboard=[[
                    InlineKeyboardButton(text="Download", callback_data=id),
                    InlineKeyboardButton(text="Info", callback_data=album)
                ]]))
        except:
            bot.sendMessage(chat_id, "Error :(")
    goes = 2
コード例 #2
0
ファイル: bot.py プロジェクト: phanirithvij/DeezloaderRMX_bot
def Audio(audio, chat_id):
    global spo
    file = loc_dir + audio + ".ogg"
    try:
        bot.download_file(audio, file)
    except telepot.exception.TelegramError:
        sendMessage(chat_id, translate(
            languag[chat_id], "File sent is too big, please send a file lower than 20 MB"))
        return
    audio = acrcloud.recognizer(config, file)
    try:
        os.remove(file)
    except FileNotFoundError:
        pass
    if audio['status']['msg'] != "Success":
        sendMessage(chat_id, translate(
            languag[chat_id], "Sorry cannot detect the song from audio :(, retry..."))
    else:
        artist = audio['metadata']['music'][0]['artists'][0]['name']
        track = audio['metadata']['music'][0]['title']
        album = audio['metadata']['music'][0]['album']['name']
        try:
            date = audio['metadata']['music'][0]['release_date']
            album += "_" + date
        except KeyError:
            album += "_"
        try:
            label = audio['metadata']['music'][0]['label']
            album += "_" + label
        except KeyError:
            album += "_"
        try:
            genre = audio['metadata']['music'][0]['genres'][0]['name']
            album += "_" + genre
        except KeyError:
            album += "_"
        if len(album) > 64:
            album = "Infos with too many bytes"
        try:
            url = request("https://api.deezer.com/search/track/?q=" + track.replace(
                "#", "") + " + " + artist.replace("#", ""), chat_id, True).json()
        except AttributeError:
            return
        try:
            for a in range(url['total'] + 1):
                if url['data'][a]['title'] == track:
                    id = url['data'][a]['link']
                    image = url['data'][a]['album']['cover_xl']
                    break
        except IndexError:
            try:
                id = "https://open.spotify.com/track/" + \
                    audio['metadata']['music'][0]['external_metadata']['spotify']['track']['id']
                try:
                    url = spo.track(id)
                except:
                    spo = spotipy.Spotify(auth=generate_token())
                    url = spo.track(id)
                image = url['album']['images'][0]['url']
            except KeyError:
                pass
            try:
                id = "https://api.deezer.com/track/" + \
                    str(audio['metadata']['music'][0]
                        ['external_metadata']['deezer']['track']['id'])
                try:
                    url = request(id, chat_id, True).json()
                except AttributeError:
                    return
                image = url['album']['cover_xl']
            except KeyError:
                pass
        try:
            sendPhoto(chat_id, image, caption=track + " - " + artist,
                      reply_markup=InlineKeyboardMarkup(
                          inline_keyboard=[
                              [InlineKeyboardButton(text="Download", callback_data=id), InlineKeyboardButton(
                                  text="Info", callback_data=album)]
                          ]
                      ))
        except:
            sendMessage(chat_id, translate(languag[chat_id], "Error :("))
コード例 #3
0
ファイル: main.py プロジェクト: BogdanRajkov/LyricsFinder
fs = 44100

os.system('cls')
print('LyricsFinder by Srki & Bobo\n')

print('snimam')
rec_start = time.time()
myrec = sd.rec(int(duration*fs))
sd.wait()

print('pisem u fajl')
sf.write('test.wav', myrec, fs)

print('prepoznajem')
stopwatch = time.time()
song = acr.recognizer(config, 'test.wav')
print('vreme:', time.time() - stopwatch)

if song['status']['msg'] == 'Success':
    # artist_name = fix_text(song['metadata']['music'][0]['artists'][0]['name'])
    # song_name = fix_text(song['metadata']['music'][0]['title'])
    artist_name = song['metadata']['music'][0]['artists'][0]['name']
    song_name = song['metadata']['music'][0]['title']

    play_offset = song['metadata']['music'][0]['play_offset_ms'] / 1000
    song_start = rec_start - play_offset
    song_duration = song['metadata']['music'][0]['duration_ms'] / 1000

    lyrics = genius.search_song(song_name, artist_name)
    print(lyrics)
    if lyrics is None: