superdima05 / tidalgrabber

If you have a lossless subscription, and you want to get .flac files, you can use this python script.
15 stars 3 forks source link

'raw_input' is not defined? #2

Closed bascurtiz closed 5 years ago

bascurtiz commented 5 years ago

After fixing the indents in tidal.py with PyCharm, changing the token to a working one, using my own login credentials, i get this:

image

Any idea?

superdima05 commented 5 years ago

Try to change raw_input to input

superdima05 commented 5 years ago

What version of python do you use?

bascurtiz commented 5 years ago

Python 3.7.2

superdima05 commented 5 years ago

Did you try to change raw_input() to input()?

bascurtiz commented 5 years ago

I did, and then it works! image

But when trying to grab a playlist or album, I get this: image

image

superdima05 commented 5 years ago

Try to use branch "python3", but don't forget this script uses wget

superdima05 commented 5 years ago

I will use python downloading using requests instead of wget, but I can't do it now

bascurtiz commented 5 years ago

Awesome!

Just FYI: However, Search feature in your script is working with: browser = 'wdgaB1CilGA-S_s2' # Streams HIGH/LOW Quality over RTMP, FLAC and Videos over HTTP, but many Lossless Streams are encrypted. native = '4zx46pyr9o8qZNRw' # Same as Android Token, but FLAC streams are encrypted audirvana = 'BI218mwp9ERZ3PFI' # Like Android Token, supports MQA, but returns 'numberOfVideos = 0' in Playlists amarra = 'wc8j_yBJd20zOmx0' # Like Android Token, but returns 'numberOfVideos = 0' in Playlists token2 = 'oIaGpqT_vQPnTr0Q' # Like token1, but uses RTMP for HIGH/LOW Quality

Search feature in your script is NOT working with: token1 = 'P5Xbeo5LFvESeDy6' # Like Android Token, but returns 'numberOfVideos = 0' in Playlists token3 = '_KM2HixcUBZtmktH' # Same as token1 android = 'kgsOOmYk3zShYrNP' # All Streams are HTTP Streams. Correct numberOfVideos in Playlists ios = '_DSTon1kC8pABnTw' # Same as Android Token, but uses ALAC instead of FLAC

superdima05 commented 5 years ago

By default I use this token “audirvana = 'BI218mwp9ERZ3PFI' # Like Android Token, supports MQA, but returns 'numberOfVideos = 0' in Playlists”

superdima05 commented 5 years ago

Now script works, normally?

bascurtiz commented 5 years ago

Only, the search function.

bascurtiz commented 5 years ago

image

superdima05 commented 5 years ago

No, if you want to work with python3 you need to grab script from this repository from branch “python3”

superdima05 commented 5 years ago

7fe2a15b-d381-4b1f-a8ff-b3cc07147ca4

bascurtiz commented 5 years ago

image

superdima05 commented 5 years ago

OK, I understood. I have the same problem, I will fix it after I charge my laptop.

bascurtiz commented 5 years ago

\o/

superdima05 commented 5 years ago

Try to add this function def download(url, file_name): with open(file_name, "wb") as file: response = get(url), this to start of file from requests import get. And then replace os.system('wget "'+url+'" -O "music/'+name+'.flac"') os.system('wget "'+track.album.image+'" -O "music/'+name+'.png"') with download(url, 'music/'+name+'.flac') download(track.album.image, name+'.png')

superdima05 commented 5 years ago

I wrote this from my phone

bascurtiz commented 5 years ago

image

# -*- coding: utf-8 -*-
# vim:fileencoding=utf-8

import tidalapi
from transliterate import translit
import os
from mutagen.flac import Picture, FLAC
from requests import get

session = tidalapi.Session(tidalapi.Config('LOSSLESS'))
session._config.api_token='BI218mwp9ERZ3PFI'
session.login('xxx@xxx.com', 'xxx')

def download(url, file_name):

    with open(file_name, "wb") as file: response = get(url)

def start():

    mode = input("Mode: \n 1) Playlist grabber\n 2) Track grabber\n 3) Album grabber\n 4) Search \n")

    if int(mode) == 1:
        playlist_id = input("Enter playlist id: ")
        playlist = session.get_playlist_tracks(playlist_id=playlist_id)
        for track in playlist:
            download_flac(track)
        want_start()
    elif int(mode) == 2:
        track_id = input("Enter track id: ")
        track = session._map_request('tracks/'+str(track_id), params={'limit': 100}, ret='tracks')
        download_flac(track)
        want_start()
    elif int(mode) == 3:
        album_id = input("Enter album id: ")
        album = session.get_album_tracks(album_id=album_id)
        for track in album:
            download_flac(track)
        want_start()
    elif int(mode) == 4:
        search_query = input("Enter search query: ")
        search = session.search(field='track', value=search_query)
        for track in search.tracks:
            print(track.artist.name+" - "+track.name+": "+str(track.id))
        want_start()
    else:
        print("Incorrect mode!")
        start()

def download_flac(track):
    url = session.get_media_url(track_id=track.id)
    name = translit(""+track.name, "ru", reversed=True)
    artist_name = translit(""+track.artist.name, "ru", reversed=True)
    album_name = translit(""+track.album.name, "ru", reversed=True)
    releaseDate = str(track.album.release_date)
    print(name+' - '+url)
    album_artist = translit(u""+track.album.artist.name, "ru", reversed=True).encode("UTF-8")
    print('wget "'+url+'" -O "music/'+name+'.flac"')
    download(url, 'music/'+name+'.flac')
    download(track.album.image, name+'.png')
    audio = FLAC("music/"+name+".flac")
    albumart = "music/"+name+".png"
    image = Picture()
    image.type = 3
    mime = 'image/png'
    image.desc = 'front cover'
    with open(albumart, 'rb') as f: # better than open(albumart, 'rb').read() ?
        image.data = f.read()
    audio['artist'] = artist_name
    audio['title'] = name
    audio['album'] = album_name
    audio['date'] = releaseDate
    audio.add_picture(image)
    audio.save()
    os.remove("music/"+name+".png")

def want_start():
    want = input("Do you want to continue [0/1]: ")
    if want == "1":
        start()
    elif want == "0":
        print("OK!")
    else:
        want_start()
start()
#playlist = session.get_playlist_tracks(playlist_id='004a984e-6f9e-44ed-a447-9c3dd4b0405f')
#for track in playlist:
#    url = session.get_media_url(track_id=track.id)
#    name = translit(u""+track.name, "ru", reversed=True).encode("UTF-8")
#    print(name+' - '+url)
#    os.system('wget "'+url+'" -O "music/'+name+'.flac"'.encode('utf-8'))
superdima05 commented 5 years ago

Use new update of python3

superdima05 commented 5 years ago

python3 branch

bascurtiz commented 5 years ago

Works! Thank you =) image

Will test playlist too.

superdima05 commented 5 years ago

OK, can I close this issue?

bascurtiz commented 5 years ago

Let's. And focus on playlist, cause it errors after a bit.