%global _empty_manifest_terminate_build 0
Name: python-spotify
Version: 0.10.2
Release: 1
Summary: spotify.py is an asynchronous API wrapper for Spotify written in Python.
License: MIT
URL: https://github.com/mental32/spotify.py
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/d2/a1/b08be1aae30d1dd28b63328e114d9d3a326308db07461604ef24e31e6a5e/spotify-0.10.2.tar.gz
BuildArch: noarch
Requires: python3-aiohttp
Requires: python3-backoff
%description

[](https://github.com/mental32/spotify.py/stargazers)
# spotify.py
An API library for the spotify client and the Spotify Web API written in Python.
Spotify.py is an asyncronous API library for Spotify. While maintaining an
emphasis on being purely asyncronous the library provides syncronous
functionality with the `spotify.sync` module.
```python
import spotify.sync as spotify # Nothing requires async/await now!
```
## Index
- [Installing](#Installing)
- [Examples](#Examples)
- [Resources](#Resources)
## Installing
To install the library simply clone it and run pip.
- `git clone https://github.com/mental32/spotify.py`
- `pip3 install -U .`
or use pypi
- `pip3 install -U spotify` (latest stable)
- `pip3 install -U git+https://github.com/mental32/spotify.py#egg=spotify` (nightly)
## Examples
### Sorting a playlist by popularity
```py
import sys
import getpass
import spotify
async def main():
playlist_uri = input("playlist_uri: ")
client_id = input("client_id: ")
secret = getpass.getpass("application secret: ")
token = getpass.getpass("user token: ")
async with spotify.Client(client_id, secret) as client:
user = await spotify.User.from_token(client, token)
async for playlist in user:
if playlist.uri == playlist_uri:
return await playlist.sort(reverse=True, key=(lambda track: track.popularity))
print('No playlists were found!', file=sys.stderr)
if __name__ == '__main__':
client.loop.run_until_complete(main())
```
### Required oauth scopes for methods
```py
import spotify
from spotify.oauth import get_required_scopes
# In order to call this method sucessfully the "user-modify-playback-state" scope is required.
print(get_required_scopes(spotify.Player.play)) # => ["user-modify-playback-state"]
# Some methods have no oauth scope requirements, so `None` will be returned instead.
print(get_required_scopes(spotify.Playlist.get_tracks)) # => None
```
### Usage with flask
```py
import string
import random
from typing import Tuple, Dict
import flask
import spotify.sync as spotify
SPOTIFY_CLIENT = spotify.Client('SPOTIFY_CLIENT_ID', 'SPOTIFY_CLIENT_SECRET')
APP = flask.Flask(__name__)
APP.config.from_mapping({'spotify_client': SPOTIFY_CLIENT})
REDIRECT_URI: str = 'http://localhost:8888/spotify/callback'
OAUTH2_SCOPES: Tuple[str] = ('user-modify-playback-state', 'user-read-currently-playing', 'user-read-playback-state')
OAUTH2: spotify.OAuth2 = spotify.OAuth2(SPOTIFY_CLIENT.id, REDIRECT_URI, scopes=OAUTH2_SCOPES)
SPOTIFY_USERS: Dict[str, spotify.User] = {}
@APP.route('/spotify/callback')
def spotify_callback():
try:
code = flask.request.args['code']
except KeyError:
return flask.redirect('/spotify/failed')
else:
key = ''.join(random.choice(string.ascii_uppercase) for _ in range(16))
SPOTIFY_USERS[key] = spotify.User.from_code(
SPOTIFY_CLIENT,
code,
redirect_uri=REDIRECT_URI,
refresh=True
)
flask.session['spotify_user_id'] = key
return flask.redirect('/')
@APP.route('/spotify/failed')
def spotify_failed():
flask.session.pop('spotify_user_id', None)
return 'Failed to authenticate with Spotify.'
@APP.route('/')
@APP.route('/index')
def index():
try:
return repr(SPOTIFY_USERS[flask.session['spotify_user_id']])
except KeyError:
return flask.redirect(OAUTH2.url)
if __name__ == '__main__':
APP.run('127.0.0.1', port=8888, debug=False)
```
## Resources
For resources look at the [examples](https://github.com/mental32/spotify.py/tree/master/examples) or ask in the [discord](https://discord.gg/k43FSFF)
%package -n python3-spotify
Summary: spotify.py is an asynchronous API wrapper for Spotify written in Python.
Provides: python-spotify
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-spotify

[](https://github.com/mental32/spotify.py/stargazers)
# spotify.py
An API library for the spotify client and the Spotify Web API written in Python.
Spotify.py is an asyncronous API library for Spotify. While maintaining an
emphasis on being purely asyncronous the library provides syncronous
functionality with the `spotify.sync` module.
```python
import spotify.sync as spotify # Nothing requires async/await now!
```
## Index
- [Installing](#Installing)
- [Examples](#Examples)
- [Resources](#Resources)
## Installing
To install the library simply clone it and run pip.
- `git clone https://github.com/mental32/spotify.py`
- `pip3 install -U .`
or use pypi
- `pip3 install -U spotify` (latest stable)
- `pip3 install -U git+https://github.com/mental32/spotify.py#egg=spotify` (nightly)
## Examples
### Sorting a playlist by popularity
```py
import sys
import getpass
import spotify
async def main():
playlist_uri = input("playlist_uri: ")
client_id = input("client_id: ")
secret = getpass.getpass("application secret: ")
token = getpass.getpass("user token: ")
async with spotify.Client(client_id, secret) as client:
user = await spotify.User.from_token(client, token)
async for playlist in user:
if playlist.uri == playlist_uri:
return await playlist.sort(reverse=True, key=(lambda track: track.popularity))
print('No playlists were found!', file=sys.stderr)
if __name__ == '__main__':
client.loop.run_until_complete(main())
```
### Required oauth scopes for methods
```py
import spotify
from spotify.oauth import get_required_scopes
# In order to call this method sucessfully the "user-modify-playback-state" scope is required.
print(get_required_scopes(spotify.Player.play)) # => ["user-modify-playback-state"]
# Some methods have no oauth scope requirements, so `None` will be returned instead.
print(get_required_scopes(spotify.Playlist.get_tracks)) # => None
```
### Usage with flask
```py
import string
import random
from typing import Tuple, Dict
import flask
import spotify.sync as spotify
SPOTIFY_CLIENT = spotify.Client('SPOTIFY_CLIENT_ID', 'SPOTIFY_CLIENT_SECRET')
APP = flask.Flask(__name__)
APP.config.from_mapping({'spotify_client': SPOTIFY_CLIENT})
REDIRECT_URI: str = 'http://localhost:8888/spotify/callback'
OAUTH2_SCOPES: Tuple[str] = ('user-modify-playback-state', 'user-read-currently-playing', 'user-read-playback-state')
OAUTH2: spotify.OAuth2 = spotify.OAuth2(SPOTIFY_CLIENT.id, REDIRECT_URI, scopes=OAUTH2_SCOPES)
SPOTIFY_USERS: Dict[str, spotify.User] = {}
@APP.route('/spotify/callback')
def spotify_callback():
try:
code = flask.request.args['code']
except KeyError:
return flask.redirect('/spotify/failed')
else:
key = ''.join(random.choice(string.ascii_uppercase) for _ in range(16))
SPOTIFY_USERS[key] = spotify.User.from_code(
SPOTIFY_CLIENT,
code,
redirect_uri=REDIRECT_URI,
refresh=True
)
flask.session['spotify_user_id'] = key
return flask.redirect('/')
@APP.route('/spotify/failed')
def spotify_failed():
flask.session.pop('spotify_user_id', None)
return 'Failed to authenticate with Spotify.'
@APP.route('/')
@APP.route('/index')
def index():
try:
return repr(SPOTIFY_USERS[flask.session['spotify_user_id']])
except KeyError:
return flask.redirect(OAUTH2.url)
if __name__ == '__main__':
APP.run('127.0.0.1', port=8888, debug=False)
```
## Resources
For resources look at the [examples](https://github.com/mental32/spotify.py/tree/master/examples) or ask in the [discord](https://discord.gg/k43FSFF)
%package help
Summary: Development documents and examples for spotify
Provides: python3-spotify-doc
%description help

[](https://github.com/mental32/spotify.py/stargazers)
# spotify.py
An API library for the spotify client and the Spotify Web API written in Python.
Spotify.py is an asyncronous API library for Spotify. While maintaining an
emphasis on being purely asyncronous the library provides syncronous
functionality with the `spotify.sync` module.
```python
import spotify.sync as spotify # Nothing requires async/await now!
```
## Index
- [Installing](#Installing)
- [Examples](#Examples)
- [Resources](#Resources)
## Installing
To install the library simply clone it and run pip.
- `git clone https://github.com/mental32/spotify.py`
- `pip3 install -U .`
or use pypi
- `pip3 install -U spotify` (latest stable)
- `pip3 install -U git+https://github.com/mental32/spotify.py#egg=spotify` (nightly)
## Examples
### Sorting a playlist by popularity
```py
import sys
import getpass
import spotify
async def main():
playlist_uri = input("playlist_uri: ")
client_id = input("client_id: ")
secret = getpass.getpass("application secret: ")
token = getpass.getpass("user token: ")
async with spotify.Client(client_id, secret) as client:
user = await spotify.User.from_token(client, token)
async for playlist in user:
if playlist.uri == playlist_uri:
return await playlist.sort(reverse=True, key=(lambda track: track.popularity))
print('No playlists were found!', file=sys.stderr)
if __name__ == '__main__':
client.loop.run_until_complete(main())
```
### Required oauth scopes for methods
```py
import spotify
from spotify.oauth import get_required_scopes
# In order to call this method sucessfully the "user-modify-playback-state" scope is required.
print(get_required_scopes(spotify.Player.play)) # => ["user-modify-playback-state"]
# Some methods have no oauth scope requirements, so `None` will be returned instead.
print(get_required_scopes(spotify.Playlist.get_tracks)) # => None
```
### Usage with flask
```py
import string
import random
from typing import Tuple, Dict
import flask
import spotify.sync as spotify
SPOTIFY_CLIENT = spotify.Client('SPOTIFY_CLIENT_ID', 'SPOTIFY_CLIENT_SECRET')
APP = flask.Flask(__name__)
APP.config.from_mapping({'spotify_client': SPOTIFY_CLIENT})
REDIRECT_URI: str = 'http://localhost:8888/spotify/callback'
OAUTH2_SCOPES: Tuple[str] = ('user-modify-playback-state', 'user-read-currently-playing', 'user-read-playback-state')
OAUTH2: spotify.OAuth2 = spotify.OAuth2(SPOTIFY_CLIENT.id, REDIRECT_URI, scopes=OAUTH2_SCOPES)
SPOTIFY_USERS: Dict[str, spotify.User] = {}
@APP.route('/spotify/callback')
def spotify_callback():
try:
code = flask.request.args['code']
except KeyError:
return flask.redirect('/spotify/failed')
else:
key = ''.join(random.choice(string.ascii_uppercase) for _ in range(16))
SPOTIFY_USERS[key] = spotify.User.from_code(
SPOTIFY_CLIENT,
code,
redirect_uri=REDIRECT_URI,
refresh=True
)
flask.session['spotify_user_id'] = key
return flask.redirect('/')
@APP.route('/spotify/failed')
def spotify_failed():
flask.session.pop('spotify_user_id', None)
return 'Failed to authenticate with Spotify.'
@APP.route('/')
@APP.route('/index')
def index():
try:
return repr(SPOTIFY_USERS[flask.session['spotify_user_id']])
except KeyError:
return flask.redirect(OAUTH2.url)
if __name__ == '__main__':
APP.run('127.0.0.1', port=8888, debug=False)
```
## Resources
For resources look at the [examples](https://github.com/mental32/spotify.py/tree/master/examples) or ask in the [discord](https://discord.gg/k43FSFF)
%prep
%autosetup -n spotify-0.10.2
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-spotify -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Sun Apr 23 2023 Python_Bot - 0.10.2-1
- Package Spec generated