mirror of
https://github.com/ovosimpatico/radio.garden-to-m3u.git
synced 2026-01-15 06:02:52 -03:00
Initial commit
This commit is contained in:
175
.gitignore
vendored
175
.gitignore
vendored
@@ -1,24 +1,163 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# Log file
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
# Project
|
||||
*.m3u
|
||||
50
README.md
50
README.md
@@ -1,2 +1,48 @@
|
||||
# radio.garden-to-m3u
|
||||
A software that creates a m3u playlist from radio.garden public API
|
||||
# Radio.garden -> m3u
|
||||
A software that creates a m3u playlist from radio.garden public API data.
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
- Python
|
||||
|
||||
## How to use
|
||||
|
||||
1. Clone the repository
|
||||
|
||||
```bash
|
||||
git clone https://github.com/ovosimpatico/radio.garden-to-m3u.git
|
||||
```
|
||||
|
||||
2. Run the script
|
||||
|
||||
```bash
|
||||
python main.py --country COUNTRY --state STATE
|
||||
```
|
||||
|
||||
The m3u file will be created in the same directory as the script, as radio.m3u. It can be used on any player that supports m3u playlists, such as VLC or MPV.
|
||||
|
||||
Examples:
|
||||
|
||||
```bash
|
||||
python main.py --country "Brazil" --state "SP"
|
||||
```
|
||||
|
||||
```bash
|
||||
python main.py --country "United States" --state "LA"
|
||||
```
|
||||
|
||||
```bash
|
||||
python main.py --country "Bulgaria"
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the Affero General Public License v3.0. See the [LICENSE](LICENSE) file for details.
|
||||
|
||||
## Disclaimer
|
||||
|
||||
This project is not affiliated with radio.garden in any way. It uses the public API provided by the website to create a m3u playlist.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
- [radio-garden-openapi](https://github.com/jonasrmichel/radio-garden-openapi)
|
||||
73
main.py
Normal file
73
main.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import os
|
||||
import requests
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='Radio Garden M3U Generator',
|
||||
description='This script generates a M3U file with stations from Radio Garden.')
|
||||
|
||||
parser.add_argument('--country', help='Country name', type=str, required=True)
|
||||
parser.add_argument('--state', help='State or province name', type=str, required=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
BASE_URL = "http://radio.garden/api"
|
||||
|
||||
def get_places():
|
||||
|
||||
list = []
|
||||
|
||||
data = requests.get(f"{BASE_URL}/ara/content/places").json()['data']['list']
|
||||
for place in data:
|
||||
list.append([place['country'], # Country
|
||||
place['title'], # City, State or Province
|
||||
place['id']]) # Place ID
|
||||
|
||||
return sorted(list)
|
||||
|
||||
def get_stations(place_id):
|
||||
list = []
|
||||
|
||||
data = requests.get(f"{BASE_URL}/ara/content/page/{place_id}/channels").json()['data']['content'][0]['items']
|
||||
for station in data:
|
||||
list.append([station['page']['title'], # Station Name
|
||||
station['page']['url'].split("/")[-1]]) # Station ID
|
||||
return list
|
||||
|
||||
def get_stream_url(station_id):
|
||||
return f"{BASE_URL}/ara/content/listen/{station_id}/channel.mp3"
|
||||
|
||||
|
||||
def m3u(stations):
|
||||
f = open('radio.m3u','a', encoding='utf-8')
|
||||
|
||||
# if the file is empty, write the header
|
||||
if os.path.getsize("radio.m3u") == 0:
|
||||
f.write('#EXTM3U\n')
|
||||
|
||||
for station in stations:
|
||||
station_name = station[0]
|
||||
stream_url = get_stream_url(station[1])
|
||||
f.write(f'#EXTINF:-1 tvg-name="{station_name}", {station_name}\n')
|
||||
f.write(f'{stream_url}\n')
|
||||
f.close()
|
||||
|
||||
def main():
|
||||
open('radio.m3u', 'w').close()
|
||||
if not args.state:
|
||||
places = get_places()
|
||||
for place in places:
|
||||
if args.country in place[0]:
|
||||
print(place[1])
|
||||
stations = get_stations(place[2])
|
||||
m3u(stations)
|
||||
if args.state:
|
||||
places = get_places()
|
||||
for place in places:
|
||||
if args.state in place[1]:
|
||||
print(place[1])
|
||||
stations = get_stations(place[2])
|
||||
m3u(stations)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user