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

@ -1,43 +1,44 @@
{
"name": "ts3bot",
"version": "0.2.0",
"description": "Allows running TeamSpeak3 as a bot for all kinds of media (local music/videos/streams/YouTube/...) without the need for a real GUI to exist.",
"main": "app.js",
"keywords": [
"teamspeak",
"teamspeak3",
"ts3",
"bot",
"ts3bot",
"teamspeak3bot",
"music",
"playback",
"audio",
"video",
"media",
"musicbot"
],
"author": "Carl Kittelberger <icedream2k9@die-optimisten.net>",
"license": "GPL-3.0+",
"dependencies": {
"express": "^4.13.3",
"iced-coffee-script": "^108.0.8",
"merge": "^1.2.0",
"mkdirp": "^0.5.1",
"nconf": "^0.7.2",
"npm-which": "^2.0.0",
"password-generator": "^2.0.1",
"querystring": "^0.2.0",
"request": "^2.61.0",
"simple-ini": "^1.0.3",
"sqlite3": "^3.1.0",
"stream-splitter": "^0.3.2",
"string.prototype.startswith": "^0.2.0",
"sync": "^0.2.5",
"valid-url": "^1.0.9",
"vlc-api": "0.0.0",
"which": "^1.1.2",
"winston": "^1.0.1",
"xvfb": "git://github.com/icedream/node-xvfb.git"
}
"name": "ts3bot",
"version": "0.2.0",
"description": "Allows running TeamSpeak3 as a bot for all kinds of media (local music/videos/streams/YouTube/...) without the need for a real GUI to exist.",
"main": "app.js",
"keywords": [
"teamspeak",
"teamspeak3",
"ts3",
"bot",
"ts3bot",
"teamspeak3bot",
"music",
"playback",
"audio",
"video",
"media",
"musicbot"
],
"author": "Carl Kittelberger <icedream2k9@die-optimisten.net>",
"license": "GPL-3.0+",
"dependencies": {
"express": "^4.13.3",
"iced-coffee-script": "^108.0.8",
"merge": "^1.2.0",
"mkdirp": "^0.5.1",
"nconf": "^0.7.2",
"npm-which": "^2.0.0",
"password-generator": "^2.0.1",
"querystring": "^0.2.0",
"request": "^2.61.0",
"simple-ini": "^1.0.3",
"sqlite3": "^3.1.0",
"stream-splitter": "^0.3.2",
"string.prototype.startswith": "^0.2.0",
"sync": "^0.2.5",
"valid-url": "^1.0.9",
"vlc-api": "0.0.0",
"which": "^1.1.2",
"winston": "^1.0.1",
"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