# Localify

> A Python-powered CLI that turns public Spotify playlists into local MP3 collections using browser automation, YouTube search, and intelligent track matching — no Spotify API key or Premium subscription required.

Case study: https://sushandahal.com.np/work/localify

Author: Sushan Dahal

Role: Solo Developer

Status: Open Source — Local Utility

Technologies: Python, Playwright, yt-dlp, FFmpeg, Chromium, Deno

## Problem

Spotify playlists are convenient for organizing music, but accessing those collections as local audio files is not straightforward. Localify explores an automated workflow for extracting public playlist metadata and finding corresponding audio on YouTube, without requiring Spotify API credentials.

## Contribution

Developed a Python-based command-line utility that automates playlist extraction, track matching, and local audio downloads. Implemented headless browser scraping, lazy-loaded content handling, duration-based matching, MP3 conversion, and error-tolerant batch processing.

## Approach

- Used Playwright with headless Chromium to navigate public Spotify playlist pages.
- Implemented automated scrolling to extract tracks from dynamically loaded playlists.
- Collected track titles, artists, albums, and durations without using the Spotify API.
- Integrated yt-dlp to search YouTube for corresponding audio.
- Compared Spotify and YouTube track durations to improve match accuracy.
- Used FFmpeg to extract and convert matched audio into MP3 files.
- Organized downloaded files using playlist position, artist, and song title.
- Added error handling to skip unmatched tracks and continue processing when individual downloads fail.
- Introduced randomized delays between downloads to reduce request frequency.

## Decision

Chose browser automation instead of Spotify's official API to experiment with extracting publicly available metadata directly from dynamic web pages. Used duration-based matching as a lightweight heuristic rather than introducing complex audio fingerprinting or external recognition services.

## Tradeoff

Scraping depends on Spotify's page structure and may break when the interface changes. Duration-based matching is efficient but cannot always distinguish original recordings from remixes, covers, or live performances. YouTube availability, rate limits, and external tooling also affect reliability.

## Outcome

Built a locally runnable CLI that accepts a public Spotify playlist URL, extracts its tracks, searches for matching YouTube audio, and saves successful downloads as organized MP3 files. Published the source code and setup instructions on GitHub for local experimentation.

## Lessons

Learned how to automate dynamic websites, handle lazy-loaded content, integrate command-line tools, and build resilient multi-stage data pipelines. The project reinforced the importance of validating scraped data, handling partial failures, and understanding the limitations of heuristic matching.

Interface illustrations on the case-study page explain the concept; they are not project screenshots.

Source: https://github.com/Sushan2589/Localify
