Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
collaborative = None
if len(sys.argv) > 5:
collaborative = sys.argv[5].lower() == 'true'
description = None
if len(sys.argv) > 6:
description = sys.argv[6]
else:
print ("Usage: %s username playlist_id name [public collaborative "
"description]" % (sys.argv[0]))
sys.exit()
scope = 'playlist-modify-public playlist-modify-private'
token = util.prompt_for_user_token(username, scope)
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
results = sp.user_playlist_change_details(
username, playlist_id, name=name, public=public,
collaborative=collaborative, description=description)
print results
else:
print "Can't get token for", username
import pprint
import sys
import spotipy
import spotipy.util as util
if len(sys.argv) > 3:
username = sys.argv[1]
playlist_id = sys.argv[2]
track_ids = sys.argv[3:]
else:
print("Usage: %s username playlist_id track_id ..." % (sys.argv[0],))
sys.exit()
scope = 'playlist-modify-public'
token = util.prompt_for_user_token(username, scope)
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
results = sp.user_playlist_replace_tracks(username, playlist_id, track_ids)
pprint.pprint(results)
else:
print("Can't get token for", username)
def main():
# All reddit api info
reddit = praw.Reddit('bot')
reddit = praw.Reddit(client_id=os.environ['REDDIT_CLIENT_ID'],
client_secret=os.environ['REDDIT_CLIENT_SECRET'],
password='',
user_agent='Reddit Music Bot 0.1',
username='')
subreddit = reddit.subreddit(os.environ['SUBREDDIT'])
# All spotify api info
scope = 'playlist-modify-public'
username = os.environ['SPOTIFY_USERNAME']
spotify_client_id = os.environ['SPOTIFY_CLIENT_ID']
spotify_client_secret = os.environ['SPOTIFY_CLIENT_SECRET']
token = util.prompt_for_user_token(username, scope,
client_id=spotify_client_id,
client_secret=spotify_client_secret,
redirect_uri='http://localhost/')
spotify = spotipy.Spotify(auth=token)
top_month_id = os.environ['SPOTIFY_MONTHLY_ID']
top_all_id = os.environ['SPOTIFY_ALL_ID']
month_upvote_treshold = int(os.environ['MONTH_UPVOTE_THRESHOLD'])
all_upvote_treshold = int(os.environ['ALL_UPVOTE_THRESHOLD'])
#Main App Loop
while True:
titles = []
for submission in subreddit.top('month', limit=None):
if (submission.media is not None
and valid_artist_and_song(submission.title,
submission.media)
# shows a user's starred playlist
import sys
import spotipy
import spotipy.util as util
if len(sys.argv) > 1:
username = sys.argv[1]
else:
print("Whoops, need your username!")
print("usage: python user_playlists.py [username]")
sys.exit()
token = util.prompt_for_user_token(username)
if token:
sp = spotipy.Spotify(auth=token)
results = sp.user_playlist(username)
tracks = results['tracks']
which = 1
while tracks:
for item in tracks['items']:
track = item['track']
print(which, track['name' ], ' --', track['artists'][0]['name'])
which += 1
tracks = sp.next(tracks)
else:
print("Can't get token for", username)
result = filter_title.sub('', song_title).strip()
for m in re.finditer(r'\([^()]+\)', result):
if not re.search(keep_words, m.group(), re.I):
result = re.sub(re.escape(m.group()), '', result)
filter_strings = re.sub(string_regex, '', result).strip()
result = ' '.join(filter_strings.split())
new_list = list(filter(None, re.split(split, result)))
first = new_list[0]
sep = 'aka'
sep2 = 'AKA'
new_list[0] = first.split(sep, 1)[0]
new_list[0] = first.split(sep2, 1)[0]
spotify_token = util.prompt_for_user_token(Config.USERNAME, Config.SCOPE)
if spotify_token:
spotify = spotipy.Spotify(auth=spotify_token)
artist = new_list[0]
track = new_list[1]
results = spotify.search(q="artist:{} track:{}".format(artist, track, limit=1))
if results:
spot_tracks = results['tracks']['items']
if spot_tracks:
spot_artist = spot_tracks[0]['artists'][0]['name']
spot_title = spot_tracks[0]['name']
spot_url = spot_tracks[0]['external_urls']['spotify']
update.effective_message.reply_text \
("► {0} - {1} \n{2}".format(spot_artist, spot_title, spot_url), disable_web_page_preview=True)
def login_to_spotify(self):
token = spotipy.util.prompt_for_user_token(self.username, scope='playlist-modify-public')
if token:
return spotipy.Spotify(auth=token)
else:
return spotipy.Spotify()
def connect_to_spotify():
token = spotipy.util.prompt_for_user_token(USERNAME,
scope = 'user-library-modify',
client_id = CLIENT_ID,
client_secret = CLIENT_SECRET,
redirect_uri = REDIRECT_URI)
return spotipy.Spotify(auth=token)
def akttym():
SCOPE = 'user-library-modify,user-read-playback-state'
dir_path = os.path.dirname(os.path.realpath(__file__))
config = yaml.safe_load(open(dir_path + '/config.yaml'))
check_config(config, dir_path)
token = util.prompt_for_user_token(
config['username'],
SCOPE,
client_id=config['client_id'],
client_secret=config['client_secret'],
redirect_uri='http://localhost:1911/',
cache_path=dir_path + '/cache'
)
if token:
sp = Spotify(auth=token)
track = sp.current_playback()
if track is not None:
sp.current_user_saved_tracks_add([track['item']['id']])
logging.warning("added %s to %s's library", track['item']['name'], config['username'])
else:
logging.warning("nothing is playing currently, aborting")
def login(username) -> str:
return util.prompt_for_user_token(
username,
scope,
client_id= os.getenv("SPOTIPY_CLIENT_ID") or "47085e9bfd4c40b986d599a311a1f6be",
client_secret= os.getenv("SPOTIPY_CLIENT_SECRET") or "d9efc8f758e5449bb7516e6f2f90e1e5",
redirect_uri= os.getenv("SPOTIPY_REDIRECT_URI") or "http://localhost:8888/callback",
)
def get_new_token(self):
token = spotipy.util.prompt_for_user_token(
self.spotify_username,
client_id=self.spotify_client_id,
client_secret=self.spotify_client_secret,
scope="playlist-read-private user-library-read"
)
return token