1
0
Fork 0
mirror of https://github.com/Findus23/RadioStats.git synced 2024-09-19 16:03:48 +02:00

static channelInfo

This commit is contained in:
Lukas Winkler 2018-02-08 15:40:00 +01:00
parent 52f1399cd8
commit c30c63fa61
No known key found for this signature in database
GPG key ID: 94AFBE7C2656A5B5
5 changed files with 240 additions and 62 deletions

215
channelInfo.py Normal file
View file

@ -0,0 +1,215 @@
channels = {
"oe1": {
"shortname": "oe1",
"streamurl": "http://mp3ooe1.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe1shoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/oe1.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/oe1infos.html",
"aticon": "./images/oe1-aticon.png",
"statncss": "./css/oe1.css",
"stationname": "Radio Österreich 1",
"cHasData": False,
"cPrimaryColor": "#b11a1a",
"cSecondaryColor": None,
"cStationName": "Radio Ö1"
},
"oe3": {
"shortname": "oe3",
"streamurl": "http://mp3oe3.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe3shoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://ms01.oe3.fm/oe3metafiles/RMX/RMWEB.PHP?Res=200&Format=json&callback=onair&Type=long",
"curProgram": "http://ms01.oe3.fm/oe3metafiles/ModAK/ShowInfo.php?ImgRes=HD&InfoType=Full&Format=json&callback=sendung",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/oe3infos.html",
"aticon": "./images/oe3-aticon.png",
"statncss": "./css/oe3b.css",
"chcolor": "#f04040",
"stationname": "hitradio Ö3",
"cHasData": True,
"cPrimaryColor": "#002350",
"cSecondaryColor": "#E10032",
"cStationName": "Hitradio Ö3"
},
"fm4": {
"shortname": "fm4",
"streamurl": "http://mp3fm4.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://fm4shoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/fm4.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=Wochen-Plan-Fm4.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/fm4infos.html",
"aticon": "./images/fm4-aticon.png",
"statncss": "./css/fm4b.css",
"stationname": "Radio FM4",
"cHasData": True,
"cPrimaryColor": "#FFE500",
"cSecondaryColor": None
},
"bgl": {
"shortname": "bgl",
"streamurl": "http://mp3burgenland.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2bshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/bgl.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-bgl.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/bglinfos.html",
"aticon": "./images/bgl-aticon.png",
"anicon": "./images/bgl-aticon-128.png",
"statncss": "./css/bgl.css",
"stationname": "Radio Burgenland",
"cHasData": True,
"cPrimaryColor": "#ffa60f",
"cSecondaryColor": "#d32824"
},
"ktn": {
"shortname": "ktn",
"streamurl": "http://mp3kaernten.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2kshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/ktn.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-ktn.xml",
"leftbuttonstring": "Tracklist",
"midbuttonstring": "",
"infodata": "./infos/ktninfos.html",
"aticon": "./images/ktn-aticon.png",
"statncss": "./css/ktn.css",
"stationname": "Radio Kärnten",
"cHasData": False,
"cPrimaryColor": "#bc1716",
"cSecondaryColor": "#ffcd00"
},
"noe": {
"shortname": "noe",
"streamurl": "http://mp3noe.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2nshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/noe.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-noe.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/noeinfos.html",
"aticon": "./images/noe-aticon.png",
"statncss": "./css/noe.css",
"stationname": "Radio Niederösterreich",
"cHasData": True,
"cPrimaryColor": "#002777",
"cSecondaryColor": "#ffcd00"
},
"ooe": {
"shortname": "ooe",
"streamurl": "http://mp3ooe.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2oshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/ooe.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-ooe.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "",
"infodata": "./infos/ooeinfos.html",
"aticon": "./images/ooe-aticon.png",
"statncss": "./css/ooe.css",
"stationname": "Radio Oberösterreich",
"deskstream": "http://orfradio.liwest.at/liveHQ.m3u",
"cHasData": True,
"cPrimaryColor": "#bc1716",
"cSecondaryColor": "#ffffff"
},
"sbg": {
"shortname": "sbg",
"streamurl": "http://mp3salzburg.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2sshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/sbg.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-sbg.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "",
"infodata": "./infos/sbginfos.html",
"aticon": "./images/sbg-aticon.png",
"splash": "./images/sbg-splash.png",
"statncss": "./css/sbg.css",
"stationname": "Radio Salzburg",
"cHasData": True,
"cPrimaryColor": "#bc1716",
"cSecondaryColor": "#ffffff"
},
"stm": {
"shortname": "stm",
"streamurl": "http://mp3stmrk.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2stshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/stmk.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-stm.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/stminfos.html",
"aticon": "./images/stm-aticon.png",
"statncss": "./css/stm.css",
"stationname": "Radio Steiermark",
"cHasData": True,
"cPrimaryColor": "#006843",
"cSecondaryColor": "#ffffff"
},
"tir": {
"shortname": "tir",
"streamurl": "http://mp3tirol.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2tshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/tir.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-tir.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/tirinfos.html",
"aticon": "./images/tir-aticon.png",
"statncss": "./css/tir.css",
"stationname": "Radio Tirol",
"cHasData": True,
"cPrimaryColor": "#bc1716",
"cSecondaryColor": "#ffffff"
},
"vbg": {
"shortname": "vbg",
"streamurl": "http://mp3vlbg.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2vshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/vbg.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-vbg.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/vbginfos.html",
"aticon": "./images/vbg-aticon.png",
"statncss": "./css/vbg.css",
"stationname": "Radio Vorarlberg",
"cHasData": False,
"cPrimaryColor": "#bc1716",
"cSecondaryColor": "#ffffff"
},
"wie": {
"shortname": "wie",
"streamurl": "http://mp3wien2.apasf.sf.apa.at/;",
"streamurlShoutcast2": "http://oe2wshoutcast.sf.apa.at:8000/;",
"strmtype": "audio/mpeg",
"tracklist": "http://hop.orf.at/img-trackservice/wien.js",
"curProgram": "http://tube.orf.at/broadcastSchedule/currentBroadcast.jsonp?scheme=sendungsplan-wie.xml",
"leftbuttonstring": "Hitlist",
"midbuttonstring": "Podcasts",
"infodata": "./infos/wieinfos.html",
"aticon": "./images/wie-aticon.png",
"splash": "./images/wie-splash.png",
"statncss": "./css/wie.css",
"stationname": "Radio Wien",
"cHasData": True,
"cPrimaryColor": "#ee7e01",
"cSecondaryColor": "#552382"
}
}

View file

@ -1,7 +1,4 @@
import json
import requests
import channelInfo
from models import *
for i in [Play, Channel, Song]:
@ -9,23 +6,13 @@ for i in [Play, Channel, Song]:
for i in [Channel, Song, Play]:
i.create_table()
r = requests.get('http://radio.orf.at/player/js/config.js')
config_js = r.text
pseudo_json = config_js \
.replace("// here be the settings for all radio programs", "") \
.replace("var stations = ", "") \
.replace("};", "}") \
.replace("Burgenland\",", "Burgenland\"")
config = json.loads(pseudo_json)
for id, channel in config.items():
if id != "validStationList" and "apasf.sf.apa.at" in channel["streamurl"] and id != "oe1":
streamurl = channel["streamurl"].replace(";", "")
try:
r = requests.get(streamurl + "played.html?type=json")
supports_json = r.status_code == 200
except requests.exceptions.ConnectionError:
supports_json = False
Channel.get_or_create(shortname=channel["shortname"], streamurl=streamurl,
stationname=channel["stationname"], supports_json=supports_json)
for id, channel in channelInfo.channels.items():
if "streamurlShoutcast2" in channel:
streamurl = channel["streamurlShoutcast2"].replace(";", "")
else:
streamurl = None
if "cStationName" in channel:
channel["stationname"] = channel["cStationName"]
Channel.create(shortname=channel["shortname"], streamurl=streamurl,
stationname=channel["stationname"], has_data=channel["cHasData"],
primary_color=channel["cPrimaryColor"], secondary_color=channel["cSecondaryColor"])

View file

@ -2,7 +2,6 @@ from datetime import datetime, timedelta
from time import sleep
import requests
from bs4 import BeautifulSoup
from models import *
@ -15,6 +14,7 @@ def careful_fetch(url):
"""
:rtype: requests.models.Response
"""
print(url)
result = None
tries = 0
while result is None:
@ -38,24 +38,10 @@ def detect_show(artist, title):
or "mein radio" in title.lower() or "SCHOENSTEN OLDIES" in title \
or "RADIO STEIERMARK" in title or "Radio Burgenland" in title \
or "FM4 " in title or "Radio Salzburg" in title \
or "RADIO OÖ" == title \
or "RADIO OÖ" == title or "Radio Wien" in title \
or (title == "" and artist == "")
def time_to_date(time):
"""
:rtype: datetime.datetime
:type time: datetime.time
"""
time_hour = time.hour
day = datetime.now()
current_hour = day.hour
if 0 <= current_hour <= 3 and 22 <= time_hour <= 24:
day = datetime.today() - timedelta(days=1)
return datetime.combine(day.date(), time)
def add_entry(time, artist, title):
print(time, artist, title)
try:
@ -72,33 +58,21 @@ def add_entry(time, artist, title):
for channel in Channel.select():
if channel.supports_json:
if channel.has_data:
r = careful_fetch(channel.streamurl + "played.html?type=json")
print(r.text)
for song in r.json():
time = datetime.fromtimestamp(song["playedat"])
artist, title = song["title"].split(" - ")
add_entry(time, artist, title)
else:
print(channel.streamurl + "played.html")
r = careful_fetch(channel.streamurl + "played.html")
soup = BeautifulSoup(r.text.encode('latin1').decode('utf8'), 'html.parser')
table = soup.find_all("table")[2]
for b in table("b"):
b.extract()
for tr in table.find_all("tr")[1:]:
tds = tr.find_all("td")
timestring = tds[0].get_text()
description = tds[1].get_text()
if " - " in description:
print(description)
title, artist = description.split(" - ")[:2] # non oe3 channels are the other way round
if " - " in song["title"]:
if channel.shortname == "oe3" or channel.shortname=="fm4":
artist, title = song["title"].split(" - ")
else:
title, artist = song["title"].split(" - ")[:2] # non oe3 channels are the other way round
else:
artist = ""
title = description
title = song["title"]
if channel.shortname == "fm4" and "|" in artist:
artist = artist.split("|")[0]
time = time_to_date(datetime.strptime(timestring, "%H:%M:%S").time())
add_entry(time, artist, title)

View file

@ -5,9 +5,11 @@ from basemodel import BaseModel
class Channel(BaseModel):
shortname = CharField(unique=True, max_length=5)
streamurl = CharField()
streamurl = CharField(null=True)
stationname = CharField()
supports_json = BooleanField()
has_data = BooleanField()
primary_color = CharField(max_length=7)
secondary_color = CharField(max_length=7,null=True)
class Song(BaseModel):

View file

@ -8,7 +8,7 @@ itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
mysqlclient==1.3.12
peewee==3.0.13
peewee==3.0.15
requests==2.18.4
urllib3==1.22
Werkzeug==0.14.1