self.player.on('playing', function(song) { var isValidSong = song.title && song.sid; self.status = 'playing'; // update playing label menu.update('header', color.green('>')); // update song infomation menu.update(channel.index, template.song(song)); // logging songs history if (isValidSong) { var updates = {}; updates[song.sid] = song; try { fs.updateJSON(this.rc.history, updates); } catch (err) { // error must be logged in a private place. } } // print LRC if needed. if (self.isShowLrc) { if (self.lrc) self.lrc.stop(); geci.fetch(song, function(err, lrc) { if (err) return menu.update('header', color.grey(errors.lrc_notfound + err.toString())); if (!lrc) return menu.update('header', color.grey(errors.lrc_notfound)); self.lrc = geci.print(lrc, function(line, extra) { menu.update(channel.index, template.song(song, line)); }); }); } // 没有对尝试获取列表失败进行处理,如果失败2次,则不会再播放任何歌曲 if (song._id < self.player.list.length - 1) return false; return self.fetch(channel, account); });
function updateProxy(profile) { try { fs.updateJSON(fm.rc.profile, profile); } catch (err) { if (!utils.noSuchFile(err.message)) return consoler.error(err); fs.writeJSON(fm.rc.profile, profile); } consoler.success('HTTP PROXY已经成功修改为 ' + profile.http_proxy); var f = new Fm; return f.init(exports.ready); }
}, function(err, account) { if (err) return consoler.error(err); var configs = {}; configs.account = account; try { fs.updateJSON(fm.rc.profile, configs); } catch (err) { if (!utils.noSuchFile(err.message)) return consoler.error(err); fs.writeJSON(fm.rc.profile, configs); } return ready(account); });
}, function(err, account) { if (err) return consoler.error(err); var configs = {}; configs.account = account; try { fs.updateJSON(fm.rc.profile, configs); consoler.success('欢迎,' + account.user_name + '。您的豆瓣账户已经成功修改为:' + account.email); fm.init(exports.ready); } catch (err) { return consoler.error(err); } });
exports.home = function(fm, argv) { try { var home = argv[3] || process.cwd(); fs.updateJSON(fm.rc.profile, { home: home }); consoler.success('下载目录已成功修改为 ' + home); var f = new Fm; return f.init(exports.ready); } catch (err) { return consoler.error(err); } }
function updatePath(profile) { try { fs.updateJSON(fm.path.profile, profile) } catch (err) { if (!utils.noSuchFile(err.message)) return consoler.error(err) fs.writeJSON(fm.path.profile, profile) } consoler.success('下载目录已成功修改为 ' + profile.home) return (new Fm).init(exports.ready) }
sdk.fm.auth(form, (err, account) => { if (err) return consoler.error(err); var configs = { account } try { fs.updateJSON(fm.path.profile, configs) } catch (err) { if (!utils.noSuchFile(err.message)) return consoler.error(err) fs.writeJSON(fm.path.profile, configs) } return getReady(account) })
function onPlaying(song) { var isValidSong = song.title && song.sid; self.status = 'playing'; // Update playing label menu.update('header', color.green('>')); // Update song infomation menu.update(channel.index, template.song(song)); // Logging songs history if (isValidSong) { var updates = {}; updates[song.sid] = song; try { fs.updateJSON(self.path.history, updates); } catch (err) { // Errors must be logged in a private place. } } // Print LRC if needed. if (self.isShowLrc) { if (self.lrc) self.lrc.stop(); geci.fetch(song, printLrc); function printLrc(err, lrc) { if (err) return menu.update('header', color.grey(errors.lrc_notfound + err.toString())); if (!lrc) return menu.update('header', color.grey(errors.lrc_notfound)); self.lrc = geci.print(lrc, (line, extra) => { menu.update(channel.index, template.song(song, line)); }); } } // TODO: Still trying after failed two times. if (song._id < self.player.list.length - 1) return false; return self.fetch(channel, account); }
/** * [Playing songs when everything is ready] * @param {Object} channel * @param {Object} account * @return {} */ play(channel, account) { var self = this var menu = this.menu var isVaildAccount = account && account.token var privateMhz = isChannel('private', channel.channel_id) && !isVaildAccount // Check if this kind of mHz is private if (privateMhz) return menu.update('header', errors.account_missing) // Clear last label if (this.status === 'fetching' || this.status === 'downloading') return if (this.status === 'playing' || this.status === 'error') { if (typeof(this.channel) != undefined) menu.clear(this.channel) if (this.player) { this.player.stop() delete this.player } } // Clear label status menu.clear('header') this.channel = channel.index this.status = 'fetching' menu.update(channel.index, template.listing()) try { fs.updateJSON(this.path.profile, { lastChannel: channel }) } catch (err) {}; // Start fetching songs this.fetch(channel, account, (err, songs, result) => { if (err) { this.status = 'error'; return menu.update(channel.index, color.red(err.toString())); } // Mark a `PRO` label on logo if (result && !result.warning) menu.update('header', color.inverse(' PRO ')); this.status = 'ready'; this.player = new Player(songs, { src: 'url', cache: true, downloads: this.home, http_proxy: this.http_proxy }); this.player.play(); this.player.on('downloading', onDownloading); this.player.on('playing', onPlaying); function onDownloading(url) { self.status = 'downloading'; menu.update(channel.index, template.loading()); } function onPlaying(song) { var isValidSong = song.title && song.sid; self.status = 'playing'; // Update playing label menu.update('header', color.green('>')); // Update song infomation menu.update(channel.index, template.song(song)); // Logging songs history if (isValidSong) { var updates = {}; updates[song.sid] = song; try { fs.updateJSON(self.path.history, updates); } catch (err) { // Errors must be logged in a private place. } } // Print LRC if needed. if (self.isShowLrc) { if (self.lrc) self.lrc.stop(); geci.fetch(song, printLrc); function printLrc(err, lrc) { if (err) return menu.update('header', color.grey(errors.lrc_notfound + err.toString())); if (!lrc) return menu.update('header', color.grey(errors.lrc_notfound)); self.lrc = geci.print(lrc, (line, extra) => { menu.update(channel.index, template.song(song, line)); }); } } // TODO: Still trying after failed two times. if (song._id < self.player.list.length - 1) return false; return self.fetch(channel, account); } }) }
/** * [Playing songs when everything is ready] * @param {[type]} channel [description] * @param {[type]} account [description] * @return {[type]} [description] */ function play(channel, account) { var self = this; var menu = self.menu; var isVaildAccount = account && account.token; var privateMhz = isChannel('private', channel.channel_id) && !isVaildAccount; // Check if this kind of mHz is private if (privateMhz) return menu.update('header', errors.account_missing); // clear last label if (self.status === 'fetching' || self.status === 'downloading') return; if (self.status === 'playing' || self.status === 'error') { if (typeof(self.channel) != undefined) menu.clear(self.channel); if (self.player) { self.player.stop(); delete self.player; } } // clear label status menu.clear('header'); self.channel = channel.index; self.status = 'fetching'; menu.update(channel.index, template.listing()); try { fs.updateJSON(self.rc.profile, { lastChannel: channel }); } catch (err) {}; // start fetching songs self.fetch(channel, account, function(err, songs, result) { if (err) { self.status = 'error'; return menu.update(channel.index, color.red(err.toString())); } // mark PRO account on logo if (result && !result.warning) menu.update('header', color.inverse(' PRO ')); self.status = 'ready'; self.player = new Player(songs, { src: 'url', cache: true, downloads: self.home, http_proxy: self.http_proxy }); self.player.play(); self.player.on('downloading', function(url) { self.status = 'downloading'; menu.update(channel.index, template.loading()); }); // update template self.player.on('playing', function(song) { var isValidSong = song.title && song.sid; self.status = 'playing'; // update playing label menu.update('header', color.green('>')); // update song infomation menu.update(channel.index, template.song(song)); // logging songs history if (isValidSong) { var updates = {}; updates[song.sid] = song; try { fs.updateJSON(self.rc.history, updates); } catch (err) { // error must be logged in a private place. } } // print LRC if needed. if (self.isShowLrc) { if (self.lrc) self.lrc.stop(); geci.fetch(song, function(err, lrc) { if (err) return menu.update('header', color.grey(errors.lrc_notfound + err.toString())); if (!lrc) return menu.update('header', color.grey(errors.lrc_notfound)); self.lrc = geci.print(lrc, function(line, extra) { menu.update(channel.index, template.song(song, line)); }); }); } // 没有对尝试获取列表失败进行处理,如果失败2次,则不会再播放任何歌曲 if (song._id < self.player.list.length - 1) return false; return self.fetch(channel, account); }); }); }