# Welcome to the docs

https\://github.com/jbh-cloud/spotify\_sync

### **spotify\_sync**

A schedulable, configurable CLI downloader for Spotify accounts

![](https://1474908792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1R6nUUNu3QJvQC0uY3PZ%2Fuploads%2FGWakMAlKyrK3EfpSdJkM%2Frun_example.gif?alt=media\&token=d51becaa-a0a5-4db7-a976-383fdf99741b)


# Intro

spotify\_sync is a CLI app written in Python that allows you to download songs from your Spotify account. It is designed to be a 'set and forget' tool for users wanting to keep an offline copy of their songs.

This is achieved by linking your Spotify account to a configuration and then running spotify\_sync either manually or on a schedule.

Directly downloading songs from Spotify is currently impossible. To work around this, song metadata is downloaded from Spotify which is then used to match it to a Deezer equivalent. Songs that are successfully matched are then queued for download via the [Deemix Api](https://deemix.app).

Currently, spotify\_sync features include:

* Download of liked songs
* Download of playlist songs
* Up-to lossless quality downloads
* Multi-threaded downloading
* Scheduling (e.g. cron)
* Multi-config support; configure and schedule multiple profiles with separate Spotify accounts
* Backup and restore of config and persistent data
* Runtime notification support via [Pushover](https://pushover.net)
* Automatic Plex library scanning via [Autoscan](https://github.com/Cloudbox/autoscan)


# Quick start

## Prerequisites

* Python >= 3.8 & pip
* Spotify account (free or premium)
* Deezer account (free or premium)

## Install

> python3 -m pip install -U spot\_sync

You should now be able to reference via `spotify_sync`. However if you aren't it's possible you need to add package install directory to your $PATH. E.g. `pip3 show spot-sync | grep Location`

## Configure

Generate a new config

> spotify\_sync config generate

Configure config.json as per [Schema](/configuration/schema)

(Optional) Add config to the profile cache

> spotify\_sync config add myFirstProfile ./config.json

## Run

Allow spotify\_sync to connect to your Spotify account

> spotify\_sync utils authorize-spotify --profile myFirstProfile

{% hint style="info" %}
This will direct you to Spotify to authorize the app you created earlier. After you confirm, the url you are directed to will not 'work'. This is expected, copy the url and paste back into the CLI
{% endhint %}

Start spotify\_sync!&#x20;

> spotify\_sync run auto --profile myFirstProfile

{% hint style="info" %}
Any command that accepts a --profile argument also accepts --config instead:

*spotify\_sync utils authorize-spotify --config /path/to/config.json*
{% endhint %}

{% hint style="warning" %}
If you have a large Spotify library (or are downloading many followed playlists) this first run could take a long time. This is a limit with the Deezer API used to match songs
{% endhint %}

### Other run modes

```
spotify_sync --help

Usage: spotify_sync [OPTIONS] COMMAND [ARGS]...

  spotify_sync
  A schedulable, configurable CLI downloader for Spotify accounts 

Options:
  --help  Show this message and exit.
  
Commands:
  backup   Backup config and persistent data
  config   Access app configurations
  restore  Restore an existing backup
  run      Run spotify_sync in different modes
  stats    Display stats from various sources
  utils    Helper commands
```


# Overview

spotify\_sync requires additional configuration in order to run. Primarily this is used for:

* Binding to your Spotify account
* Additional configuration of what to download from Spotify
* Binding to the Deezer account that will be used to download tracks from
* Specifying where to download songs to
* Specifying the target bit rate of downloaded songs


# Schema

## threads

type: integer

notes: Number of threads to utilize.

{% hint style="info" %}
Setting to -1 will use all available threads
{% endhint %}

## anon\_metrics\_enable

type: bool

notes: If enabled, allows anonymous metrics. This allows capture of which run types and settings are used to understand app usage

## deemix

### arl

**type:** string

**notes:** Cookie[ ](https://pastebin.com/Wn7TaZFB)required for Deezer download functionality.&#x20;

{% hint style="info" %}
See [Getting a Deezer arl](/guides/getting-a-deezer-arl)
{% endhint %}

### download\_path

**type:** string

**notes:** Path that spotify\_sync will download songs into.

### max\_bitrate

**type:** string

**oneOf:** '128', '320', 'lossless'

**notes:** The highest download quality to attempt. '320' & 'lossless' require a Deezer Hi-Fi account.

### skip\_low\_quality

**type:** boolean

**notes:** If true and max\_bitrate > '128', check that the Deezer account has privileges to stream the requested quality. If not, exit before downloads commence.

{% hint style="info" %}
This is especially useful if you rotate Deezer Hi-Fi free trials and don't want to accidentally download 128kbps once your trial has ended.
{% endhint %}

### strict\_matching

**type:** boolean

**notes:** If true, only successfully match a Spotify song to Deezer via it's ISRC. Setting to false allows fallback to Title - Artist - Album search.

## spotify

### username

**type:** string

**notes:** Your Spotify account username.

{% hint style="info" %}
This can be found in your [account overview](https://www.spotify.com/us/account/overview/), it is important it is set correctly
{% endhint %}

### custom\_application/enabled

**type:** boolean

**notes:** Whether to use your own Spotify OAuth2 application instead

{% hint style="info" %}
OAuth2 is currently implemented via PCKE and access tokens stay on your device. However if you'd like to create and use you're own OAuth application you can
{% endhint %}

### **custom\_application/client\_id**

**type:** string

**notes:** Client id of Spotify application.

{% hint style="info" %}
See [Setting up a Spotify oauth application](/guides/setting-up-a-spotify-oauth-application)
{% endhint %}

### **custom\_application/**&#x63;lient\_secret

**type:** string

**notes:** Client secret of Spotify application.

{% hint style="info" %}
See [Setting up a Spotify oauth application](/guides/setting-up-a-spotify-oauth-application)
{% endhint %}

### **custom\_application/**&#x73;cope

**type:** string

**notes:** The scope to use when authenticating to your Spotify account. If unsure, leave as default.

### **custom\_application/**&#x72;edirect\_uri\_port

**type:** string

**notes:** Any usable host port, must match what application has been setup with. If unsure, leave as default.

### playlists/enabled

**type:** boolean

**notes:** Include playlist songs in download

{% hint style="info" %}
Songs in playlists that are already 'liked' :green\_heart: will be downloaded without enabling this feature. Use if you want to include playlist songs that aren't liked
{% endhint %}

### playlists/owner\_only

**type:** boolean

**notes:** Only download playlists you've created yourself, not followed.

### playlists/excluded

**type:** array of strings

**notes:** A list of playlists you wish to be excluded from download (case sensitive).

{% hint style="info" %}
To view all playlists associated with your account run:&#x20;

spotify\_sync stats playlists
{% endhint %}

## pushover

### enabled

**type:** boolean

**notes:** Enable [Pushover ](https://pushover.net/)notifications for run modes.

### user\_key

**type:** string

**notes:** Pushover user key.

### api\_token

**type:** string

**notes:** Pushover token (per Pushover application).

## autoscan

### enabled

**type:** boolean

**notes:** Enable [autoscan ](https://github.com/Cloudbox/autoscan)integration. Assumes you have set this up correctly and created rewrite rules if needed.

### endpoint

**type:** string

**notes:** The API endpoint to POST to.

### auth\_enabled

**type:** boolean

**notes:** Enable basic auth

### username

**type:** string

**notes:** Basic auth username

### password

**type:** string

**notes:** Basic auth password

##

##


# Profiles

Profiles add an additional layer of management for dealing with one or more app configurations. spotify\_sync allows you to cache these configurations in your operating system user cache.

When running spotify\_sync with a profile, persistent data is stored per profile, per Spotify account. This makes it possible to have more than 1 configuration per account.

Currently, you can generate, add,  list and remove config profiles.

#### Add your first profile

* Generate an example to edit. This will output a config.json in the current working directory

```
spotify_sync config generate
```

* Configure your config
* Add your config file to the profile cache

```
spotify_sync config add myFirstProfile ./config.json
```


# Scheduling

Assumes you have successfully Spotify authorized the profile or config you are scheduling.

### Linux

Edit cron

> crontab -e

Run auto mode everyday at 2pm

> 0 14 \* \* \* /usr/bin/python3 -m spotify\_sync run auto --profile MyFirstProfile 2>&1

### Windows (PowerShell)

Get spotify\_sync.exe path

> (Get-Command spotify\_sync).Path

Run auto mode everyday at 2pm

```powershell
$action = New-ScheduledTaskAction -Execute 'PATH_FROM_ABOVE' -Argument 'run auto --profile myFirstProfile'

$trigger =  New-ScheduledTaskTrigger -Daily -At 2pm

Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "spotify_sync" -Description "Download Spotify songs for myFirstPreofile profile" -
```

### MacOS


# Backup and restore

### Backup

Backup state to the current working directory

> spotify\_sync backup local --profile myFirstProfile

Backup state to a custom folder

> spotify\_sync backup local --out-dir /my/existing/folder --profile myFirstProfile

### Restore

> spotify\_sync restore /my/existing/backup.zip

This will attempt to restore to the same profile it was backed up as. You can also override this with the following options

> \--new-profile TEXT New profile name to restore to

> -f, --force Overwrites destination profile or persistent files if they exist


# Migrate from older versions

You can migrate your existing setup to the new version of spotify\_sync.

### Config

This will output a new config.json matching the new schema

> spotify\_sync utils migrate-config --config /path/to/legacy/config.json

### Migrate to profile

If you want to migrate everything into a config profile, use the following:

```
Usage: spotify_sync utils migrate-to-profile [OPTIONS]

  Migrate historical config and cache to a profile

Options:
  Input config object: [mutually_exclusive, required]
  --config PATH                   Path to a separate config file
  --spotify PATH                  Path to a Spotify song json file to migrate
                                  [required]
  --processed PATH                Path to a processed song json file to
                                  migrate  [required]
  --profile TEXT                  Name of a (non existent) profile to migrate
                                  settings to  [required]
  --config-schema-mode [legacy|latest]
                                  Specify schema of config file  [default:
                                  legacy]
  --help                          Show this message and exit.
```


# FAQ

### I've upgraded spotify\_sync since PCKE auth was introduced, how can I switch to that?

Go into your configuration and set `custom_application/enabled` to `false`. Run `spotify_sync utils authorize-spotify --force` and you're good to go.

### I receive \`ModuleNotFoundError: No module named 'pkg\_resources'\` when running spotify\_sync

Ensure setuptools is installed `pip3 install setuptools`


# Getting a Deezer arl

1. Login to your Deezer account
2. Open Chrome developer tools (Windows  "Ctrl + Shift + i" or MacOS "Command + Option + i")
3. Navigate to Deezer cookies and copy value named "arl"

&#x20;

![](https://1474908792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1R6nUUNu3QJvQC0uY3PZ%2Fuploads%2FFGyTJQbm97IcTiebyGag%2Farl.png?alt=media\&token=ed057c67-668f-4dde-bb5f-c1e00fa2cde7)

{% hint style="info" %}
Process will be similar for other browsers
{% endhint %}


# Setting up a Spotify oauth application

1. Login to [Spotify developer portal](https://developer.spotify.com/dashboard/) using your Spotify account credentials
2. Select **Create an app**
3. Pick an app name and description, suggest using **spotify\_sync** as the name, click **Create**
4. Select **Edit settings**, nagivate to **Redirect URIs** and enter **`http://127.0.0.1:9090`** and click **Add**
   * If you have changed the default [Schema](/configuration/schema#redirect_uri_port) this will need to match what you have configured
5. Click **Save**&#x20;
6. Click **Show client secret**

You are now able to see your [Schema](/configuration/schema#client_id) and [Schema](/configuration/schema#client_secret)


