Skip to content

Commit

Permalink
Updates to REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
duracell80 committed Jun 22, 2023
1 parent 3cb2d82 commit f97cf40
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 28 deletions.
32 changes: 32 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ async def fav_remaining():
async def fav_total():
return '{"value": "' + str(oe.get_total("fav")) + '"}'

@app.get("/v1/favourites/play/{c}", status_code=200)
async def fav_move(c):
if c.isnumeric():
result = oe.play(str(c))
if result:
status = str(oe.status(url))
return '{"result": "' + str(result) + '", "message": "' + str(status) + '"}'
else:
return '{"result": "failed", "message": "Channel may be out of range, for example if you are trying to play channel 5 and only have 4 channels in memory"}'

else:
return '{"result": "failed", "message": "Channel index not a number, try requesting with an integer value"}'




@app.get("/v1/favourites/move/{r}", status_code=200)
async def fav_move(r):
if ":" in r:
r_bits = r.split(":")
result = oe.move(str(r_bits[0]), str(r_bits[1]))
return '{"result": "' + str(result) + '"}'
else:
return '{"result": "failed"}'

@app.get("/v1/search/radiobrowser/{keywords}", status_code=200)
async def search(keywords):
code, result = oe.search(str(keywords), "RadioBrowser", False)
Expand All @@ -47,6 +72,13 @@ async def search(keywords):
else:
return '{"chname": "Station Not Found", "churl": "https://streaming.radio.co/s5c5da6a36/listen"}'

@app.get("/v1/search/tunein/{keywords}", status_code=200)
async def search(keywords):
code, result = oe.search(str(keywords), "TuneIn", False)
if code == 200:
return result
else:
return '{"chname": "Station Not Found", "churl": "https://streaming.radio.co/s5c5da6a36/listen"}'



Expand Down
13 changes: 6 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ def main():
ip = settings["ipaddress"]
url= "http://" + str(ip)

# Search TuneIn (VPN to non UK country)
code, result = oe.search("BBC", "TuneIn", False)

if oe.is_online():

print(oe.status(url))
Expand All @@ -32,6 +29,10 @@ def main():
# Use Community Radio Browser to replace a masked URL from skytune
#print(oe.enrich_url("BBC Radio 4"))

# Search TuneIn
#code, result = oe.search("Dash Radio", "TuneIn", False)
#print(result)

#oe.volume("down")
#oe.volume("up")
#oe.volume("mute")
Expand All @@ -42,11 +43,8 @@ def main():
#oe.delete("54")
#oe.edit("53", "Vivaldi", "https://stream.0nlineradio.com/vivaldi", "3;17;-1", "2;15", "0")

#print(oe.info_get("1"))
#print(oe.info_get("18"))
#print(oe.info_get("47"))


# Export favourites and attempt to unmask / replace URL's hidden by skytune
#print(oe.get_list("plain", False))
#print(oe.get_list("json", True))
#print(oe.get_list("json-rpp", True))
Expand All @@ -61,6 +59,7 @@ def main():
#print(oe.decode_genre("-1", "1", "6"))


#Get info from a favourite
#chid, chname, churl, chcountry, chgenre = oe.info_get("1")
#print(chid + "," + chname + "," + churl + "," + chcountry + "," + chgenre)

Expand Down
67 changes: 46 additions & 21 deletions oceaneyes.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,33 +205,54 @@ def search(keyword = "BBC Radio 1", source = "radiobrowser", match_exact = True
try:
import opml

data = opml.parse("http://opml.radiotime.com/Search.ashx?query=" + str(keyword))
data = opml.parse("http://opml.radiotime.com/Search.ashx?event=lit&query=" + str(keyword))
i = 0
c = 0

for d in data:
if "stations" in str(data[i].text).lower():
#print(data[i][0].type)
c = 0
for r in data[i]:
if str(data[i][c].type).lower() == "audio":
station_name = str(data[i][c].text)
station_url = str(data[i][c].URL)
station_codec = str(data[i][c].formats)
station_bitrate = str(data[i][c].bitrate)
station_genre = str(data[i][c].genre_id)
station_country = str(data[i][c].guide_id)
station_language= str(data[i][c].subtext)

link = "http://www.somesite.com/details.pl?urn=2344"
try:
if str(data[i].type).lower() == "audio" and str(data[i].item).lower() == "station" and i <= int(len(data)):
c+=1
try:
station_name = str(data[i].text)
station_url = str(data[i].URL)

f = urllib.request.urlopen(str(station_url))
station_url = str(f.read())
station_url = station_url.replace("b'http", "http").replace("\\n'", "")
f.close()

station_data = {'chindex': int(c), 'chname': str(station_name), 'churl': str(station_url), 'chcodec': str(station_codec), 'chbitrate': str(station_bitrate), 'chhls': 0, 'chgenre': str(station_genre), 'chcountry': str(station_country), 'chlanguage': str(station_language)}
l.append(station_data)
except:
station_name = str(url_placeholder)
station_url = str(name_placeholder)
try:
station_codec = str(data[i].formats)
station_bitrate = str(data[i].bitrate)
except:
station_code = "not"
station_bitrate = "0"
try:
data[i].genre_id
station_genre = str(data[i].genre_id)
except:
station_genre = "g0"
try:
station_country = str(data[i].guide_id)
except:
station_country = str(data[i].guide_id)
try:
station_language = str(data[i].subtext)
except:
station_language = "s0"


station_data = {'chindex': int(c), 'chname': str(station_name), 'churl': str(station_url), 'chcodec': str(station_codec), 'chbitrate': str(station_bitrate), 'chhls': 0, 'chgenre': str(station_genre), 'chcountry': str(station_country), 'chlanguage': str(station_language)}
l.append(station_data)
i+=1
except:
station_data = {'chindex': 0, 'chname': 'not found', 'source': 'none', 'churl': 'not found', 'chcodec': 'MP3', 'chbitrate': '320', 'chhls': 0, 'chgenre': 'notfound', 'chcountry': 'not found', 'chlanguage': 'not found'}


c+=1
i+=1
if len(data) > 2:
code = 200
else:
Expand Down Expand Up @@ -379,8 +400,12 @@ def edit(chid = "0", newchname = name_placeholder, newchurl = url_placeholder, f


def play(ch = "0"):
r = requests.get(url + "/doApi.cgi", params = {"AI":"16", "CI": str(ch - 1)})
return
t = get_total("fav")
if int(ch) <= t:
r = requests.get(url + "/doApi.cgi", params = {"AI":"16", "CI": str(int(ch) - 1)})
return True
else:
return False


def delete(chid = "100"):
Expand Down

0 comments on commit f97cf40

Please sign in to comment.