# check_playlists.py

A Python script that bulk-checks the availability of Spotify playlists using the Spotify Web API, with concurrent requests for speed.

## Features

- Checks hundreds of Spotify playlists in parallel (20 workers)
- Handles various ID formats: plain IDs, `spotify:playlist:` URIs, and full share URLs with query parameters
- Outputs results to a CSV file (`playlist_status.csv`)
- Prints a summary of available, unavailable, and errored playlists

## Prerequisites

- Python 3.7+
- `requests` library

```bash
pip install requests
```

## Setup

### 1. Generate a Spotify API Token

You need a Spotify Web API **Client ID** and **Client Secret** from the [Spotify Developer Dashboard](https://developer.spotify.com/dashboard).

```bash
curl -X POST "https://accounts.spotify.com/api/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>"
```

Example response:
```json
{"access_token":"<SPOTIFY_API_TOKEN>","token_type":"Bearer","expires_in":3600}
```

> **Note:** Tokens expire after 1 hour (`expires_in: 3600`).

### 2. Set the Token

Replace the placeholder in the script:

```python
TOKEN = "<SPOTIFY_API_TOKEN>"
```

## Usage

```bash
python check_playlists.py
```

The script reads playlist IDs from the `PLAYLIST_IDS` string in the script, checks each one against the Spotify API, and writes results to `playlist_status.csv`.

### Adding Playlists

Add playlist IDs (one per line) to the `PLAYLIST_IDS` multiline string in the script. The following formats are supported:

| Format | Example |
|---|---|
| Plain ID | `37i9dQZF1DWSOb6VfKLO9H` |
| Spotify URI | `spotify:playlist:7DzuEBHtwgSasrgVgTa3Eh` |
| Share URL with query params | `37i9dQZF1DX9pryhDLql25?si=abc123&nd=1` |

## Output

Results are saved to `playlist_status.csv`:

| PlaylistID | Status |
|---|---|
| `37i9dQZF1DWSOb6VfKLO9H` | `AVAILABLE` |
| `0000000000000000000000` | `NOT_AVAILABLE` |
| `invalidid` | `STATUS_400` |

**Status values:**
- `AVAILABLE` — playlist exists and is accessible
- `NOT_AVAILABLE` — playlist not found (HTTP 404)
- `STATUS_<code>` — unexpected HTTP response code
- `INVALID` — ID was empty after cleaning
- `ERROR_<message>` — network or other exception

A summary is also printed to the console:

```
Done! Results saved to playlist_status.csv
  AVAILABLE:     312
  NOT_AVAILABLE: 47
  OTHER:         5
```
