diff --git a/XMLGenerator.js b/XMLGenerator.js index 37bf02a..4f7d272 100755 --- a/XMLGenerator.js +++ b/XMLGenerator.js @@ -528,6 +528,52 @@ function generateScrobbleXML(type, id, UDID, url, label, callback){ callback(xw.toString()); } +function generateScrobbleXMLOLD(type, id, UDID, url, label, callback){ + var XMLWriter = require('xml-writer'); + xw = new XMLWriter; + xw.startDocument(version='1.0', encoding='UTF-8'); + xw.startElement('atv') + .startElement('head') + .startElement('script') + .writeAttribute('src', 'http://trailers.apple.com/js/utils.js') + .endElement() + .endElement() + .startElement('body') + .startElement('optionDialog') + .writeAttribute('id', 'scrobble.optionDialog') + .startElement('header') + .startElement('simpleHeader') + .writeElement('title', 'Favorites') + .writeElement('subtitle', 'Add or remove movie from your Favorites.') + .endElement() + .endElement() + .startElement('menu') + .startElement('sections') + .startElement('menuSection') + .startElement('header') + .startElement('horizontalDivider') + .writeAttribute('alignment', 'left') + .writeElement('title', '') + .endElement() + .endElement() + .startElement('items') + .startElement('oneLineMenuItem') + .writeAttribute('id', 'item') + .writeAttribute('onSelect', "atv.unloadPage();atv.loadURL('http://trailers.apple.com/" + url + "?type=" + type + '&id=' + id + '&UDID=' + UDID + "');") + .writeElement('label', label) + .endElement() + xw.endElement() + .endElement() + .endElement() + .endElement() + .endElement() + .endElement() + .endElement(); + xw.endDocument(); + logger.Debug(xw.toString()); + callback(xw.toString()); +} + function generateMovieParadeXML(sort_by, callback){ var XMLWriter = require('xml-writer'); xw = new XMLWriter; @@ -2051,6 +2097,7 @@ exports.generateSettingsXML = generateSettingsXML; exports.generateGenre = generateGenre; exports.generateMoviesXML = generateMoviesXML; exports.generateScrobbleXML = generateScrobbleXML; +exports.generateScrobbleXMLOLD = generateScrobbleXMLOLD; exports.generateMoviePrePlayXML = generateMoviePrePlayXML; exports.generateMoviePrePlayFanartXML = generateMoviePrePlayFanartXML; exports.generateMovieParadeXML = generateMovieParadeXML; diff --git a/assets/js/utils.js b/assets/js/utils.js index e170447..f2ed8bf 100755 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -11,7 +11,7 @@ if( atv.Document ) { return elements[0]; } return undefined; - } + } } @@ -36,7 +36,7 @@ if( atv.Element ) { if (!String.prototype.format) { String.prototype.format = function() { var args = arguments; - return this.replace(/{(\d+)}/g, function(match, number) { + return this.replace(/{(\d+)}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); }; @@ -87,13 +87,13 @@ function loadMore(type, sort_by, page){ if (type == "movie"){ newPoster.setAttribute('onPlay', 'addUDIDtoQuery("http://trailers.apple.com/MoviePrePlay.xml?torrentID=' + response[i].id + '&imdb=' + response[i].imdb_code + '")'); newPoster.setAttribute('onSelect', 'addUDIDtoQuery("http://trailers.apple.com/MoviePrePlay.xml?torrentID=' + response[i].id + '&imdb=' + response[i].imdb_code + '")'); - } else if (type == "tv") { + } else if (type == "tv") { //var url = 'http://trailers.apple.com/seasons.xml?imdb=' + shows[i].imdb_id + '&title=' + shows[i].title.replace(/ /g,"%20"); newPoster.setAttribute('onPlay', 'addUDIDtoQuery("http://trailers.apple.com/seasons.xml?imdb=' + response[i].imdb_id + '&title=' + response[i].title.replace(/ /g,"%20") + '")'); newPoster.setAttribute('onSelect', 'addUDIDtoQuery("http://trailers.apple.com/seasons.xml?imdb=' + response[i].imdb_id + '&title=' + response[i].title.replace(/ /g,"%20") + '")'); } newPoster.setAttribute('onHoldSelect', 'scrobbleMenu("http://trailers.apple.com/scrobble.xml?type=' + type + '&id=' + response[i].id + '")'); - + var title = document.makeElementNamed('title'); title.textContent = response[i].title; newPoster.appendChild(title); @@ -124,18 +124,18 @@ function loadMore(type, sort_by, page){ { fv = atv.device.softwareVersion.split("."); firmVer = fv[0] + "." + fv[1]; + var url = url + "&UDID="+atv.device.udid if (parseFloat(firmVer) < 6.0) { // firmware <6.0 // load standard scrobble menu - atv.loadURL(url); + atv.loadURL(url + "&version=old"); } else { // firmware >=6.0 // load scrobble menu xml - // parse the xml and build a popup context menu - var url = url + "&UDID="+atv.device.udid + // parse the xml and build a popup context menu var req = new XMLHttpRequest(); req.onreadystatechange = function() { @@ -156,19 +156,30 @@ function loadMore(type, sort_by, page){ } xmlDoc = atv.parseXML(xml); atv.contextMenu.load(xmlDoc); - } + } } catch(e) { req.abort(); } } - + req.open('GET',unescape(url), false); req.send(); } } +/* + * Force the generation of the old Scrobble Menu. This is useful when a context menu is not allowed (ie. from a search window) + */ + function oldScrobbleMenu(url) +{ + fv = atv.device.softwareVersion.split("."); + firmVer = fv[0] + "." + fv[1]; + var url = url + "&UDID="+atv.device.udid; + atv.loadURL(url + "&version=old"); +} + /* * Add UDID to URL */ @@ -216,4 +227,4 @@ function errorXML(title, err){ '; xmlDoc = atv.parseXML(errorXML); atv.loadXML(xmlDoc); -} \ No newline at end of file +} diff --git a/webserver.js b/webserver.js index 88455ff..6a06106 100755 --- a/webserver.js +++ b/webserver.js @@ -72,12 +72,12 @@ function startWebServer(localIp) { logger.Debug('=== Ending MoviePlay.xml Generation ==='); if (data.isMP4){ var playXML = xml.generatePlayXML({ - url: torrent.getURL(), - title: decodeURIComponent(query.title), - desc: decodeURIComponent(query.desc), - image: query.poster, - subtitle: (query.subtitle || 'Off'), - subtitleSize: subtitleSize, + url: torrent.getURL(), + title: decodeURIComponent(query.title), + desc: decodeURIComponent(query.desc), + image: query.poster, + subtitle: (query.subtitle || 'Off'), + subtitleSize: subtitleSize, traktToken: token }); @@ -90,11 +90,11 @@ function startWebServer(localIp) { convertFile(query.hash, function(){ // As soon as the playlist file exists this will return so that we can start playing the episode. var playXML =xml.generatePlayXML({ - url: 'http://trailers.apple.com/converted/' + query.hash + '.m3u8', - title: decodeURIComponent(query.title), - desc: decodeURIComponent(query.desc), - image: query.poster, - subtitle: (query.subtitle || 'Off'), + url: 'http://trailers.apple.com/converted/' + query.hash + '.m3u8', + title: decodeURIComponent(query.title), + desc: decodeURIComponent(query.desc), + image: query.poster, + subtitle: (query.subtitle || 'Off'), subtitleSize: subtitleSize, traktToken: token }); @@ -464,22 +464,42 @@ function startWebServer(localIp) { var aTVSettings = require('./settings.js'); var checkFavorite = aTVSettings.checkFavorite(query.type, query.id, query.UDID); - if (checkFavorite){ - response.writeHead(200, {'Content-Type': 'text/xml'}); - logger.Debug('=== Starting scrobble.xml Generation ==='); - xml.generateScrobbleXML(query.type, query.id, query.UDID, 'removeFavorite.xml', 'Remove from Favorites', function(xmlstring){ - logger.Debug('=== Ending scrobble.xml Generation ==='); - response.write(xmlstring); - response.end(); - }) + if (query.version == 'old'){ + if (checkFavorite){ + response.writeHead(200, {'Content-Type': 'text/xml'}); + logger.Debug('=== Starting scrobble.xml Generation ==='); + xml.generateScrobbleXMLOLD(query.type, query.id, query.UDID, 'removeFavorite.xml', 'Remove from Favorites', function(xmlstring){ + logger.Debug('=== Ending scrobble.xml Generation ==='); + response.write(xmlstring); + response.end(); + }) + } else { + response.writeHead(200, {'Content-Type': 'text/xml'}); + logger.Debug('=== Starting scrobble.xml Generation ==='); + xml.generateScrobbleXMLOLD(query.type, query.id, query.UDID, 'addFavorite.xml', 'Add to Favorites', function(xmlstring){ + logger.Debug('=== Ending scrobble.xml Generation ==='); + response.write(xmlstring); + response.end(); + }) + } } else { - response.writeHead(200, {'Content-Type': 'text/xml'}); - logger.Debug('=== Starting scrobble.xml Generation ==='); - xml.generateScrobbleXML(query.type, query.id, query.UDID, 'addFavorite.xml', 'Add to Favorites', function(xmlstring){ - logger.Debug('=== Ending scrobble.xml Generation ==='); - response.write(xmlstring); - response.end(); - }) + if (checkFavorite){ + response.writeHead(200, {'Content-Type': 'text/xml'}); + logger.Debug('=== Starting scrobble.xml Generation ==='); + xml.generateScrobbleXML(query.type, query.id, query.UDID, 'removeFavorite.xml', 'Remove from Favorites', function(xmlstring){ + logger.Debug('=== Ending scrobble.xml Generation ==='); + response.write(xmlstring); + response.end(); + }) + } else { + response.writeHead(200, {'Content-Type': 'text/xml'}); + logger.Debug('=== Starting scrobble.xml Generation ==='); + xml.generateScrobbleXML(query.type, query.id, query.UDID, 'addFavorite.xml', 'Add to Favorites', function(xmlstring){ + logger.Debug('=== Ending scrobble.xml Generation ==='); + response.write(xmlstring); + response.end(); + }) + } } staticFile = false; } else if(pathname.indexOf("altersetting.xml") >= 0){