Use youtube-dl to resolve URLs if possible.

First try --format=bestaudio, if that fails  try --format=best and if that fails as well, just pass the URL as-is to VLC. Very fault tolerant and silently ignores errors (except for letting it show up in the logs)...
develop
Icedream 2015-10-16 15:25:46 +02:00
parent ab3e66ae8f
commit a5dbbb631b
2 changed files with 60 additions and 43 deletions

View File

@ -38,6 +38,7 @@
"vlc-api": "0.0.0",
"which": "^1.1.2",
"winston": "^1.0.1",
"xvfb": "git://github.com/icedream/node-xvfb.git"
"xvfb": "git://github.com/icedream/node-xvfb.git",
"youtube-dl": "^1.10.5"
}
}

View File

@ -7,6 +7,7 @@ Socket = net.Socket
getLogger = require "../logger"
config = require "../config"
log = getLogger "API"
youtubedl = require "youtube-dl"
#PulseAudio = require "pulseaudio"
isValidUrl = (require "valid-url").isWebUri
@ -60,14 +61,29 @@ module.exports = class APIService extends services.Service
log.warn "VLC API returned an error when trying to empty", err
return
await vlc.status.play input, defer(err)
# let's give youtube-dl a shot!
await youtubedl.getInfo input, [
"--format=bestaudio"
], defer(err, info)
if err or not info?
await youtubedl.getInfo input, [
"--format=best"
], defer(err, info)
if err or not info?
info =
url: input
if not info.url?
info.url = input
info.title = input # URL as title
await vlc.status.play info.url, defer(err)
if err
vlc.status.empty()
res.status(503).send("Something went wrong")
log.warn "VLC API returned an error when trying to play", err
return
res.send("OK")
res.send JSON.stringify info
app.get "/stop", (req, res) =>
if not req.query.uid