Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailer integration #679

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ sidebar .play .poster img.big-poster {
height: 100%;
border-radius: 4px;
}
sidebar .play a.play-button {
sidebar .play a.play-button, a.trailer-button {
text-align: center;
color: #FFF;
font-weight: bold;
Expand All @@ -1424,7 +1424,7 @@ sidebar .play a.play-button {
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
background: #cc181e;
}
sidebar .play a.play-button:hover {
sidebar .play a.play-button:hover, a.trailer-button:hover {
background: #eb282e;
}
sidebar .play .movie-detail {
Expand Down Expand Up @@ -1740,7 +1740,7 @@ sidebar .play .movie-detail .side-content .subtitles-list ul li .flag.flag-hunga
sidebar .play .movie-detail .side-content .subtitles-list ul li .flag.flag-bulgarian {
background-image: url(../images/bulgarian.png);
}
sidebar .play .movie-detail .side-content a.play-button {
sidebar .play .movie-detail .side-content a.play-button, a.trailer-button {
background: #286dc4;
background-image: linear-gradient(to bottom, #3076ce 0%, #175ab0 100%);
color: #FFF;
Expand All @@ -1752,7 +1752,7 @@ sidebar .play .movie-detail .side-content a.play-button {
margin-top: 10px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
sidebar .play .movie-detail .side-content a.play-button:hover {
sidebar .play .movie-detail .side-content a.play-button:hover, a.trailer-button:hover {
background-image: linear-gradient(to bottom, #4387de 0%, #175ab0 100%);
}

Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ <h4><%= i18n.__('subtitledIn') %></h4>

<!-- Data Sources -->
<script src="js/frontend/providers/torrents.js"></script>
<script src="js/frontend/providers/trailersapi.js"></script>

<!-- Backbone Models, Views and Controllers -->
<script src="js/frontend/models/movie.js"></script>
Expand All @@ -200,6 +201,7 @@ <h4><%= i18n.__('subtitledIn') %></h4>
<!-- Other Dependencies -->
<script src="js/vendor/video-js/video.dev.js"></script>
<script src="js/vendor/videojsplugins.js"></script>
<script src="js/vendor/vjs.youtube.js"></script>
<script src="js/vendor/dragwindow.js"></script>

<script>userTracking.event('App Start', 'Ready - '+Settings.get('version'), (Math.round(((new Date()*1) - __startTime) / 100) * 100) +'ms' ).send();</script>
Expand Down
8 changes: 8 additions & 0 deletions js/frontend/models/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,18 @@ App.Model.Movie = Backbone.Model.extend({
});
},

setTrailer: function() {
var model = this;
App.findTrailer(model.get('title'), function(data) {
model.set('trailer', data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question about asynchronous programming. If findTrailer took forever to get a response back, and you wrote var trailer = model.get('trailer') right after this.setTrailer(); on line 75, would trailer be undefined? How can you avoid that?

});
},

initialize: function () {
this.buildBasicView();
//this.setRottenInfo();
//this.setSubtitles();
this.setTrailer();
this.calculateTorrentHealth();
},

Expand Down
34 changes: 24 additions & 10 deletions js/frontend/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {

var player =
'<video autoplay id="video_player" width="100%" height="100%" class="video-js vjs-default-skin" controls preload>' +
'<source src="' + url + '" type="video/mp4" />' +
'<source src="' + url + '" type="' + (movieModel ? 'video/mp4' : 'video/youtube') + '" />' +
subtracks +
'</video>' +
'<a href="javascript:;" id="video_player_close" class="btn-close"><img src="/images/close.svg" width="50" /></a>';
Expand All @@ -146,22 +146,36 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
$('.vjs-fullscreen-control').trigger('click');
});

// Youtube support (for trailers)
if(!movieModel) {
var options = {
techOrder: ["html5", "youtube"],
forceSSL: true,
loop: true
};
} else {
var options = {
techOrder: ["html5"],
plugins: { biggerSubtitle : {}, smallerSubtitle : {}, customSubtitles: {} }
};
}

// Init video.
var video = window.videoPlaying = videojs('video_player', { plugins: { biggerSubtitle : {}, smallerSubtitle : {}, customSubtitles: {} }});
var video = window.videoPlaying = videojs('video_player', options);


userTracking.pageview('/movies/watch/'+movieModel.get('slug'), movieModel.get('niceTitle') ).send();
if(movieModel) userTracking.pageview('/movies/watch/'+movieModel.get('slug'), movieModel.get('niceTitle') ).send();


// Enter full-screen
$('.vjs-fullscreen-control').on('click', function () {
if(win.isFullscreen) {
win.leaveFullscreen();
userTracking.event('Video Size', 'Normal', movieModel.get('niceTitle') ).send();
if(movieModel) userTracking.event('Video Size', 'Normal', movieModel.get('niceTitle') ).send();
win.focus();
} else {
win.enterFullscreen();
userTracking.event('Video Size', 'Fullscreen', movieModel.get('niceTitle') ).send();
if(movieModel) userTracking.event('Video Size', 'Fullscreen', movieModel.get('niceTitle') ).send();
win.focus();
}
});
Expand All @@ -171,7 +185,7 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
if (e.keyCode == 27) {
if(win.isFullscreen) {
win.leaveFullscreen();
userTracking.event('Video Size', 'Normal', movieModel.get('niceTitle') ).send();
if(movieModel) userTracking.event('Video Size', 'Normal', movieModel.get('niceTitle') ).send();
win.focus();
}
}
Expand All @@ -183,7 +197,7 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
tracks[i].on('loaded', function(){
// Trigger a resize to get the subtitles position right
$(window).trigger('resize');
userTracking.event('Video Subtitles', 'Select '+ this.language_, movieModel.get('niceTitle') ).send();
if(movieModel) userTracking.event('Video Subtitles', 'Select '+ this.language_, movieModel.get('niceTitle') ).send();
});
}

Expand All @@ -207,7 +221,7 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {

if( typeof video == 'undefined' || video == null ){ clearInterval(statusReportInterval); return; }

userTracking.event('Video Playing', movieModel.get('niceTitle'), getTimeLabel(), Math.round(video.currentTime()/60) ).send();
if(movieModel) userTracking.event('Video Playing', movieModel.get('niceTitle'), getTimeLabel(), Math.round(video.currentTime()/60) ).send();

}, 1000*60*10);

Expand All @@ -218,10 +232,10 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
// Determine if the user quit because he watched the entire movie
// Give 15 minutes or 15% of the movie for credits (everyone quits there)
if( video.duration() > 0 && video.currentTime() >= Math.min(video.duration() * 0.85, video.duration() - 15*60) ) {
userTracking.event('Video Finished', movieModel.get('niceTitle'), getTimeLabel(), Math.round(video.currentTime()/60) ).send();
if(movieModel) userTracking.event('Video Finished', movieModel.get('niceTitle'), getTimeLabel(), Math.round(video.currentTime()/60) ).send();
}
else {
userTracking.event('Video Quit', movieModel.get('niceTitle'), getTimeLabel(), Math.round(video.currentTime()/60) ).send();
if(movieModel) userTracking.event('Video Quit', movieModel.get('niceTitle'), getTimeLabel(), Math.round(video.currentTime()/60) ).send();
}

// Clear the status report interval so it doesn't leak
Expand Down
27 changes: 27 additions & 0 deletions js/frontend/providers/trailersapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var request = require('request'),

baseUrl = 'http://trailersapi.com/trailers.json?movie=';

App.findTrailer = function (title, callback) {
var doRequest = function () {
var requestOptions = {
url: baseUrl + '/' + encodeURI(title)
};

request(requestOptions, function(error, response, json) {
if (!error && response.statusCode == 200) {
var trailer=/[^>]+src="?([^"\s]+)"/.exec(JSON.parse(json)[0]['code'])[1];
App.Cache.setItem('trailer', title, trailer);
callback(trailer);
}
});
};

App.Cache.getItem('trailer', title, function (cachedItem) {
if (cachedItem) {
cb(cachedItem);
} else {
doRequest();
}
});
};
Loading