local and radio
This commit is contained in:
parent
23038c99a2
commit
b976e330ca
14
bin/radio.js
Normal file
14
bin/radio.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
var player = require('play-sound')(opts = {})
|
||||||
|
// const { exec } = require("child_process");
|
||||||
|
|
||||||
|
async function playRadio(album) {
|
||||||
|
const localPlayList = album.split(":")
|
||||||
|
const stream = localPlayList[1] + ':' + localPlayList[2]
|
||||||
|
const audio = player.play(stream, { mplayer: ['-playlist'] }, function (err) {
|
||||||
|
if (err && !err.killed) throw err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
playRadio
|
||||||
|
}
|
69
player.js
69
player.js
@ -3,6 +3,7 @@ var _ = require('lodash')
|
|||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
var rpn = require('request-promise-native')
|
var rpn = require('request-promise-native')
|
||||||
var localPlayFunctions = require('./bin/local')
|
var localPlayFunctions = require('./bin/local')
|
||||||
|
var radioPlayFunctions = require('./bin/radio')
|
||||||
|
|
||||||
var myArgs = process.argv.slice(2);
|
var myArgs = process.argv.slice(2);
|
||||||
|
|
||||||
@ -103,43 +104,47 @@ async function playFile() {
|
|||||||
if (album.includes('local:')) {
|
if (album.includes('local:')) {
|
||||||
console.log('local')
|
console.log('local')
|
||||||
await localPlayFunctions.playLocal(album)
|
await localPlayFunctions.playLocal(album)
|
||||||
|
} else if (album.includes('radio:')) {
|
||||||
|
console.log('radio')
|
||||||
|
await radioPlayFunctions.playRadio(album)
|
||||||
} else {
|
} else {
|
||||||
console.log('spotify')
|
console.log('spotify')
|
||||||
let response;
|
let response;
|
||||||
let body;
|
let body;
|
||||||
try {
|
try {
|
||||||
if (lastPlayer.includes(album)) {
|
if (lastPlayer.includes(album)) {
|
||||||
body = {}
|
body = {}
|
||||||
} else {
|
} else {
|
||||||
body = {
|
body = {
|
||||||
"context_uri": album,
|
"context_uri": album,
|
||||||
"offset": {
|
"offset": {
|
||||||
"position": 0
|
"position": 0
|
||||||
},
|
},
|
||||||
"position_ms": 0
|
"position_ms": 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
response = await rpn({
|
||||||
|
method: 'PUT',
|
||||||
|
url: ' https://api.spotify.com/v1/me/player/play',
|
||||||
|
qs: {
|
||||||
|
device_id: DiskPlayerId
|
||||||
|
},
|
||||||
|
simple: false,
|
||||||
|
body,
|
||||||
|
resolveWithFullResponse: true,
|
||||||
|
json: true,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${spotify._credentials.accessToken}`
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
throw Error(`Request error: ${e}`);
|
||||||
}
|
}
|
||||||
response = await rpn({
|
this.response = response;
|
||||||
method: 'PUT',
|
this.response.body = response.body
|
||||||
url: ' https://api.spotify.com/v1/me/player/play',
|
|
||||||
qs: {
|
|
||||||
device_id: DiskPlayerId
|
|
||||||
},
|
|
||||||
simple: false,
|
|
||||||
body,
|
|
||||||
resolveWithFullResponse: true,
|
|
||||||
json: true,
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${spotify._credentials.accessToken}`
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
throw Error(`Request error: ${e}`);
|
|
||||||
}
|
}
|
||||||
this.response = response;
|
|
||||||
this.response.body = response.body }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ async function buildPage() {
|
|||||||
sid = `spotify:album:${id}`
|
sid = `spotify:album:${id}`
|
||||||
} else if (i.includes("/playlist/")) {
|
} else if (i.includes("/playlist/")) {
|
||||||
sid = `spotify:playlist:${id}`
|
sid = `spotify:playlist:${id}`
|
||||||
|
} else if (i.includes(".m3u")) {
|
||||||
|
sid = `radio:${id}`
|
||||||
} else if (i.includes("local:")) {
|
} else if (i.includes("local:")) {
|
||||||
sid = `${id}`
|
sid = `${id}`
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user