*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",
|
||||
"airprogressive.org:8000/stream",
|
||||
|
||||
"BBC",
|
||||
"bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-einws",
|
||||
"BBC World Service -data",
|
||||
"a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_vlow/ak/bbc_world_service.m3u8",
|
||||
|
||||
"CBC",
|
||||
"3153.live.streamtheworld.com:80/CBC_R1_MCT_L_SC",
|
||||
"CBC Fresh Air",
|
||||
"cbcradiolive.akamaized.net/hls/live/2041037/ES_R1ETT/master.m3u8",
|
||||
|
||||
"GLT News & Ideas",
|
||||
"wgltradio.ilstu.edu:8000/wgltmain.mp3",
|
||||
|
||||
"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",
|
||||
"vice02.iad.xpc-mii.net:80/communicorp/Newstalk_high",
|
||||
|
@ -36,9 +36,6 @@
|
|||
"Freethought Radio",
|
||||
"212.48.126.146:9110",
|
||||
|
||||
"Infowars",
|
||||
"50.7.79.22:80",
|
||||
|
||||
"KSFC",
|
||||
"173.192.70.138:8710",
|
||||
|
||||
|
|
61
src/term.nim
61
src/term.nim
|
@ -2,7 +2,7 @@ import
|
|||
osproc, terminal, random, os,
|
||||
strformat, strutils, json,
|
||||
client, sequtils, parseutils,
|
||||
httpclient, times, asyncdispatch
|
||||
httpclient
|
||||
|
||||
proc clear* =
|
||||
eraseScreen()
|
||||
|
@ -192,40 +192,27 @@ proc init(parm:string,ctx: ptr Handle) =
|
|||
cE initialize ctx
|
||||
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 =
|
||||
var client = newAsyncHttpClient()
|
||||
var link = linke
|
||||
link.removePrefix("http://")
|
||||
link.delete(find(link, "/") .. link.high)
|
||||
echo link
|
||||
var
|
||||
client = newHttpClient()
|
||||
link = linke
|
||||
link.removePrefix "http://"
|
||||
var findSlash = link.find "/"
|
||||
if findSlash != -1:
|
||||
link.delete(findSlash .. link.high)
|
||||
link = "http://" & link
|
||||
#try: #icecast
|
||||
var xsl = waitFor asyncProc link
|
||||
#var xsl = client.getContent(link & "/status-json.xsl")
|
||||
return
|
||||
to(
|
||||
parseJson(
|
||||
xsl
|
||||
){"icestats"}{"source"}[1]{"yp_currently_playing"},
|
||||
try: #shoutcast
|
||||
return client.getContent(link & "/currentsong")
|
||||
except HttpRequestError: #icecast
|
||||
try:
|
||||
return
|
||||
to(
|
||||
parseJson(
|
||||
client.getContent(link & "/status-json.xsl")
|
||||
){"icestats"}{"source"}[1]{"yp_currently_playing"},
|
||||
string
|
||||
)
|
||||
#[except HttpRequestError, JsonParsingError: #shoutcast
|
||||
return client.getContent(link & "/currentsong")
|
||||
except:
|
||||
return ""]#
|
||||
|
||||
except: return ""
|
||||
|
||||
proc call*(sub:string; sect = ""; stat,link:string):Natural {.discardable.} =
|
||||
if link == "": return 1
|
||||
|
@ -244,10 +231,14 @@ proc call*(sub:string; sect = ""; stat,link:string):Natural {.discardable.} =
|
|||
echoPlay = true
|
||||
event = ctx.waitEvent 1000
|
||||
isPaused = false
|
||||
nowPlayingExcept = false
|
||||
|
||||
while true:
|
||||
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"
|
||||
cursorUp()
|
||||
echoPlay = false
|
||||
|
@ -268,7 +259,13 @@ proc call*(sub:string; sect = ""; stat,link:string):Natural {.discardable.} =
|
|||
case getch():
|
||||
of 'p','m','P','M':
|
||||
if isPaused:
|
||||
if nowPlayingExcept != true:
|
||||
cursorUp()
|
||||
eraseLine()
|
||||
cursorDown()
|
||||
eraseLine()
|
||||
if nowPlayingExcept != true:
|
||||
cursorUp()
|
||||
let ctx = create()
|
||||
init link, ctx
|
||||
echoPlay = true
|
||||
|
|
Loading…
Reference in a new issue