var info_file = function() {
var me = "file";
function podComment(parent) {
if (parent.playlistinfo.type == 'podcast' && parent.playlistinfo.Comment) {
return '
';
}
return '';
}
function createInfoFromPlayerInfo(info, parent) {
var html = "";
var file = decodeURI(info.file);
debug.log("FILE INFO","Decoded File Name is",file);
file = file.replace(/^file:\/\//, '');
var filetype = "";
if (file) {
var n = file.match(/.*\.(.*?)$/);
if (n) {
filetype = n[n.length-1];
filetype = filetype.toLowerCase();
if (filetype.match(/\/|\?|\=/)) {
filetype = "";
}
}
}
if (file == "null" || file == "undefined") file = "";
html += '
';
html += '
Format Information
';
html += '
'+language.gettext("info_file")+'
'+file;
if (file.match(/^http:\/\/.*item\/\d+\/file/)) html += ' '+language.gettext("info_from_beets")+'';
if (info.file) {
var f = info.file.match(/^podcast[\:|\+](http.*?)\#/);
if (f && f[1]) {
html += ''+
'';
}
}
html += '
';
if (filetype != "" && !file.match(/^http/)) {
html += '
'+language.gettext("info_format")+'
'+filetype+'
';
}
if (info.bitrate && info.bitrate != 'None' && info.bitrate != 0) {
html += '
'+language.gettext("info_bitrate")+'
'+info.bitrate+'
';
}
var ai = info.audio;
if (ai) {
var p = ai.split(":");
html += '
'+language.gettext("info_samplerate")+'
'+p[0]+' Hz, '+p[1]+' Bit, ';
if (p[2] == 1) {
html += language.gettext("info_mono");
} else if (p[2] == 2) {
html += language.gettext("info_stereo");
} else {
html += p[2]+' '+language.gettext("info_channels");
}
'
';
}
if (info.Date) {
if (typeof info.Date == "string") {
info.Date = info.Date.split(';');
}
html += '
'+language.gettext("info_date")+'
'+info.Date[0]+'
';
}
if (info.Genre) {
if (typeof info.Genre == "string") {
info.Genre = info.Genre.split(';');
}
html += '
'+language.gettext("info_genre")+'
'+info.Genre.join(', ')+'
';
}
if (info.Performer) {
if (typeof info.Performer == "object") {
info.Performer = info.Performer.join(';');
}
html += '
';
}
if (info.Comment) {
if (typeof info.Comment == "object") {
info.Comment = info.Comment.join(' ');
}
html += '
'+language.gettext("info_comment")+'
'+info.Comment+'
';
}
if (parent.playlistinfo.type == 'stream' && parent.playlistinfo.stream) {
html += '
'+language.gettext("info_comment")+'
'+parent.playlistinfo.stream+'
';
}
html += '
';
return html;
}
function createInfoFromBeetsInfo(data) {
var html = "";
debug.log("FILE PLUGIN","Doing info from Beets server");
var file = decodeURIComponent(player.status.file);
var gibbons = [ 'year', 'genre', 'label', 'disctitle', 'encoder'];
if (!file) { return "" }
html += '
';
html += '
Format Information
';
html += '
'+language.gettext("info_file")+'
'+file;
html += ' '+language.gettext("info_from_beets")+'';
html = html +'
';
html += '
'+language.gettext("info_format")+'
'+data.format+'
';
if (data.bitrate) html += '
'+language.gettext("info_bitrate")+'
'+data.bitrate+'
';
html += '
'+language.gettext("info_samplerate")+'
'+data.samplerate+' Hz, '+data.bitdepth+' Bit, ';
if (data.channels == 1) {
html += language.gettext("info_mono");
} else if (data.channels == 2) {
html = html +language.gettext("info_stereo");
} else {
html += data.channels +' '+language.gettext("info_channels");
}
html += '
';
$.each(gibbons, function (i,g) {
if (data[g]) html += '
'+language.gettext("info_"+g)+'
'+data[g]+'
';
});
if (data.composer) html += '
'+language.gettext("info_composers")+'
'+data.composer+'
';
if (data.comments) html += '
'+language.gettext("info_comment")+'
'+data.comments+'
';
html += '
';
return html;
}
return {
getRequirements: function(parent) {
return [];
},
collection: function(parent, artistmeta, albummeta, trackmeta) {
debug.trace("FILE PLUGIN", "Creating data collection");
var self = this;
var displaying = false;
this.displayData = function() {
displaying = true;
self.doBrowserUpdate();
browser.Update(null, 'album', me, parent.nowplayingindex,
{ name: "", link: "", data: null }
);
browser.Update(null, 'artist', me, parent.nowplayingindex,
{ name: "", link: "", data: null }
);
}
this.stopDisplaying = function() {
displaying = false;
}
this.handleClick = function(source, element, event) {
if (element.hasClass("clicksetrating")) {
nowplaying.setRating(event);
} else if (element.hasClass("clickaddtocollection")) {
nowplaying.addTrackToCollection(event, parent.nowplayingindex);
} else if (element.hasClass("clickremtag")) {
nowplaying.removeTag(event, parent.nowplayingindex);
} else if (element.hasClass("clickaddtags")) {
tagAdder.show(event, parent.nowplayingindex);
}
}
this.populate = function() {
if (trackmeta.fileinfo === undefined) {
var file = parent.playlistinfo.file;
var m = file.match(/^beets:library:track(:|;)(\d+)/)
if (m && m[2] && prefs.beets_server_location != '') {
debug.trace("FILE PLUGIN","File is from beets server",m[2]);
self.updateBeetsInformation(m[2]);
} else {
setTimeout(function() {
player.controller.do_command_list([], self.updateFileInformation)
}, 1000);
}
} else {
debug.mark("FILE PLUGIN",parent.nowplayingindex,"is already populated");
}
}
this.updateFileInformation = function() {
trackmeta.fileinfo = {beets: null, player: cloneObject(player.status)};
debug.log("FILE PLUGIN","Doing update from",trackmeta);
trackmeta.lyrics = null;
player.controller.checkProgress();
self.doBrowserUpdate();
}
this.updateBeetsInformation = function(thing) {
// Get around possible same origin policy restriction by using a php script
$.getJSON('browser/backends/getBeetsInfo.php', 'uri='+thing)
.done(function(data) {
debug.trace("FILE PLUGIN",'Got info from beets server',data);
trackmeta.fileinfo = {beets: data, player: null};
if (data.lyrics) {
debug.shout("FILE PLUGIN","Got lyrics from Beets Server");
trackmeta.lyrics = data.lyrics;
} else {
trackmeta.lyrics = null;
}
self.doBrowserUpdate();
})
.fail( function() {
debug.error("FILE PLUGIN", "Error getting info from beets server");
self.updateFileInformation();
});
}
this.ratingsInfo = function() {
var html = "";
debug.shout("FILE PLUGIN","Doing the monkey spanner",trackmeta);
if (trackmeta.usermeta) {
html += '
';
html += '
Collection Information
';
if (typeof trackmeta.usermeta.Playcount != 'undefined') {
html += '
';
switch (trackmeta.usermeta.Playcount) {
case '0':
html += language.gettext('played_never');
break
case '1':
html += language.gettext('played_once');
break
case '2':
html += language.gettext('played_twice');
break
default:
html += language.gettext('played_n',[trackmeta.usermeta.Playcount]);
break
}
html += '
';
}
if (typeof trackmeta.usermeta.Last != 'undefined' && trackmeta.usermeta.Last != 0) {
var t = parseInt(trackmeta.usermeta.Last) * 1000;
var d = new Date(t);
var s = d.toLocaleTimeString(getLocale(), { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
html += '
'+language.gettext('played_last',[s]);
html += '
';
}
if (prefs.player_backend == 'mopidy') {
html += '
';
if (trackmeta.usermeta.isSearchResult < 2 && trackmeta.usermeta.Hidden == 0) {
html += 'This track is in the Music Collection';
} else {
html += 'This track is not in the Music Collection. Click to add it';
}
html += '
';
}
if (trackmeta.usermeta.isSearchResult < 2 && trackmeta.usermeta.Hidden == 0) {
var t = parseInt(trackmeta.usermeta.DateAdded) * 1000;
var d = new Date(t);
var s = d.toLocaleDateString(getLocale(), { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
html += '
'+language.gettext('added_on',[s]);
html += '
';
}
html += '
Rating:
';
html += '';
html += '';
html += '
';
html += '
'+language.gettext("musicbrainz_tags")+'
';
for(var i = 0; i < trackmeta.usermeta.Tags.length; i++) {
if (trackmeta.usermeta.Tags[i] != '') {
html += ''+trackmeta.usermeta.Tags[i]+' ';
}
}
html += '
';
}
html += '
';
return html;
}
this.doBrowserUpdate = function() {
if (displaying && trackmeta.fileinfo !== undefined) {
var data = '
';
// data += '';
data += '
';
data += (trackmeta.fileinfo.player !== null) ? createInfoFromPlayerInfo(trackmeta.fileinfo.player, parent) : createInfoFromBeetsInfo(trackmeta.fileinfo.beets);
data += '