Skip to content

This Python script automates the process of scraping Billboard's Hot 100 songs for a specified date and creating a private playlist on Spotify

Notifications You must be signed in to change notification settings

Manjunathhs-0003/Spotify-Playlist-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Scraping Billboard and Creating Spotify Playlist

This Python script automates the process of scraping Billboard's Hot 100 songs for a specified date and creating a private playlist on Spotify with those songs. It utilizes web scraping with BeautifulSoup and interacts with the Spotify API using the Spotipy library.

Prerequisites

Python Environment:

  • Python 3.x installed on your system.

Install Required Libraries:

pip install beautifulsoup4 requests spotipy python-dotenv

Spotify Developer Account:

Setup Instructions

1. Obtain Spotify API Credentials

Create a Spotify Application:

  • Log in to your Spotify Developer account and create a new application.
  • Note down the Client ID and Client Secret provided for your application.

Set Redirect URI:

  • In your Spotify application settings, add http://example.com as a Redirect URI.

2. Prepare .env File

Create .env File:

  • Create a file named .env in the same directory as your Python script.
  • Add the following lines to the .env file, replacing placeholders with your actual credentials:
SPOTIFY_APP_CLIENT=your_client_id
SPOTIFY_APP_CLIENT_SECRET=your_client_secret
SPOTIFY_REDIRECT_URL=http://example.com

3. Create token.txt File

  • Create an empty file named token.txt in the same directory as your Python script.

4. Run the Script

Execute the Script:

  • Open a terminal or command prompt.
  • Navigate to the directory containing your Python script and .env file.
  • Run the script using Python:
python main.py

Follow the Script Prompts:

  • Enter the date in the format YYYY-MM-DD when prompted. This date specifies the Billboard Hot 100 chart to scrape.
  • Enter a custom name for the playlist you want to create on Spotify.

Authentication:

  • The script will open a web browser for you to log in to Spotify (if not already authenticated) and authorize the application.
  • This step grants the script permission to create a playlist and add songs to your Spotify account.

How It Works

Web Scraping Billboard:

  • The script uses requests and BeautifulSoup to scrape Billboard's Hot 100 songs page for the specified date.
  • It extracts the song titles from the HTML response.

Spotify Authentication:

  • Authentication with Spotify is handled using spotipy and SpotifyOAuth.
  • The script prompts for Spotify login and authorization via the web browser.
  • It requests necessary permissions (playlist-modify-private and playlist-read-private) to manage playlists on your behalf.

Searching and Adding Songs:

  • For each song title scraped from Billboard, the script searches Spotify for a matching track from the same year.
  • If found, the Spotify URI for the track is collected.

Playlist Creation and Population:

  • After collecting Spotify URIs for all matching tracks, the script prompts for a custom playlist name.
  • It creates a new private playlist on your Spotify account with the specified name and adds the collected songs.

Completion:

  • Upon successful completion, the script confirms the playlist creation and exits.

About

This Python script automates the process of scraping Billboard's Hot 100 songs for a specified date and creating a private playlist on Spotify

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages