Skip to main content

A Python library for scraping FM radio station data from fmstream.org

Project description

FMStream Library

A Python library for scraping FM radio station data from fmstream.org with REST API support.

Features

  • Extract FM radio station information (title, location, frequency, etc.)
  • Parse audio stream URLs from JavaScript data
  • Intelligent matching of stations with their corresponding streams
  • Clean, structured data models using dataclasses
  • Type hints for better code documentation
  • FastAPI REST API with filtering and search capabilities
  • Compatible with fmstream.org API parameters

Installation

pip install fmstream

For API server support:

pip install fmstream[api]

Quick Start

Python Library Usage

from fmstream import FMStreamScraper

# Scrape radio station data from a fmstream.org URL
url = "https://fmstream.org/index.php?s=vietnam"
scraper = FMStreamScraper()
stations = scraper.scrape_stations(url)

# Access station information
for station in stations:
    print(f"Station: {station.title}")
    print(f"Location: {station.location}")
    print(f"Frequency: {station.frequency}")
    print(f"Streams: {len(station.streams)}")
    
    # Access audio streams
    for stream in station.streams:
        print(f"  - {stream.title}: {stream.url}")

REST API Usage

Start the API server:

import uvicorn
from fmstream import fastapi_app

uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)

Or use the example script:

python examples/api_server.py

Access the API:

# Get all stations
curl "http://localhost:8000/fmstream-api"

# Search for stations
curl "http://localhost:8000/fmstream-api?s=vietnam"

# Get featured stations
curl "http://localhost:8000/fmstream-api?c=FT"

# Filter by genre/style
curl "http://localhost:8000/fmstream-api?style=pop"

API Documentation: http://localhost:8000/docs

API Parameters

  • c: Country code (ITU), "FT" for featured, "RD" for random
  • hq: High quality audio (0/1)
  • l: Language (ISO code)
  • n: Offset (skip n entries)
  • o: Order/filter (top, big, med, sma, or letter)
  • s: Search string
  • style: Station style/genre

API Reference

FMStreamScraper

Main scraper class with methods:

  • scrape_stations(url) - Complete scraping process
  • extract_station_info(url) - Extract station metadata only
  • extract_audio_streams(url) - Extract stream data only
  • match_station_to_group(title, groups) - Match station to stream group

Data Models

  • RadioStation - Complete radio station with metadata and streams
  • AudioStream - Individual audio stream with title and URL
  • StreamGroup - Group of related audio streams

Legal & Data Source Notice

  • This library uses data scraped from fmstream.org.
  • For non-commercial use only. No ads, no fees, no user tracking.
  • Do not store or aggregate stream URLs or metadata in your own database.
  • You must clearly credit fmstream.org as the data source and provide a visible link in your application.
  • You are solely responsible for any legal issues arising from use of this data.
  • See fmstream.org API Terms for full conditions.

Requirements

  • Python 3.7+
  • requests
  • beautifulsoup4
  • fastapi (for API server)
  • pydantic (for API server)
  • uvicorn (for API server)

License

MIT License

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

fmstream-1.0.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fmstream-1.0.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file fmstream-1.0.1.tar.gz.

File metadata

  • Download URL: fmstream-1.0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for fmstream-1.0.1.tar.gz
Algorithm Hash digest
SHA256 af192d0609cf77a56300132f30e39ba32bbd102e9c024523dffae6fcc29061d6
MD5 bbd71312f8a62e1bb1fb464743288168
BLAKE2b-256 5246862bd04651978946ba72cddcb92eae698367650d7d5d875b86e29ad43d44

See more details on using hashes here.

File details

Details for the file fmstream-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: fmstream-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for fmstream-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d54c8d8abb98b68c8ac00cbee821e3c911a12f7f6d647102b1217d47571ff6de
MD5 70b87cc1e24474c12884f78864827d2e
BLAKE2b-256 cec612a5136524de5a5547602d30e1929dcf885a49d167b1ab4c2a6e47f36ff3

See more details on using hashes here.

Supported by

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