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 rpn = require('request-promise-native')
|
||||
var localPlayFunctions = require('./bin/local')
|
||||
var radioPlayFunctions = require('./bin/radio')
|
||||
|
||||
var myArgs = process.argv.slice(2);
|
||||
|
||||
@ -103,43 +104,47 @@ async function playFile() {
|
||||
if (album.includes('local:')) {
|
||||
console.log('local')
|
||||
await localPlayFunctions.playLocal(album)
|
||||
} else if (album.includes('radio:')) {
|
||||
console.log('radio')
|
||||
await radioPlayFunctions.playRadio(album)
|
||||
} else {
|
||||
console.log('spotify')
|
||||
let response;
|
||||
let body;
|
||||
try {
|
||||
if (lastPlayer.includes(album)) {
|
||||
body = {}
|
||||
} else {
|
||||
body = {
|
||||
"context_uri": album,
|
||||
"offset": {
|
||||
"position": 0
|
||||
},
|
||||
"position_ms": 0
|
||||
let response;
|
||||
let body;
|
||||
try {
|
||||
if (lastPlayer.includes(album)) {
|
||||
body = {}
|
||||
} else {
|
||||
body = {
|
||||
"context_uri": album,
|
||||
"offset": {
|
||||
"position": 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({
|
||||
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}`);
|
||||
this.response = response;
|
||||
this.response.body = response.body
|
||||
}
|
||||
this.response = response;
|
||||
this.response.body = response.body }
|
||||
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ async function buildPage() {
|
||||
sid = `spotify:album:${id}`
|
||||
} else if (i.includes("/playlist/")) {
|
||||
sid = `spotify:playlist:${id}`
|
||||
} else if (i.includes(".m3u")) {
|
||||
sid = `radio:${id}`
|
||||
} else if (i.includes("local:")) {
|
||||
sid = `${id}`
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user