Skip to content

Instantly share code, notes, and snippets.

@tasoseng
Created March 26, 2021 22:21
Show Gist options
  • Save tasoseng/ba1e10618028294810d3c8194eb1d3aa to your computer and use it in GitHub Desktop.
Save tasoseng/ba1e10618028294810d3c8194eb1d3aa to your computer and use it in GitHub Desktop.
generate .m3u playlist for thessaloniki radio stations from radiofono.gr site
#!/usr/bin/env python3
#coding: utf-8
from bs4 import BeautifulSoup
import mechanize
import re
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:32.0) Gecko/20100101 Firefox/32.0')]
response = br.open("http://www.radiofono.gr/live?city_id=9")
html = response.read()
soup = BeautifulSoup(html)
rows = soup.findAll("tr", attrs={"class":["live-station","live-station-odd"]})
get_url = re.compile(r"""window.open\('(.*)','.*',""", re.DOTALL).findall
print("#EXTM3U")
for row in rows:
name = row.find_all("td",attrs={"class":"live-station-name"})[0].get_text(strip=True)
link = row.find_all("a")[0].get("href")
if link==None:
link = get_url(row.find_all("a")[0].get("onclick"))[0]
print("#EXTINF:-1," + name)
print(link)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment