auth
), services (services
), utilities (utils
), and tests (tests
). The main.py
file serves as the entry point of the application. The services
directory contains modules for interacting with the Spotify and YouTube APIs, while the auth
directory handles authentication for both APIs. The utils
directory provides helper functions for common tasks such as normalizing titles and managing playlist IDs.spotify_services.py
: This module fetches track data from a Spotify playlist using the Spotify API. It contains functions to get the access token for authentication and retrieve the tracks of a given playlist. The spotify_track_lister()
function returns a list of tuples containing song and artist pairs.youtube_services.py
: This module interacts with the YouTube API to search for videos, add songs to a playlist, and remove duplicates. It includes functions like remove_duplicates()
to remove duplicate songs from a playlist, song_adder()
to add songs to a playlist based on the spotify_track_lister data, and search_song()
to search for a YouTube video using song and artist names.spotify_auth.py
and youtube_auth.py
: These modules handle authentication for the Spotify and YouTube APIs, respectively. They manage access tokens and credentials required for making API requests.playlist_utils.py
: This module contains utility functions for extracting playlist IDs from URLs and normalizing song titles by removing keywords and punctuation.spotify_track_lister(my_playlist_id)
:
my_playlist_id
(str): The ID of the Spotify playlist to fetch tracks from.song_adder(youtube, playlist_id, tracks)
:
youtube
(googleapiclient.discovery.Resource): The authenticated YouTube API client.playlist_id
(str): The ID of the YouTube playlist to add songs to.tracks
(list): A list of tuples containing song and artist pairs.search_song(youtube, song_name, artist)
:
youtube
(googleapiclient.discovery.Resource): The authenticated YouTube API client.song_name
(str): The name of the song to search for on YouTube.artist
(str): The artist of the song to search for on YouTube.my_playlist_id
parameter in spotify_track_lister()
allows fetching tracks from different Spotify playlists.playlist_id
parameter in song_adder()
enables adding songs to different YouTube playlists.Step-by-Step Guide:
.env
file with the required information (Spotify client ID and secret, YouTube client secrets).main.py
script to start the application.Commented Examples:
# Example usage of spotify_track_lister()
spotify_tracks = spotify_track_lister(spotify_playlist_id)
print(spotify_tracks)# Output: [('Song 1', 'Artist 1'), ('Song 2', 'Artist 2'), ...]# Example usage of song_adder()
song_adder(youtube, youtube_playlist_id, spotify_tracks)
.env
file.cron
or Celery to automatically sync playlists at regular intervals.dotenv
(already used in the project) helps keep sensitive information like API keys and secrets secure and separate from the codebase.