Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'raw_input' is not defined? #2

Closed
bascurtiz opened this issue Feb 22, 2019 · 25 comments
Closed

'raw_input' is not defined? #2

bascurtiz opened this issue Feb 22, 2019 · 25 comments
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@bascurtiz
Copy link

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
Copy link
Owner

Try to change raw_input to input

@superdima05
Copy link
Owner

What version of python do you use?

@bascurtiz
Copy link
Author

Python 3.7.2

@superdima05
Copy link
Owner

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

@bascurtiz
Copy link
Author

I did, and then it works!
image

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

image

@superdima05
Copy link
Owner

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

@superdima05
Copy link
Owner

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

@bascurtiz
Copy link
Author

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
Copy link
Owner

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

@superdima05
Copy link
Owner

Now script works, normally?

@bascurtiz
Copy link
Author

bascurtiz commented Feb 22, 2019

Only, the search function.

  • I will look into python3 branch (not sure what the difference is between my installed Python 3.7.2 and python3)
  • will pip install wget, I assume

@bascurtiz
Copy link
Author

image

@superdima05
Copy link
Owner

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

@superdima05
Copy link
Owner

7fe2a15b-d381-4b1f-a8ff-b3cc07147ca4

@bascurtiz
Copy link
Author

image

@superdima05
Copy link
Owner

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

@bascurtiz
Copy link
Author

\o/

@superdima05
Copy link
Owner

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
Copy link
Owner

I wrote this from my phone

@bascurtiz
Copy link
Author

bascurtiz commented Feb 22, 2019

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
Copy link
Owner

Use new update of python3

@superdima05
Copy link
Owner

python3 branch

@bascurtiz
Copy link
Author

Works!
Thank you =)
image

Will test playlist too.

@superdima05
Copy link
Owner

superdima05 commented Feb 22, 2019

OK, can I close this issue?

@bascurtiz
Copy link
Author

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

@superdima05 superdima05 added bug Something isn't working enhancement New feature or request good first issue Good for newcomers labels Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants