This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi!
I'm new to Python scripts, but I made this . It's a script that should get the metadata from a you_tube playlist and create a playlist on spotify and add the same songs there. The problem is, I'm a little paranoid :)
I want to use this for myself and some friends, but I am a little afraid that it might violate spotify's developer terms and conditions. Is there something I should know before running it?
The script:
"
import google_auth_oauthlib.flow
import googleapiclient.discovery
import spotipy
from spotipy.oauth2 import SpotifyOAuth
# Set up YouTube API
def get_authenticated_youtube_service(api_service_name, api_version, scopes):
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
'client_secrets.json', scopes)
credentials = flow.run_local_server(port=0)
youtube_service = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
return youtube_service
# Set up Spotify API
def get_authenticated_spotify_client():
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
scope="playlist-modify-private playlist-modify-public",
redirect_uri="http://localhost:8888/callback",
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
show_dialog=True,
cache_path="token.txt"
)
)
return sp
def main():
# Get user input for YouTube Playlist ID
youtube_playlist_id = input("Enter the YouTube Playlist ID: ")
# Get user input for Spotify Playlist ID
spotify_playlist_id = input("Enter your Spotify Playlist ID: ")
# Set up YouTube API
youtube_service = get_authenticated_youtube_service(
'youtube', 'v3', ['https://www.googleapis.com/auth/youtube.readonly'])
# Set up Spotify API
spotify_client = get_authenticated_spotify_client()
next_page_token = None
while True:
request = youtube_service.playlistItems().list(
playlistId=youtube_playlist_id,
part='snippet',
maxResults=50,
pageToken=next_page_token
)
response = request.execute()
# Loop through YouTube playlist items
for item in response.get('items', []):
song_title = item['snippet']['title']
# Search for the song on Spotify
results = spotify_client.search(q=song_title, type='track', limit=1)
# Check if a matching track is found
if results['tracks']['items']:
track_uri = results['tracks']['items'][0]['uri']
# Add the track to your Spotify playlist
spotify_client.playlist_add_items(spotify_playlist_id, [track_uri])
print(f"Added {song_title} to Spotify playlist")
# Check if there are more pages
next_page_token = response.get('nextPageToken')
if not next_page_token:
break
if __name__ == '__main__':
main()
"
Subreddit
Post Details
- Posted
- 11 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/programming...