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/country/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=radio&c=VN"

# 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.0.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.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fmstream-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 b56a8e44ef03767bac08abd77467af169022463b5027295e9033fe7be9e87a9c
MD5 ce81a9bccf758a591e25bccca3bf369c
BLAKE2b-256 f97baa8754f6f218d31027ab7d18d1e8f40a48cf850ffcb4d07b4a5a7f6531b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fmstream-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c77a81ee8aed99f6b80d09db9a6c1965cb78a74f2a3f4a7fd2e4ff86aa097aa
MD5 25df686aed38d95b6a36f9835af1b29f
BLAKE2b-256 38ea01a9f7de83944411ca34697587985e274834ffc700b2d013b540cf62b03c

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