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 randomhq: 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 stringstyle: Station style/genre
API Reference
FMStreamScraper
Main scraper class with methods:
scrape_stations(url)- Complete scraping processextract_station_info(url)- Extract station metadata onlyextract_audio_streams(url)- Extract stream data onlymatch_station_to_group(title, groups)- Match station to stream group
Data Models
RadioStation- Complete radio station with metadata and streamsAudioStream- Individual audio stream with title and URLStreamGroup- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b56a8e44ef03767bac08abd77467af169022463b5027295e9033fe7be9e87a9c
|
|
| MD5 |
ce81a9bccf758a591e25bccca3bf369c
|
|
| BLAKE2b-256 |
f97baa8754f6f218d31027ab7d18d1e8f40a48cf850ffcb4d07b4a5a7f6531b1
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c77a81ee8aed99f6b80d09db9a6c1965cb78a74f2a3f4a7fd2e4ff86aa097aa
|
|
| MD5 |
25df686aed38d95b6a36f9835af1b29f
|
|
| BLAKE2b-256 |
38ea01a9f7de83944411ca34697587985e274834ffc700b2d013b540cf62b03c
|