Skip to content

Commit

Permalink
fix: Update Favorites menu to support Apple TV's lower than v6.0 Fixes
Browse files Browse the repository at this point in the history
…#209
  • Loading branch information
OstlerDev committed Aug 31, 2015
1 parent 1749c36 commit 779b58a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 36 deletions.
47 changes: 47 additions & 0 deletions XMLGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 21 additions & 10 deletions assets/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if( atv.Document ) {
return elements[0];
}
return undefined;
}
}
}


Expand All @@ -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;
});
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
{
Expand All @@ -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
*/
Expand Down Expand Up @@ -216,4 +227,4 @@ function errorXML(title, err){
';
xmlDoc = atv.parseXML(errorXML);
atv.loadXML(xmlDoc);
}
}
72 changes: 46 additions & 26 deletions webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand All @@ -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
});
Expand Down Expand Up @@ -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){
Expand Down

0 comments on commit 779b58a

Please sign in to comment.