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", "vlc-api": "0.0.0",
"which": "^1.1.2", "which": "^1.1.2",
"winston": "^1.0.1", "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" getLogger = require "../logger"
config = require "../config" config = require "../config"
log = getLogger "API" log = getLogger "API"
youtubedl = require "youtube-dl"
#PulseAudio = require "pulseaudio" #PulseAudio = require "pulseaudio"
isValidUrl = (require "valid-url").isWebUri 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 log.warn "VLC API returned an error when trying to empty", err
return 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 if err
vlc.status.empty() vlc.status.empty()
res.status(503).send("Something went wrong") res.status(503).send("Something went wrong")
log.warn "VLC API returned an error when trying to play", err log.warn "VLC API returned an error when trying to play", err
return return
res.send("OK") res.send JSON.stringify info
app.get "/stop", (req, res) => app.get "/stop", (req, res) =>
if not req.query.uid if not req.query.uid