Skip to content

Instantly share code, notes, and snippets.

@paulgrav
Created July 3, 2012 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulgrav/3043676 to your computer and use it in GitHub Desktop.
Save paulgrav/3043676 to your computer and use it in GitHub Desktop.
Gametrailers
diff --git a/ClickToPlugin.safariextension/killers/MTVNetworks.js b/ClickToPlugin.safariextension/killers/MTVNetworks.js
index ad46ef8..082f967 100644
--- a/ClickToPlugin.safariextension/killers/MTVNetworks.js
+++ b/ClickToPlugin.safariextension/killers/MTVNetworks.js
@@ -53,7 +53,7 @@ addKiller("MTVNetworks", {
"cms:episode:thedailyshow.com:": "context5",
"cms:episode:colbertnation.com:": "context7",
"cms:video:colbertnation.com:": "context8",
- "moses:video:gametrailers.com:": "context1",
+ "arc:video:gametrailers.com:": "context1",
"cms:item:southparkstudios.com:": "context1",
"cms:content:southparkstudios.com:": "context2",
"cms:video:comedycentral.com:": "context6",
@@ -129,10 +129,16 @@ addKiller("MTVNetworks", {
// No renditionsURLs ? Then we're probably not on mtv so we'll need to make the
// additional call that gets us the resource that contains the renditions.
- if( renditionsURLs.length == 0 )
- renditionsURLs = _this.getRenditionsURLsFromFeed( feedURL, data, callbackData, _this.processRenditions, callback);
- else
+ if( renditionsURLs.length == 0 ) {
+ if(mgid.indexOf('gametrailers') >= 0) {
+ feedURL = 'http://media.mtvnservices.com/player/html5/mediagen/?uri=' + mgid + '&device=iPad';
+ _this.getRenditionsURLsFromFeed( feedURL, data, callbackData, _this.processGametrailerRenditions, callback);
+ } else {
+ _this.getRenditionsURLsFromFeed( feedURL, data, callbackData, _this.processRenditions, callback);
+ }
+ } else {
_this.processRenditions( renditionsURLs, data, callbackData, callback );
+ }
};
xhr.send();
@@ -149,27 +155,34 @@ addKiller("MTVNetworks", {
item = items[i];
var itemContentTag = item.getElementsByTagNameNS('http://search.yahoo.com/mrss/','content');
+ var srcTag = item.getElementsByTagName('src');
- if( !itemContentTag.length )
- continue;
+ if( itemContentTag.length ) {
+ var renditionURL = itemContentTag[0].getAttribute('url');
- var renditionURL = itemContentTag[0].getAttribute('url');
+ // all renditionURLs happen to have have mediagen in their paths. This check
+ // is to avoid adding URLs that don't return renditions.
+ if( /mediagen/i.test(renditionURL) ) {
- // all renditionURLs happen to have have mediagen in their paths. This check
- // is to avoid adding URLs that don't return renditions.
- if( /mediagen/i.test(renditionURL) ) {
+ renditionsURLs.push( renditionURL );
+ playlistItem = {};
- renditionsURLs.push( renditionURL );
- playlistItem = {};
+ if( item.getElementsByTagNameNS('http://search.yahoo.com/mrss/','thumbnail').length > 0 )
+ playlistItem.poster = (item.getElementsByTagNameNS('http://search.yahoo.com/mrss/','thumbnail')[0]).getAttribute('url');
- if( item.getElementsByTagNameNS('http://search.yahoo.com/mrss/','thumbnail').length > 0 )
- playlistItem.poster = (item.getElementsByTagNameNS('http://search.yahoo.com/mrss/','thumbnail')[0]).getAttribute('url');
+ if( item.getElementsByTagName('title').length > 0 )
+ playlistItem.title = (item.getElementsByTagName('title')[0]).textContent;
- if( item.getElementsByTagName('title').length > 0 )
- playlistItem.title = (item.getElementsByTagName('title')[0]).textContent;
+ playlistItem.sources = [];
+ callbackData.playlist.push(playlistItem);
+ }
+ }
+ if(srcTag.length) {
+ playlistItem = {};
playlistItem.sources = [];
callbackData.playlist.push(playlistItem);
+ renditionsURLs.push((srcTag[0]).textContent);
}
}
@@ -184,12 +197,24 @@ addKiller("MTVNetworks", {
var doc = new DOMParser().parseFromString(this.responseText.replace(/^\s+/,''), "text/xml");
var renditionsURLs = _this.getRenditionsURLsFromDoc( doc, data, callbackData, callback);
+
+
if( processCallback )
return processCallback(renditionsURLs, data, callbackData, callback);
};
xhr2.send();
return;
},
+"processGametrailerRenditions": function(renditionsURLs, data, callbackData, callback) {
+ var sources = [];
+ for(i in renditionsURLs) {
+ var source = {};
+ source.url = renditionsURLs[i];
+ sources.push(source);
+ }
+ callbackData.playlist[0].sources = sources;
+ callback(callbackData);
+},
"processRenditions": function(renditionsURLs, data, callbackData, callback) {
// we use the todo var to track the number of jobs (i.e., XHR calls) that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment