Code Monkey home page Code Monkey logo

spotify-api-project's Introduction

Spotify Song Data

This repository contains a Python script that uses the Spotipy library to interact with the Spotify Web API. The script retrieves information about an artist's top tracks and stores it in a SQLite database.

Prerequisites

Before running the script, you'll need to have the following installed:

  • Python 3: The script is written in Python 3 and requires it to be installed on your system.
  • Spotipy: This is a Python library for the Spotify Web API. It provides a simple interface for interacting with the API and retrieving data.
  • pycountry: This is a Python library that provides ISO country, subdivision, language, currency and script definitions and their translations.

You'll also need to set up a Spotify Developer account and register an application to obtain a client_id and client_secret. These values should be set as environment variables named SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET, respectively.

Installation

To install the required libraries, you can use pip by running the following command:

pip install spotipy pycountry

Usage

To run the script, navigate to the directory containing the script and run the following command:

python3 spotify_api.py

Replace spotify_api.py with the name of the script file.

The script will prompt you to enter the name of an artist. After entering the artist's name, the script will search for the artist on Spotify and retrieve their top tracks. The track information will be stored in a SQLite database named song_data.db.

The database contains a table named songs with columns for various track attributes such as artist_name, track_name, danceability, energy, etc. The script will insert data into this table for each of the artist's top tracks.

Here's a brief explanation of what each part of the code does:

  1. The first few lines of the code import the necessary libraries: os, sqlite3, spotipy, SpotifyClientCredentials from spotipy.oauth2, and pycountry.
  2. The next few lines set up the client credentials for accessing the Spotify Web API using the SpotifyClientCredentials class from the spotipy.oauth2 module. The client_id and client_secret are retrieved from environment variables and passed to the SpotifyClientCredentials constructor. A spotipy.Spotify object is then created using the client_credentials_manager parameter.
  3. The database name is set to "song_data.db".
  4. The code checks if the database file exists. If it doesn't, a new SQLite database file is created and a table named songs is created in the database with columns for various track attributes.
  5. A connection to the database is established and a cursor object is created.
  6. The user is prompted to enter the name of an artist.
  7. The code searches for the artist on Spotify using the search method of the spotipy.Spotify object and retrieves the artist's Spotify ID.
  8. The code retrieves information about the artist's albums and top tracks using various methods of the spotipy.Spotify object such as artist_albums, album, and artist_top_tracks.
  9. For each of the artist's top tracks, the code retrieves audio features and popularity information using methods such as audio_features and track.
  10. The track information is inserted into the songs table in the database if it doesn't already exist.
  11. The track name and audio features are printed to the console.
  12. Finally, the database connection is closed.

Contributing

Contributions are welcome! If you have any ideas for new features or improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

spotify-api-project's People

Contributors

migotron avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.