Skip to main content

Tomato Timer with Spotify

Project description

Spomato

Welcome!

This project is intended to be a way to generate playlists through the Spotify API. The main purpose was to create a Tomato Timer length playlist in Spotify (Spotify + Tomato = Spomato).

Installation

You can install via pypi:

pip install spomato

You can pip install it straight from git:

pip install git+git://github.com/pm8k/spomato.git

Spotify Access Token

You need to have a Spotify Access token in order to access the Spotify API. The API scopes used by this library are playlist-read-private, playlist-modify-private, and user-library-read.

You can find the Spotify Authorization flow here and you can find the Spotipy implementation here.

Using Spomato

Create a Spomato object with a Spotify Access Token:

Create a Spomato object providing your token.

from spomato import spomato
sp = spomato.Spomato(access_token='your-token')

Creating a Dataset

The first step is to create one or more datasets to use as a source for your playlist.

Creating a Dataset from Your Saved Tracks

You can use the user's saved tracks as your dataset. This is the default, or you can specify it as below:

sp.get_api_data(data_key='your_dataset_name',
                source={'savedtracks':None})

Creating a Dataset from Your Playlist(s)

You can use the user's playlist(s) as your dataset.

sp.get_api_data(data_key='your_dataset_name',
                source={'playlist':['playlistid1','playlistid2']})

Creating a Dataset from an Artist

You can use any number of artists to create your dataset.

sp.get_api_data(data_key='your_dataset_name',
                source={'artist':['artistid1','artistid2']})

Creating a Dataset from Multiple Sources

You can use any of the above sources to create a dataset.

sp.get_api_data(data_key='your_dataset_name',
                source={'artist':['artistid1','artistid2'], 'playlist':['playlistid4', 'savedtracks':None]})

Additional Arguments

There are a few more arguments you can pass to generate a dataset:

  • file_path: If you want to save the dataset to file, pass in a path to a file to save a csv of your dataset
  • reset: A boolean to determine if you want to overwrite a dataset you've previously created
  • market: The Spotify market to filter the songs that can be added to a playlist

Read the Dataset from File

If you saved the file, you can also use that to load it back into a dataset:

sp.get_file_data(data_key='default',
                 file_path='/my/path/data.csv',
                 overwrite=False)

Searching Data

You can find an artist or playlist id you're looking for with a couple builtin functions.

 playlist_df = sp.get_playlists()

The get_playlists() function returns all of your playlists by name and id.

artist_search_df = sp.artist_id_search(artist='Foo Fighters')

The artist_id_search function will search a given string for artists of that name, returning DataFrame of artists and their ids.

You can alternatively go through Spotify and find the corresponding id in the web url when you click on the corresponding playlist or artist.

Creating a Playlist

Get the Song List to Create a playlist

You can use our built in function to select tracks from a dataset to make your playlist.

my_song_df = sp.pick_tracks(data_key='my_dataset', time=25, extra=5)

This example will create a playlist between 25 and 30 minutes. It selects tracks until the total time is greater than or equal to the time argument in minutes but not that it exceeds time + extra (also in minutes). You can also specify a maximum song length with the time_limit argument (the default is one-third of time).

You can also generate you own dataframe using your own logic. You can access a dataset by:

dataset_df = sp['data']['my_dataset']

Create the Playlist

Once you have the dataframe of your songs generated, you can create the playlist.

sp.make_playlist(playlist_name='New_Playlist_Name', song_df=my_song_df)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spomato-0.2.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

spomato-0.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file spomato-0.2.0.tar.gz.

File metadata

  • Download URL: spomato-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for spomato-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d8256e4c4891391db886571bf5ce3e341e6faee8162782f0eb5a5dc17b8471f6
MD5 e508a519424f0930714bc5adf07029e1
BLAKE2b-256 d1b6d7069e819034a7b70c93dca303c5bf6717a42fbba9004dcc99ecefd64743

See more details on using hashes here.

File details

Details for the file spomato-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: spomato-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for spomato-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f8fe42d2e54994f4e9087d2372dab0d97d7a1a27ea0313bf9ac38d064f73101
MD5 372dc095f4260889bfbafd23208ae336
BLAKE2b-256 808a09707090c7051e195b722ba144379a75425e9d0d535200837767f4f8b310

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page