tamland / python-tidal

Python API for TIDAL music streaming service
GNU Lesser General Public License v3.0
406 stars 110 forks source link

Search function not working properly #113

Closed Grunksky closed 2 years ago

Grunksky commented 2 years ago

Hello, I'm attempting to use the session.search() function on version 0.7.0rc1, however the command only results in an error.

Here's a sample of my code:

import tidalapi
session = tidalapi.Session()
session.load_oauth_session(token_type="Bearer", access_token="mytokenhere")
tracker = session.search(query="Citys", models="Track", limit="1", offset="0")
print(tracker)

Here's the output:

Traceback (most recent call last):
  File "C:\Users\Name\PycharmProjects\TidalTest\Tidal.py", line 7, in <module>
    tracker = session.search(query="Citys", models="Track", limit="1", offset="0")
  File "C:\Users\Name\PycharmProjects\TidalTest\venv\lib\site-packages\tidalapi\session.py", line 436, in search
    raise ValueError("Tried to search for an invalid type")
ValueError: Tried to search for an invalid type

However if I change the the models="Track" var to models="" the output becomes:

{'artists': [<tidalapi.artist.Artist object at 0x00000181EC624A90>], 'albums': [<tidalapi.album.Album object at 0x00000181EC624250>], 'tracks': [<tidalapi.media.Track object at 0x00000181EC6243D0>], 'videos': [<tidalapi.media.Video object at 0x00000181EC6244F0>], 'playlists': [<tidalapi.playlist.Playlist object at 0x00000181EC624490>], 'top_hit': <tidalapi.artist.Artist object at 0x00000181EC6242E0>}

I'm really at a loss for ideas, so any insight would be greatly appreciated.

morguldir commented 2 years ago

In the second one they are just list of the relevant types, look at the docs to see what you can do with them.

Models is a list of the actual types, e.g [tidalapi.media.Track]

Grunksky commented 2 years ago

In the second one they are just list of the relevant types, look at the docs to see what you can do with them.

Thanks for the reply, however I just can't figure it out. Adding [tidalapi.media.Track] did allow the command to finish properly, but then what? Should I use the tidal.media.Track.parse_track() function to get the track info? It appears that the function requires a json_obj input, but tidalapi.media.Track doesn't seem to output that.

morguldir commented 2 years ago

I only linked the docs mentally, but here they are, the types are clickable so you can see the properties of everything in the output of search.

https://0-7-x--tidalapi.netlify.app/api.html#tidalapi.session.Session.search

Grunksky commented 2 years ago

Got it! Thanks a bunch for your help. For anyone in the future having a similar problem, here's my code (I'm new to python, so this can probably be cleaned up):

searchres = session.search(query="PutSearchHere", models=[tidalapi.media.Track], limit="1", offset="0")
defined = searchres.get("top_hit")
print(defined.id)