searchspotify 0.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- searchspotify-0.0.6/LICENSE +21 -0
- searchspotify-0.0.6/PKG-INFO +123 -0
- searchspotify-0.0.6/README.md +109 -0
- searchspotify-0.0.6/pyproject.toml +6 -0
- searchspotify-0.0.6/setup.cfg +28 -0
- searchspotify-0.0.6/src/searchspotify.egg-info/PKG-INFO +123 -0
- searchspotify-0.0.6/src/searchspotify.egg-info/SOURCES.txt +14 -0
- searchspotify-0.0.6/src/searchspotify.egg-info/dependency_links.txt +1 -0
- searchspotify-0.0.6/src/searchspotify.egg-info/top_level.txt +1 -0
- searchspotify-0.0.6/src/spotifysearch/__init__.py +23 -0
- searchspotify-0.0.6/src/spotifysearch/calls.py +51 -0
- searchspotify-0.0.6/src/spotifysearch/classes.py +767 -0
- searchspotify-0.0.6/src/spotifysearch/client.py +138 -0
- searchspotify-0.0.6/src/spotifysearch/constructor.py +165 -0
- searchspotify-0.0.6/src/spotifysearch/urlbuilder.py +74 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 TRUE SAIYAN
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: searchspotify
|
|
3
|
+
Version: 0.0.6
|
|
4
|
+
Summary: A complete wrapper for the Search API provided by Spotify written in Python.
|
|
5
|
+
Home-page: https://github.com/ufoptg/SearchSpotify
|
|
6
|
+
Author: True Saiyan
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/ufoptg/SearchSpotify/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
|
|
15
|
+
# Spotify Search
|
|
16
|
+
<p>
|
|
17
|
+
<a href="https://choosealicense.com/licenses/mit/" target="_blank">
|
|
18
|
+
<img src="https://img.shields.io/github/license/matcsantos/SearchSpotify" alt="LICENSE">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://pypi.org/project/searchspotify/" target="_blank">
|
|
21
|
+
<img src="https://img.shields.io/pypi/v/searchspotify?color=33BBFF&label=PIP" alt="PIP">
|
|
22
|
+
</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
SearchSpotify is a complete wrapper for the Search API provided by Spotify written in Python.
|
|
26
|
+
|
|
27
|
+
It has built-in classes that helps you access the data returned by Spotify, alongside with useful methods for exporting data.
|
|
28
|
+
|
|
29
|
+
Check the [documentation](https://readthedocs.org/) for more information on classes and methods.
|
|
30
|
+
|
|
31
|
+
## What you can do
|
|
32
|
+
- Get Spotify catalog information about albums, artists or tracks that match a keyword string.
|
|
33
|
+
- Easily access the information provided by Spotify using specific class attributes and methods, such as **name**, **id**, **url** and many more.
|
|
34
|
+
- Access and export audio and image files, such as album covers for example.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
SearchSpotify depends on **[requests](https://pypi.org/project/requests/)**. You can easily install it by using **PIP**
|
|
38
|
+
```bash
|
|
39
|
+
python -m pip install requests
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then, you can safely install SearchSpotify using the following command:
|
|
43
|
+
```bash
|
|
44
|
+
python -m pip install searchspotify
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Testing your installation
|
|
48
|
+
You can test your installation using python interactive shell
|
|
49
|
+
```python
|
|
50
|
+
>>> import searchspotify
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Getting access to the API
|
|
54
|
+
To get access to Spotify Search API, you need to have a Spotify account to get an access token, which is required by the API itself. <br>
|
|
55
|
+
You can [register an account](https://www.spotify.com/signup/) if you don't have one.
|
|
56
|
+
|
|
57
|
+
Then, you need to login into your account in [Spotify for Developers](https://developer.spotify.com/dashboard/login).
|
|
58
|
+
Once you have successfully logged in, go to your **Dashboard**, and create a new application.
|
|
59
|
+
|
|
60
|
+
You should see something like this: <br>
|
|
61
|
+
<p align="center"><img src="https://i.imgur.com/fWLbWUH.png"></p>
|
|
62
|
+
|
|
63
|
+
Once you've created your application, you'll receive a **client ID** and a **client secret**. These are your credentials, you should store them in a **safe environment**.
|
|
64
|
+
|
|
65
|
+
**IMPORTANT: You should not store your credentials inside of your code if you're planning to publish it. You should use Environment Variables instead. Check [this section](https://github.com/ufoptg/SearchSpotify#keeping-your-credentials-safe) to learn how to keep your credentials safe.**
|
|
66
|
+
|
|
67
|
+
## Making your first call
|
|
68
|
+
So now that you have your **credentials**, you can start making your calls to the API.
|
|
69
|
+
|
|
70
|
+
Open your editor and run the following code:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
# First, we import our Client class from searchspotify.client
|
|
74
|
+
from searchspotify.client import Client
|
|
75
|
+
|
|
76
|
+
# Then, we create an instance of that class passing our credentials as arguments.
|
|
77
|
+
# IMPORTANT: Don't put your credentials inside your code if your planning to publish it.
|
|
78
|
+
myclient = Client("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
|
|
79
|
+
|
|
80
|
+
# Now we can call the method search() from our client and store the results in a new object.
|
|
81
|
+
results = myclient.search("Never gonna give you up")
|
|
82
|
+
|
|
83
|
+
# Then we call the method get_tracks() from our results object, which returns a list of tracks.
|
|
84
|
+
tracks = results.get_tracks()
|
|
85
|
+
|
|
86
|
+
# Now, let's access the first track in our list by using index 0.
|
|
87
|
+
track = tracks[0]
|
|
88
|
+
|
|
89
|
+
# Finally, we can access some information contained in our track.
|
|
90
|
+
print(track.name, "-", track.artists[0].name)
|
|
91
|
+
print(track.url)
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**This should be your result:**
|
|
96
|
+
```bash
|
|
97
|
+
Never Gonna Give You Up - Rick Astley
|
|
98
|
+
https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT
|
|
99
|
+
```
|
|
100
|
+
<br>
|
|
101
|
+
|
|
102
|
+
That seems to be a lot of code, but you can simplify it a lot, like so:
|
|
103
|
+
```python
|
|
104
|
+
from searchspotify.client import Client
|
|
105
|
+
|
|
106
|
+
myclient = Client("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
|
|
107
|
+
track = myclient.search("Never gonna give you up").get_tracks()[0]
|
|
108
|
+
|
|
109
|
+
print(track.name, "-", track.artists[0].name)
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
In a few lines of code, we got access to the API, retrieved some useful information of the first track in our results and displayed it.
|
|
113
|
+
|
|
114
|
+
There are a lot of class attributes and methods that you can use to retrieve the information you need, you can check them out in the [documentation](https://readthedocs.org/).
|
|
115
|
+
|
|
116
|
+
## Keeping your credentials safe
|
|
117
|
+
As mentioned before, you should not store your credentials inside of your code. Specially if you are planning to publish it.
|
|
118
|
+
|
|
119
|
+
A safer way to store them is by using Environment Variables.
|
|
120
|
+
Here's a complete [tutorial](https://www.twilio.com/blog/environment-variables-python) on how to define and access environment variables using Python.
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
This project is under the terms of the [MIT license](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Spotify Search
|
|
2
|
+
<p>
|
|
3
|
+
<a href="https://choosealicense.com/licenses/mit/" target="_blank">
|
|
4
|
+
<img src="https://img.shields.io/github/license/matcsantos/SearchSpotify" alt="LICENSE">
|
|
5
|
+
</a>
|
|
6
|
+
<a href="https://pypi.org/project/searchspotify/" target="_blank">
|
|
7
|
+
<img src="https://img.shields.io/pypi/v/searchspotify?color=33BBFF&label=PIP" alt="PIP">
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
SearchSpotify is a complete wrapper for the Search API provided by Spotify written in Python.
|
|
12
|
+
|
|
13
|
+
It has built-in classes that helps you access the data returned by Spotify, alongside with useful methods for exporting data.
|
|
14
|
+
|
|
15
|
+
Check the [documentation](https://readthedocs.org/) for more information on classes and methods.
|
|
16
|
+
|
|
17
|
+
## What you can do
|
|
18
|
+
- Get Spotify catalog information about albums, artists or tracks that match a keyword string.
|
|
19
|
+
- Easily access the information provided by Spotify using specific class attributes and methods, such as **name**, **id**, **url** and many more.
|
|
20
|
+
- Access and export audio and image files, such as album covers for example.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
SearchSpotify depends on **[requests](https://pypi.org/project/requests/)**. You can easily install it by using **PIP**
|
|
24
|
+
```bash
|
|
25
|
+
python -m pip install requests
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then, you can safely install SearchSpotify using the following command:
|
|
29
|
+
```bash
|
|
30
|
+
python -m pip install searchspotify
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Testing your installation
|
|
34
|
+
You can test your installation using python interactive shell
|
|
35
|
+
```python
|
|
36
|
+
>>> import searchspotify
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Getting access to the API
|
|
40
|
+
To get access to Spotify Search API, you need to have a Spotify account to get an access token, which is required by the API itself. <br>
|
|
41
|
+
You can [register an account](https://www.spotify.com/signup/) if you don't have one.
|
|
42
|
+
|
|
43
|
+
Then, you need to login into your account in [Spotify for Developers](https://developer.spotify.com/dashboard/login).
|
|
44
|
+
Once you have successfully logged in, go to your **Dashboard**, and create a new application.
|
|
45
|
+
|
|
46
|
+
You should see something like this: <br>
|
|
47
|
+
<p align="center"><img src="https://i.imgur.com/fWLbWUH.png"></p>
|
|
48
|
+
|
|
49
|
+
Once you've created your application, you'll receive a **client ID** and a **client secret**. These are your credentials, you should store them in a **safe environment**.
|
|
50
|
+
|
|
51
|
+
**IMPORTANT: You should not store your credentials inside of your code if you're planning to publish it. You should use Environment Variables instead. Check [this section](https://github.com/ufoptg/SearchSpotify#keeping-your-credentials-safe) to learn how to keep your credentials safe.**
|
|
52
|
+
|
|
53
|
+
## Making your first call
|
|
54
|
+
So now that you have your **credentials**, you can start making your calls to the API.
|
|
55
|
+
|
|
56
|
+
Open your editor and run the following code:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
# First, we import our Client class from searchspotify.client
|
|
60
|
+
from searchspotify.client import Client
|
|
61
|
+
|
|
62
|
+
# Then, we create an instance of that class passing our credentials as arguments.
|
|
63
|
+
# IMPORTANT: Don't put your credentials inside your code if your planning to publish it.
|
|
64
|
+
myclient = Client("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
|
|
65
|
+
|
|
66
|
+
# Now we can call the method search() from our client and store the results in a new object.
|
|
67
|
+
results = myclient.search("Never gonna give you up")
|
|
68
|
+
|
|
69
|
+
# Then we call the method get_tracks() from our results object, which returns a list of tracks.
|
|
70
|
+
tracks = results.get_tracks()
|
|
71
|
+
|
|
72
|
+
# Now, let's access the first track in our list by using index 0.
|
|
73
|
+
track = tracks[0]
|
|
74
|
+
|
|
75
|
+
# Finally, we can access some information contained in our track.
|
|
76
|
+
print(track.name, "-", track.artists[0].name)
|
|
77
|
+
print(track.url)
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**This should be your result:**
|
|
82
|
+
```bash
|
|
83
|
+
Never Gonna Give You Up - Rick Astley
|
|
84
|
+
https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT
|
|
85
|
+
```
|
|
86
|
+
<br>
|
|
87
|
+
|
|
88
|
+
That seems to be a lot of code, but you can simplify it a lot, like so:
|
|
89
|
+
```python
|
|
90
|
+
from searchspotify.client import Client
|
|
91
|
+
|
|
92
|
+
myclient = Client("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
|
|
93
|
+
track = myclient.search("Never gonna give you up").get_tracks()[0]
|
|
94
|
+
|
|
95
|
+
print(track.name, "-", track.artists[0].name)
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
In a few lines of code, we got access to the API, retrieved some useful information of the first track in our results and displayed it.
|
|
99
|
+
|
|
100
|
+
There are a lot of class attributes and methods that you can use to retrieve the information you need, you can check them out in the [documentation](https://readthedocs.org/).
|
|
101
|
+
|
|
102
|
+
## Keeping your credentials safe
|
|
103
|
+
As mentioned before, you should not store your credentials inside of your code. Specially if you are planning to publish it.
|
|
104
|
+
|
|
105
|
+
A safer way to store them is by using Environment Variables.
|
|
106
|
+
Here's a complete [tutorial](https://www.twilio.com/blog/environment-variables-python) on how to define and access environment variables using Python.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
This project is under the terms of the [MIT license](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = searchspotify
|
|
3
|
+
version = 0.0.6
|
|
4
|
+
author = True Saiyan
|
|
5
|
+
description = A complete wrapper for the Search API provided by Spotify written in Python.
|
|
6
|
+
long_description = file: README.md
|
|
7
|
+
long_description_content_type = text/markdown
|
|
8
|
+
url = https://github.com/ufoptg/SearchSpotify
|
|
9
|
+
project_urls =
|
|
10
|
+
Bug Tracker = https://github.com/ufoptg/SearchSpotify/issues
|
|
11
|
+
classifiers =
|
|
12
|
+
Programming Language :: Python :: 3
|
|
13
|
+
License :: OSI Approved :: MIT License
|
|
14
|
+
Operating System :: OS Independent
|
|
15
|
+
|
|
16
|
+
[options]
|
|
17
|
+
package_dir =
|
|
18
|
+
= src
|
|
19
|
+
packages = find:
|
|
20
|
+
python_requires = >=3.6
|
|
21
|
+
|
|
22
|
+
[options.packages.find]
|
|
23
|
+
where = src
|
|
24
|
+
|
|
25
|
+
[egg_info]
|
|
26
|
+
tag_build =
|
|
27
|
+
tag_date = 0
|
|
28
|
+
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: searchspotify
|
|
3
|
+
Version: 0.0.6
|
|
4
|
+
Summary: A complete wrapper for the Search API provided by Spotify written in Python.
|
|
5
|
+
Home-page: https://github.com/ufoptg/SearchSpotify
|
|
6
|
+
Author: True Saiyan
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/ufoptg/SearchSpotify/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
|
|
15
|
+
# Spotify Search
|
|
16
|
+
<p>
|
|
17
|
+
<a href="https://choosealicense.com/licenses/mit/" target="_blank">
|
|
18
|
+
<img src="https://img.shields.io/github/license/matcsantos/SearchSpotify" alt="LICENSE">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://pypi.org/project/searchspotify/" target="_blank">
|
|
21
|
+
<img src="https://img.shields.io/pypi/v/searchspotify?color=33BBFF&label=PIP" alt="PIP">
|
|
22
|
+
</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
SearchSpotify is a complete wrapper for the Search API provided by Spotify written in Python.
|
|
26
|
+
|
|
27
|
+
It has built-in classes that helps you access the data returned by Spotify, alongside with useful methods for exporting data.
|
|
28
|
+
|
|
29
|
+
Check the [documentation](https://readthedocs.org/) for more information on classes and methods.
|
|
30
|
+
|
|
31
|
+
## What you can do
|
|
32
|
+
- Get Spotify catalog information about albums, artists or tracks that match a keyword string.
|
|
33
|
+
- Easily access the information provided by Spotify using specific class attributes and methods, such as **name**, **id**, **url** and many more.
|
|
34
|
+
- Access and export audio and image files, such as album covers for example.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
SearchSpotify depends on **[requests](https://pypi.org/project/requests/)**. You can easily install it by using **PIP**
|
|
38
|
+
```bash
|
|
39
|
+
python -m pip install requests
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then, you can safely install SearchSpotify using the following command:
|
|
43
|
+
```bash
|
|
44
|
+
python -m pip install searchspotify
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Testing your installation
|
|
48
|
+
You can test your installation using python interactive shell
|
|
49
|
+
```python
|
|
50
|
+
>>> import searchspotify
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Getting access to the API
|
|
54
|
+
To get access to Spotify Search API, you need to have a Spotify account to get an access token, which is required by the API itself. <br>
|
|
55
|
+
You can [register an account](https://www.spotify.com/signup/) if you don't have one.
|
|
56
|
+
|
|
57
|
+
Then, you need to login into your account in [Spotify for Developers](https://developer.spotify.com/dashboard/login).
|
|
58
|
+
Once you have successfully logged in, go to your **Dashboard**, and create a new application.
|
|
59
|
+
|
|
60
|
+
You should see something like this: <br>
|
|
61
|
+
<p align="center"><img src="https://i.imgur.com/fWLbWUH.png"></p>
|
|
62
|
+
|
|
63
|
+
Once you've created your application, you'll receive a **client ID** and a **client secret**. These are your credentials, you should store them in a **safe environment**.
|
|
64
|
+
|
|
65
|
+
**IMPORTANT: You should not store your credentials inside of your code if you're planning to publish it. You should use Environment Variables instead. Check [this section](https://github.com/ufoptg/SearchSpotify#keeping-your-credentials-safe) to learn how to keep your credentials safe.**
|
|
66
|
+
|
|
67
|
+
## Making your first call
|
|
68
|
+
So now that you have your **credentials**, you can start making your calls to the API.
|
|
69
|
+
|
|
70
|
+
Open your editor and run the following code:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
# First, we import our Client class from searchspotify.client
|
|
74
|
+
from searchspotify.client import Client
|
|
75
|
+
|
|
76
|
+
# Then, we create an instance of that class passing our credentials as arguments.
|
|
77
|
+
# IMPORTANT: Don't put your credentials inside your code if your planning to publish it.
|
|
78
|
+
myclient = Client("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
|
|
79
|
+
|
|
80
|
+
# Now we can call the method search() from our client and store the results in a new object.
|
|
81
|
+
results = myclient.search("Never gonna give you up")
|
|
82
|
+
|
|
83
|
+
# Then we call the method get_tracks() from our results object, which returns a list of tracks.
|
|
84
|
+
tracks = results.get_tracks()
|
|
85
|
+
|
|
86
|
+
# Now, let's access the first track in our list by using index 0.
|
|
87
|
+
track = tracks[0]
|
|
88
|
+
|
|
89
|
+
# Finally, we can access some information contained in our track.
|
|
90
|
+
print(track.name, "-", track.artists[0].name)
|
|
91
|
+
print(track.url)
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**This should be your result:**
|
|
96
|
+
```bash
|
|
97
|
+
Never Gonna Give You Up - Rick Astley
|
|
98
|
+
https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT
|
|
99
|
+
```
|
|
100
|
+
<br>
|
|
101
|
+
|
|
102
|
+
That seems to be a lot of code, but you can simplify it a lot, like so:
|
|
103
|
+
```python
|
|
104
|
+
from searchspotify.client import Client
|
|
105
|
+
|
|
106
|
+
myclient = Client("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
|
|
107
|
+
track = myclient.search("Never gonna give you up").get_tracks()[0]
|
|
108
|
+
|
|
109
|
+
print(track.name, "-", track.artists[0].name)
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
In a few lines of code, we got access to the API, retrieved some useful information of the first track in our results and displayed it.
|
|
113
|
+
|
|
114
|
+
There are a lot of class attributes and methods that you can use to retrieve the information you need, you can check them out in the [documentation](https://readthedocs.org/).
|
|
115
|
+
|
|
116
|
+
## Keeping your credentials safe
|
|
117
|
+
As mentioned before, you should not store your credentials inside of your code. Specially if you are planning to publish it.
|
|
118
|
+
|
|
119
|
+
A safer way to store them is by using Environment Variables.
|
|
120
|
+
Here's a complete [tutorial](https://www.twilio.com/blog/environment-variables-python) on how to define and access environment variables using Python.
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
This project is under the terms of the [MIT license](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.cfg
|
|
5
|
+
src/searchspotify.egg-info/PKG-INFO
|
|
6
|
+
src/searchspotify.egg-info/SOURCES.txt
|
|
7
|
+
src/searchspotify.egg-info/dependency_links.txt
|
|
8
|
+
src/searchspotify.egg-info/top_level.txt
|
|
9
|
+
src/spotifysearch/__init__.py
|
|
10
|
+
src/spotifysearch/calls.py
|
|
11
|
+
src/spotifysearch/classes.py
|
|
12
|
+
src/spotifysearch/client.py
|
|
13
|
+
src/spotifysearch/constructor.py
|
|
14
|
+
src/spotifysearch/urlbuilder.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
spotifysearch
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Copyright 2020-2023 (c) Randy W @xtdevs, @xtsea
|
|
4
|
+
# Nimbus ~ UserBot
|
|
5
|
+
# Copyright (C) 2023 NimbusTheCloud, ufoptg, @TrueSaiyan
|
|
6
|
+
#
|
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU Affero General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
# any later version.
|
|
11
|
+
#
|
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
# GNU Affero General Public License for more details.
|
|
16
|
+
# This file is a part of < https://github.com/ufoptg/Nimbus/ >
|
|
17
|
+
# PLease read the GNU Affero General Public License in
|
|
18
|
+
# <https://www.github.com/ufoptg/Nimbus/blob/main/LICENSE/>.
|
|
19
|
+
# If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
from .classes import *
|
|
23
|
+
from .client import Client
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Copyright 2020-2023 (c) Randy W @xtdevs, @xtsea
|
|
4
|
+
# Nimbus ~ UserBot
|
|
5
|
+
# Copyright (C) 2023 NimbusTheCloud, ufoptg, @TrueSaiyan
|
|
6
|
+
#
|
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU Affero General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
# any later version.
|
|
11
|
+
#
|
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
# GNU Affero General Public License for more details.
|
|
16
|
+
# This file is a part of < https://github.com/ufoptg/Nimbus/ >
|
|
17
|
+
# PLease read the GNU Affero General Public License in
|
|
18
|
+
# <https://www.github.com/ufoptg/Nimbus/blob/main/LICENSE/>.
|
|
19
|
+
# If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
|
|
21
|
+
# THIS FILE IS RESPONSABLE FOR API CALLS
|
|
22
|
+
|
|
23
|
+
from requests import get, post
|
|
24
|
+
|
|
25
|
+
from . import urlbuilder
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def call_acess_token(credentials):
|
|
29
|
+
"""
|
|
30
|
+
Calls Spotify API to obtain an access token using client credentials.
|
|
31
|
+
|
|
32
|
+
:param credentials: Encoded client credentials.
|
|
33
|
+
:return: Response object containing the access token.
|
|
34
|
+
"""
|
|
35
|
+
endpoint = "https://accounts.spotify.com/api/token"
|
|
36
|
+
data = {"grant_type": "client_credentials"}
|
|
37
|
+
headers = {"Authorization": f"Basic {credentials}"}
|
|
38
|
+
return post(url=endpoint, data=data, headers=headers)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def call_search(acess_token, args):
|
|
42
|
+
"""
|
|
43
|
+
Calls Spotify API to search for entities using the provided access token and arguments.
|
|
44
|
+
|
|
45
|
+
:param access_token: Access token for authentication.
|
|
46
|
+
:param args: Tuple of arguments for the search endpoint.
|
|
47
|
+
:return: Response object containing the search results.
|
|
48
|
+
"""
|
|
49
|
+
endpoint = urlbuilder.search_endpoint(*args)
|
|
50
|
+
headers = {"Authorization": f"Bearer {acess_token}"}
|
|
51
|
+
return get(url=endpoint, headers=headers)
|