Automatically scrobble your favorite radio tracks from to

Similar projects worth following
Non commercial radio stations use Spinitron to publish their live playlists, and I wanted to be able to scrobble those songs to my account. Now I can, thanks to an afternoon with ChatGPT, who helped me build this little web app that provides a convenient way for anyone to automatically log their favorite radio station's tracks to their account.
  • Writing

    Mx. Jack Nelson04/26/2023 at 16:14 0 comments

    The app is a Python script written by my lovely wife, Steph. She has kindly donated this script to my project, as getting the Session Key is the most complicated step of the entire process - now simplified. The script's purpose is to generate a session key for the API, authorize the app to access the user's profile, and then use the session key to scrobble a specific song to the user's account to check that it is working.

    Note: The script contains placeholders for the user's API key (`YOUR_API_KEY`) and API secret (`YOUR_API_SECRET`), which need to be replaced with the user's actual values before running the script. Sign up for a API account to acquire your API key and API shared secret.

    Here's a summary of the script's main steps:

    1. The script defines various constants and variables, including the API endpoints, the user's API key and secret, and other configuration options.

    2. The script generates an API signature (`API_TK_SIG`) using the user's API key and secret, and then sends an HTTP GET request to the API to obtain a temporary token (`TOKEN`) using the `auth.getToken` method.

    3. The user is prompted to visit a URL to authorize the app to access their profile. After the user grants access, they are instructed to press any key to continue.

    4. The script generates another API signature (`API_SES_SIG`) using the temporary token, and then sends another HTTP GET request to the API to obtain a permanent session key (`SESSION_KEY`) using the `auth.getSession` method.

    5. The script prints the session key to the console.

    6. The script prepares to scrobble the song "Never Gonna Give You Up" by Rick Astley. It generates a timestamp (`TS`) and an API signature (`API_SIG`) using the session key, artist name, track name, and other parameters.

    7. The script sends an HTTP POST request to the API to scrobble the song using the `track.scrobble` method. The request includes the necessary data, such as the API key, API signature, artist name, track name, session key, and timestamp.

    8. The script prints the XML response from the API to the console.

  • Writing styles.css

    Mx. Jack Nelson04/26/2023 at 06:13 0 comments

    This CSS code styles a webpage with a white background, a container with a maximum width of 600px, a box-shadow effect, and padding. It also centers headings and has styles for messages and links. The code also includes styles for input fields and buttons, including a hover effect for buttons. The container also has a "Go back" button styled, which gets bigger on hovering. The button-container is designed to live within the container and is displayed as a flex element.

  • Writing submit.html

    Mx. Jack Nelson04/24/2023 at 23:06 0 comments

    The SpinLast web page submit.html displays the latest track scrobbled from the submitted Spinitron radio station to a user's account. The label informs users that "This field will update automatically as you listen." The page features a heading, a label, a message area, and a "Go back" link. The message area shows the latest scrobbled song and artist or indicates if no song has been scrobbled. The "Go back" link redirects users to the main page to enter a new Spinitron URL. Additionally, JavaScript code periodically updates the message area with the latest scrobbled song by making AJAX requests to the "/latest_scrobble" route. The page has the same clean design with a centered container and a light background.

  • Writing index.html

    Mx. Jack Nelson04/24/2023 at 22:47 0 comments

    Upon opening the index.html page, users are greeted with a centered heading that reads "SpinLast" and a subheading reading "The Spinitron Scrobbler.": Below the heading, there is a form that prompts users to enter the URL of their desired Spinitron radio station. The form consists of a label, an input text field, and a submit button.

    The label instructs users to "Enter Spinitron Radio Station URL," and the input text field is where users can type or paste the URL. The input field is styled to be 100% wide, with padding and rounded corners for a pleasant visual appearance. The submit button is styled with a blue background and white text, and it changes to a darker shade of blue when hovered over.

    Once users enter the URL and click the "Submit" button, the form sends a POST request to the "/submit" endpoint, triggering the scrobbling process.

    The overall design of the page is clean and straightforward, with a light background and a centered container that holds the form. The container has a white background and a subtle box shadow for a modern look. The font used is Arial, and the page is responsive, thanks to the "viewport" meta tag.

  • Creating a Python script

    Mx. Jack Nelson04/24/2023 at 22:43 0 comments

    This Python script is designed to automatically scrobble the tracks played on a Spinitron radio station to a user's account. It uses the Flask web framework to create a simple web application that allows users to input the URL of a Spinitron radio station. The script then periodically checks the Spinitron page for the currently playing track and scrobbles it to if it's a new track.

    Here's how the script works:

    1. The script starts by importing the necessary libraries, including threading, time, schedule, pylast, requests, BeautifulSoup, and Flask.
    2. The user's API credentials (API key, API secret, and session key) are defined, and a API client (network) is set up using the pylast library.
    3. The Flask web application is created with the app variable.
    4. Two global variables, last_scrobbled_track and spinitron_url, are defined to keep track of the most recently scrobbled track and the URL of the Spinitron radio station, respectively.
    5. An event object (stop_event) is created to control the scheduler thread.
    6. The run_scheduler function is defined to run the scheduled tasks in a separate thread. It uses the stop_event to stop the scheduler thread when needed.
    7. The scrobble_new_track function is defined to check the Spinitron page for the currently playing track. It fetches the HTML content of the Spinitron page, extracts the track information (artist, song, and release), and compares it to the last scrobbled track. If the current track is different, it scrobbles the track to using the network.scrobble method.
    8. The index route renders the HTML page with a form for users to input the Spinitron URL.
    9. The submit route is triggered when the user submits the form. It extracts the Spinitron URL from the form data, performs an initial scrobble, and returns a message indicating the result.
    10. The latest_scrobble route returns the most recently scrobbled track in JSON format.
    11. The scrobble_new_track function is scheduled to run every minute using the schedule library.
    12. The scheduler thread is started, and the Flask web application is launched.
    13. If the Flask application is terminated (e.g., by pressing Ctrl+C), the scheduler thread is signaled to stop, and the script gracefully shuts down.

View all 5 project logs

  • 1
    Structure your directory

    Set up a directory structure on your local computer that looks like this:

    └── static/
        ├── styles.css
    └── templates/
        ├── index.html
        └── submit.html

  • 2
    Get a API account

    Sign up for a API account and record your API Key and Shared Secret somewhere safe.

  • 3

    Edit the file to include your API Key and Shared Secret.

View all 7 instructions

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates