1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| const request = require('./util/request') const login = require('./module/login') const level = require('./module/level') const signin = require('./module/daily_signin') const recommend_resource = require('./module/recommend_resource') const playlist_detail = require('./module/playlist_detail') const scrobble = require('./module/scrobble') const personFm = require('./module/personal_fm')
const { cookieToJson } = require('./util/index') const COOKIE = "os=pc;osver=Microsoft-Windows-10-Professional-build-10586-64bit;appver=2.0.3.131777;channel=netease;__remember_me=true" class App { constructor() { this.getSongidIndex = 0; }
async login(username, md5_password) { const regexp = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; this.query = { email: username, md5_password, cookie: cookieToJson(COOKIE) } const isMail = regexp.test(username); if (!isMail) { delete this.query.email;
if (username.length === 11) { this.query.phone = username } else { [, this.query.phone] = username.split(2) } }
const result = await login(this.query, request)
if (result.status === 200) { this.query.cookie = result.body.cookie await signin(this.query, request).catch(err => err) await signin({ ...this.query, type: 1 }, request).catch(err => err) }
const levelData = await level(this.query, request)
this.config = {} this.config.level = levelData.body.data.level; this.config.nextPlayCount = levelData.body.data.nextPlayCount this.config.nowPlayCount = levelData.body.data.nowPlayCount this.config.defaultPlayCount = this.config.nowPlayCount; this.config.nowLoginCount = levelData.body.data.nowLoginCount this.config.nextLoginCount = levelData.body.data.nextLoginCount
this.config.diffPlayCount = this.config.nextPlayCount - this.config.nowPlayCount this.config.diffLoginCount = this.config.nextLoginCount - this.config.nowLoginCount
this.config.diffNextLevelPlayCount = this.config.diffPlayCount < 300 ? 300 - this.config.diffPlayCount : 0 return }
async recommend() { const json = await recommend_resource(this.query, request) return json.body.recommend.map(res => res.id) || [] }
async PersonFm() { return (await personFm(this.query, request)).body.data; }
async getSongid(playlist_id) { if (playlist_id.length <= this.getSongidIndex) { return [] } const singleItem = playlist_id[this.getSongidIndex]; this.getSongidIndex++; const result = await playlist_detail({ ...this.query, id: singleItem }, request); return result.body.playlist.trackIds }
async punch(songidlist, time, timer) { if (songidlist.length === 0) { return time; } while (songidlist.length) { const singleSong = songidlist.splice(0, 1)[0] try { await scrobble({ ...this.query, sourceId: "", time: 240, id: singleSong.id }, request) } catch (err) { throw { len: songidlist.length + 1 } } await timer() } const levelData = await level(this.query, request) this.config.nowPlayCount = levelData.body.data.nowPlayCount if (levelData.body.data.level === this.config.level) { const result = this.config.nowPlayCount - this.config.defaultPlayCount return result } else if (levelData.body.data.level === 10) { return 300; } else { const result = this.config.diffNextLevelPlayCount + this.config.nowPlayCount + time return result } } }
process.on('unhandledRejection', (reason, p) => { console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); });
module.exports = App
|