Skip to content

Commit

Permalink
Merge pull request #47 from gnehs/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gnehs authored Sep 1, 2018
2 parents 8cc8a6e + d50c24c commit 6524d87
Show file tree
Hide file tree
Showing 19 changed files with 885 additions and 224 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ typings/
config.json
sessions/*
playlist.json
package-lock.json
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ FROM node:10-alpine
RUN mkdir /app
WORKDIR /app

RUN apk add --no-cache make gcc g++ python git
RUN apk add --no-cache make gcc g++ python git sed
RUN git clone https://github.com/gnehs/PokaPlayer.git .
RUN npm install --production

RUN mkdir ./NeteaseCloudMusicApi
RUN git clone https://github.com/Binaryify/NeteaseCloudMusicApi.git /NeteaseCloudMusicApi
RUN npm install /NeteaseCloudMusicApi
RUN sed -i 's/"User-Agent": randomUserAgent()/"User-Agent": randomUserAgent(), "X-Real-IP":`36\.\${Math\.floor(Math\.random() \* 64) + 128}\.\${Math\.floor(Math\.random() \* 255) + 1}\.\${Math.floor(Math\.random() \* 255) + 1}`/g' /NeteaseCloudMusicApi/util/util.js

RUN npm install forever -g

ENV NODE_ENV=production

EXPOSE 3000

CMD ["npm","start"]
RUN echo "cd /app" > /start.sh
RUN echo 'PORT=4000 forever start /NeteaseCloudMusicApi/app.js -w /NeteaseCloudMusicApi/package.json -w /NeteaseCloudMusicApi/util/util.js ' >> /start.sh
RUN echo 'forever -c "npm start" ./' >> /start.sh
CMD ["sh", "/start.sh"]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ PokaPlayer 是 Synology Audio Station 的新朋友!

Repo 內附的背景來自 [Free Set of 40+ Material Design Backgrounds](https://www.oxygenna.com/news/brand-new-set-of-40-material-design-backgrounds)

## 貢獻者
## 貢獻者 Contributors

[@gnehs](https://github.com/gnehs)
[@rexx0520](https://github.com/rexx0520)
[@coin3x](https://github.com/coin3x)
[@hang333](https://github.com/hang333)
[@hugwalk](https://github.com/hugwalk)
22 changes: 22 additions & 0 deletions config-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,27 @@
"jwtExpirePeriod": 600,
"userFilesDir": "./users",
"dbType": "fs"
},
"Netease2": {
"topPlaylist": {
"enabled": false,
"category": "ACG",
"limit": 5,
"order": "hot" // hot or new
},
"hqPlaylist": {
"enabled": false,
"category": "ACG",
"limit": 5
},
"dailyRecommend": {
"songs": false,
"playlist": false
},
"login": {
"phone": null,
"email": null,
"password": null
}
}
}
65 changes: 7 additions & 58 deletions dataModule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs')
const path = require('path');
const config = require('./config.json'); // 設定檔
const playlist = require('./playlist.json'); // 歌單
const router = require('express').Router()
const FileStore = require('session-file-store')(require('express-session')); // session
const session = require('express-session')({
Expand Down Expand Up @@ -36,7 +37,7 @@ router.use(session);
let moduleList = {};
fs.readdir(__dirname + "/dataModule", (err, files) => {
if (err) return console.error(err)
files.forEach(file => {
files.forEach(async file => {
if (path.extname(file) == '.js') {
let uri = __dirname + "/dataModule/" + file,
_module = require(uri)
Expand All @@ -45,10 +46,9 @@ fs.readdir(__dirname + "/dataModule", (err, files) => {
"active": Object.keys(_module),
"js": uri
}
if (moduleData.active.indexOf('onLoaded') > -1) { // 如果模組想要初始化
_module.onLoaded()
}
moduleList[moduleData.name] = moduleData;
let enabled = moduleData.active.indexOf('onLoaded') > -1 ? await _module.onLoaded() : true
if (enabled)
moduleList[moduleData.name] = moduleData;
}
});
})
Expand All @@ -68,57 +68,6 @@ router.use((req, res, next) => {
else
next();
});

/*
song {
name:'',
artist:'',
album:'',
cover:'',
url:'',
bitrate: 320000,
lrc:'',
source:'',
id:'',
}
album {
name:'',
artist:'',
year:'',
cover:'',
source:'',
id:''
}
artist {
name:'',
source:'',
cover:'',
id:''
}
composer {
name:'',
source:'',
cover:'',
id:''
}
folder {
name:'',
source:'',
id:''
}
playlist {
name: '',
source:'',
id: ''
}
lyrics {
name:''
artist:''
source:''
id:'',
lyric:''
}
*/
//-----------------------------> 首頁
// 取得想推薦的東西(?
router.get('/home/', async(req, res) => {
Expand All @@ -128,7 +77,7 @@ router.get('/home/', async(req, res) => {
let x = moduleList[Object.keys(moduleList)[i]]
let y = require(x.js)
if (x.active.indexOf('getHome') > -1) {
let result = await y.getHome() || null
let result = await y.getHome(playlist) || null
if (result) {
if (result.folders)
for (i = 0; i < result.folders.length; i++) resData.folders.push(result.folders[i])
Expand Down Expand Up @@ -277,7 +226,7 @@ router.get('/playlists/', async(req, res) => {
let x = moduleList[Object.keys(moduleList)[i]]
let y = require(x.js)
if (x.active.indexOf('getPlaylists') > -1) {
let list = await y.getPlaylists() || null
let list = await y.getPlaylists(playlist) || null
if (list) {
for (i = 0; i < list.playlists.length; i++) r.playlists.push(list.playlists[i])
}
Expand Down
31 changes: 18 additions & 13 deletions dataModule/dsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,31 @@ function parseLyrics(lyrics) {
return r
}
async function onLoaded() {
login();
schedule.scheduleJob("'* */12 * * *'", async function() {
console.log("[DataModules][DSM] 正在重新登入...")
login();
});
return await login();
}
async function login() {
let url = `${dsmURL}/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=1&account=${config.DSM.account}&passwd=${config.DSM.password}&session=AudioStation&format=cookie`
console.log("[DataModules][DSM] 正在登入...")
request(url, async function(error, res, body) {
if (!error && res.statusCode == 200) {
if (JSON.parse(body).success) {
console.log("[DataModules][DSM] 登入成功!")
} else {
console.error("[DataModules][DSM] 登入失敗,請檢查您的設定檔是否正確")
}
} else {
console.error("[DataModules][DSM] 登入時遇到錯誤:", error)
}
});
if (!config.DSM.account && !config.DSM.password) {
console.error("[DataModules][DSM] 登入失敗,未設定帳號密碼")
return false
}
let result = await getAPI("auth.cgi", "SYNO.API.Auth", "Login", [
{ key: "account", "value": config.DSM.account },
{ key: "passwd", "value": config.DSM.password },
{ key: "session", "value": "AudioStation" },
{ key: "format", "value": "cookie" }
])
if (result.success) {
console.log("[DataModules][DSM] 登入成功!")
return true
} else {
console.error("[DataModules][DSM] 登入失敗,請檢查您的設定檔是否正確")
return false
}
}
//- API 請求
async function getAPI(CGI_PATH, API_NAME, METHOD, PARAMS_JSON = [], VERSION = 1) {
Expand Down
File renamed without changes.
Loading

0 comments on commit 6524d87

Please sign in to comment.