*fix news *rm infowars *rm async *polish nowPlaying
This commit is contained in:
parent
7296e42b4c
commit
1c62ee61c7
2 changed files with 34 additions and 40 deletions
|
@ -3,17 +3,17 @@
|
||||||
"Air Progressive",
|
"Air Progressive",
|
||||||
"airprogressive.org:8000/stream",
|
"airprogressive.org:8000/stream",
|
||||||
|
|
||||||
"BBC",
|
"BBC World Service -data",
|
||||||
"bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-einws",
|
"a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_vlow/ak/bbc_world_service.m3u8",
|
||||||
|
|
||||||
"CBC",
|
"CBC Fresh Air",
|
||||||
"3153.live.streamtheworld.com:80/CBC_R1_MCT_L_SC",
|
"cbcradiolive.akamaized.net/hls/live/2041037/ES_R1ETT/master.m3u8",
|
||||||
|
|
||||||
"GLT News & Ideas",
|
"GLT News & Ideas",
|
||||||
"wgltradio.ilstu.edu:8000/wgltmain.mp3",
|
"wgltradio.ilstu.edu:8000/wgltmain.mp3",
|
||||||
|
|
||||||
"NPR",
|
"NPR",
|
||||||
"nprdmp-live01-mp3.akacast.akamaistream.net/7/998/364916/v1/npr.akacast.akamaistream.net/nprdmp_live01_mp3",
|
"https://npr-ice.streamguys1.com/live.mp3",
|
||||||
|
|
||||||
"Newstalk 106-108",
|
"Newstalk 106-108",
|
||||||
"vice02.iad.xpc-mii.net:80/communicorp/Newstalk_high",
|
"vice02.iad.xpc-mii.net:80/communicorp/Newstalk_high",
|
||||||
|
@ -36,9 +36,6 @@
|
||||||
"Freethought Radio",
|
"Freethought Radio",
|
||||||
"212.48.126.146:9110",
|
"212.48.126.146:9110",
|
||||||
|
|
||||||
"Infowars",
|
|
||||||
"50.7.79.22:80",
|
|
||||||
|
|
||||||
"KSFC",
|
"KSFC",
|
||||||
"173.192.70.138:8710",
|
"173.192.70.138:8710",
|
||||||
|
|
||||||
|
|
61
src/term.nim
61
src/term.nim
|
@ -2,7 +2,7 @@ import
|
||||||
osproc, terminal, random, os,
|
osproc, terminal, random, os,
|
||||||
strformat, strutils, json,
|
strformat, strutils, json,
|
||||||
client, sequtils, parseutils,
|
client, sequtils, parseutils,
|
||||||
httpclient, times, asyncdispatch
|
httpclient
|
||||||
|
|
||||||
proc clear* =
|
proc clear* =
|
||||||
eraseScreen()
|
eraseScreen()
|
||||||
|
@ -192,40 +192,27 @@ proc init(parm:string,ctx: ptr Handle) =
|
||||||
cE initialize ctx
|
cE initialize ctx
|
||||||
cE ctx.cmd file
|
cE ctx.cmd file
|
||||||
|
|
||||||
|
|
||||||
#[proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} =
|
|
||||||
let t0 = cpuTime()
|
|
||||||
let t1 = cpuTime() - t0
|
|
||||||
echo t1
|
|
||||||
|
|
||||||
proc asyncProc(link: string):Future[string] {.async.} =
|
|
||||||
var client = newAsyncHttpClient()
|
|
||||||
client.onProgressChanged = onProgressChanged
|
|
||||||
return await client.getContent(link & "/status-json.xsl")
|
|
||||||
]#
|
|
||||||
|
|
||||||
proc getCurrentSong*(linke: string): string =
|
proc getCurrentSong*(linke: string): string =
|
||||||
var client = newAsyncHttpClient()
|
var
|
||||||
var link = linke
|
client = newHttpClient()
|
||||||
link.removePrefix("http://")
|
link = linke
|
||||||
link.delete(find(link, "/") .. link.high)
|
link.removePrefix "http://"
|
||||||
echo link
|
var findSlash = link.find "/"
|
||||||
|
if findSlash != -1:
|
||||||
|
link.delete(findSlash .. link.high)
|
||||||
link = "http://" & link
|
link = "http://" & link
|
||||||
#try: #icecast
|
try: #shoutcast
|
||||||
var xsl = waitFor asyncProc link
|
return client.getContent(link & "/currentsong")
|
||||||
#var xsl = client.getContent(link & "/status-json.xsl")
|
except HttpRequestError: #icecast
|
||||||
return
|
try:
|
||||||
to(
|
return
|
||||||
parseJson(
|
to(
|
||||||
xsl
|
parseJson(
|
||||||
){"icestats"}{"source"}[1]{"yp_currently_playing"},
|
client.getContent(link & "/status-json.xsl")
|
||||||
|
){"icestats"}{"source"}[1]{"yp_currently_playing"},
|
||||||
string
|
string
|
||||||
)
|
)
|
||||||
#[except HttpRequestError, JsonParsingError: #shoutcast
|
except: return ""
|
||||||
return client.getContent(link & "/currentsong")
|
|
||||||
except:
|
|
||||||
return ""]#
|
|
||||||
|
|
||||||
|
|
||||||
proc call*(sub:string; sect = ""; stat,link:string):Natural {.discardable.} =
|
proc call*(sub:string; sect = ""; stat,link:string):Natural {.discardable.} =
|
||||||
if link == "": return 1
|
if link == "": return 1
|
||||||
|
@ -244,10 +231,14 @@ proc call*(sub:string; sect = ""; stat,link:string):Natural {.discardable.} =
|
||||||
echoPlay = true
|
echoPlay = true
|
||||||
event = ctx.waitEvent 1000
|
event = ctx.waitEvent 1000
|
||||||
isPaused = false
|
isPaused = false
|
||||||
|
nowPlayingExcept = false
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
if echoPlay:
|
if echoPlay:
|
||||||
sayPos 4, "Now Playing: " & getCurrentSong(link)
|
var currentSong = getCurrentSong link
|
||||||
|
if currentSong != "":
|
||||||
|
sayPos 4, "Now Playing: " & currentSong
|
||||||
|
else: nowPlayingExcept = true
|
||||||
sayPos 4, "Playing"
|
sayPos 4, "Playing"
|
||||||
cursorUp()
|
cursorUp()
|
||||||
echoPlay = false
|
echoPlay = false
|
||||||
|
@ -268,7 +259,13 @@ proc call*(sub:string; sect = ""; stat,link:string):Natural {.discardable.} =
|
||||||
case getch():
|
case getch():
|
||||||
of 'p','m','P','M':
|
of 'p','m','P','M':
|
||||||
if isPaused:
|
if isPaused:
|
||||||
|
if nowPlayingExcept != true:
|
||||||
|
cursorUp()
|
||||||
|
eraseLine()
|
||||||
|
cursorDown()
|
||||||
eraseLine()
|
eraseLine()
|
||||||
|
if nowPlayingExcept != true:
|
||||||
|
cursorUp()
|
||||||
let ctx = create()
|
let ctx = create()
|
||||||
init link, ctx
|
init link, ctx
|
||||||
echoPlay = true
|
echoPlay = true
|
||||||
|
|
Loading…
Reference in a new issue