var info_file = function() { var me = "file"; function podComment(parent) { if (parent.playlistinfo.type == 'podcast' && parent.playlistinfo.Comment) { return '
'+ language.gettext("info_comment").replace(':','')+'
'+parent.playlistinfo.Comment+'
'; } 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 += ''; html += ''; if (filetype != "" && !file.match(/^http/)) { html += ''; } if (info.bitrate && info.bitrate != 'None' && info.bitrate != 0) { html += ''; } var ai = info.audio; if (ai) { var p = ai.split(":"); html += ''; } if (info.Date) { if (typeof info.Date == "string") { info.Date = info.Date.split(';'); } html += ''; } if (info.Genre) { if (typeof info.Genre == "string") { info.Genre = info.Genre.split(';'); } html += ''; } if (info.Performer) { if (typeof info.Performer == "object") { info.Performer = info.Performer.join(';'); } html += ''; } if (info.Composer) { if (typeof info.Composer == "object") { info.Composer = info.Composer.join(';'); } html += ''; } if (info.Comment) { if (typeof info.Comment == "object") { info.Comment = info.Comment.join('
'); } html += ''; } if (parent.playlistinfo.type == 'stream' && parent.playlistinfo.stream) { html += ''; } html += '
Format Information
'+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 += '
'+language.gettext("info_format")+''+filetype+'
'+language.gettext("info_bitrate")+''+info.bitrate+'
'+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"); } '
'+language.gettext("info_date")+''+info.Date[0]+'
'+language.gettext("info_genre")+''+info.Genre.join(', ')+'
'+language.gettext("info_performers")+''+concatenate_artist_names(info.Performer.split(';'))+'
'+language.gettext("info_composers")+''+concatenate_artist_names(info.Composer.split(';'))+'
'+language.gettext("info_comment")+''+info.Comment+'
'+language.gettext("info_comment")+''+parent.playlistinfo.stream+'
'; 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 += ''; html += ''; html += ''; if (data.bitrate) html += ''; html += ''; $.each(gibbons, function (i,g) { if (data[g]) html += ''; }); if (data.composer) html += ''; if (data.comments) html += ''; html += '
Format Information
'+language.gettext("info_file")+''+file; html += ' '+language.gettext("info_from_beets")+''; html = html +'
'+language.gettext("info_format")+''+data.format+'
'+language.gettext("info_bitrate")+''+data.bitrate+'
'+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 += '
'+language.gettext("info_"+g)+''+data[g]+'
'+language.gettext("info_composers")+''+data.composer+'
'+language.gettext("info_comment")+''+data.comments+'
'; 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 += ''; if (typeof trackmeta.usermeta.Playcount != 'undefined') { 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 += ''; } if (prefs.player_backend == 'mopidy') { 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 += ''; } html += ''; html += ''; } html += '
Collection Information
'; 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 += '
'+language.gettext('played_last',[s]); 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 += '
'+language.gettext('added_on',[s]); html += '
Rating:'; 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 += '
'; 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 += '
'; data += '
'; data += self.ratingsInfo(); data += '
'; data += podComment(parent); data += '
'; browser.Update( null, 'track', me, parent.nowplayingindex, { name: trackmeta.name, link: "", data: data } ); browser.rePoint($('#tinfobox'), { itemSelector: '.brick', columnWidth: '.dingo', percentPosition: true }); } } } } }(); nowplaying.registerPlugin("file", info_file, "icon-library", "button_fileinfo");