mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-02 13:42:40 +00:00
Packaging tweaks
This commit is contained in:
parent
95e2d354e1
commit
4da11677c5
2
CHANGES.txt
Normal file
2
CHANGES.txt
Normal file
@ -0,0 +1,2 @@
|
||||
v<version>, <date> -- Initial release.
|
||||
|
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Paul Lamere
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
2
MANIFEST.in
Normal file
2
MANIFEST.in
Normal file
@ -0,0 +1,2 @@
|
||||
include *.txt
|
||||
recursive-include docs *.txt
|
29
examples/create_playlist.py
Normal file
29
examples/create_playlist.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Creates a playlist for a user
|
||||
|
||||
import pprint
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import spotipy
|
||||
|
||||
import util
|
||||
import spotipy.oauth2 as oauth2
|
||||
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
username = sys.argv[1]
|
||||
playlist_name = sys.argv[2]
|
||||
else:
|
||||
print "Usage: %s username playlist-name" % (sys.argv[0],)
|
||||
sys.exit()
|
||||
|
||||
token = util.prompt_for_user_token(username)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
playlists = sp.user_playlist_create(username, playlist_name)
|
||||
pprint.pprint(playlists)
|
||||
else:
|
||||
print "Can't get token for", username
|
7
setup.py
7
setup.py
@ -2,11 +2,12 @@ from setuptools import setup
|
||||
|
||||
|
||||
setup(
|
||||
name='spotipy',
|
||||
version='1.100',
|
||||
name='SpotiPy',
|
||||
version='1.200',
|
||||
description='simple client for the Spotify Web API',
|
||||
author="@plamere",
|
||||
author_email="paul@echonest.com",
|
||||
url='http://github.com/plamere/spotipy',
|
||||
install_requires=['requests>=1.0', ],
|
||||
py_modules=['spotipy', 'spotify_oauth2'],)
|
||||
license='LICENSE.txt',
|
||||
py_modules=['spotipy', 'spotipy.oauth2'],)
|
||||
|
@ -4,6 +4,7 @@ from __future__ import print_function
|
||||
|
||||
import base64
|
||||
import requests
|
||||
import simplejson as json
|
||||
|
||||
__all__ = ['oauth2']
|
||||
|
||||
@ -76,6 +77,31 @@ class Spotify(object):
|
||||
kwargs.update(args)
|
||||
return self._internal_call('GET', method, kwargs)
|
||||
|
||||
def post(self, method, payload=None, **kwargs):
|
||||
args = dict(params=kwargs)
|
||||
if not method.startswith('http'):
|
||||
url = self.prefix + method
|
||||
else:
|
||||
url = method
|
||||
headers = self._auth_headers()
|
||||
headers['Content-Type'] = 'application/json'
|
||||
print('headers', headers)
|
||||
if payload:
|
||||
r = requests.post(url, headers=headers, data=json.dumps(payload), **args)
|
||||
else:
|
||||
r = requests.post(url, headers=headers, **args)
|
||||
if self.trace:
|
||||
print()
|
||||
print("POST", r.url)
|
||||
print("DATA", json.dumps(payload))
|
||||
if r.status_code != 200:
|
||||
raise SpotifyException(r.status_code, -1, u'the requested resource could not be found: ' + r.url)
|
||||
results = r.json()
|
||||
if self.trace:
|
||||
print('RESP', results)
|
||||
print()
|
||||
return results
|
||||
|
||||
def next(self, result):
|
||||
''' returns the next result given a result
|
||||
'''
|
||||
@ -178,6 +204,22 @@ class Spotify(object):
|
||||
''' Gets playlist of a user
|
||||
'''
|
||||
return self.get("users/%s/playlists/%s" % (user, playlist_id), fields=fields)
|
||||
|
||||
def user_playlist_create(self, user, name, public=True):
|
||||
''' Creates a playlist for a user
|
||||
'''
|
||||
data = {'name':name, 'public':True }
|
||||
return self.post("users/%s/playlists" % (user,), payload = data)
|
||||
|
||||
def user_playlist_add_tracks(self, user, playlist_id, uris, position=None):
|
||||
''' Adds tracks to a playlist
|
||||
'''
|
||||
data = {'uris':uris}
|
||||
uri_param = ','.join(uris)
|
||||
#return self.post("users/%s/playlists/%s/tracks" % (user,playlist_id), payload = data)
|
||||
#return self.post("users/%s/playlists/%s/tracks" % (user,playlist_id), payload = data, position=position)
|
||||
#return self.post("users/%s/playlists/%s/tracks" % (user,playlist_id), uris=uri_param, position=position)
|
||||
return self.post("users/%s/playlists/%s/tracks" % (user,playlist_id), uris=uri_param)
|
||||
|
||||
def me(self):
|
||||
''' returns info about me
|
||||
|
Loading…
Reference in New Issue
Block a user