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 all commits
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
15 changes: 12 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ <h4><%= i18n.__('subtitledIn') %></h4>
<% if (this.model.get('torrents')) { %>
<a href="" class="p_tooltip play-button"><%= i18n.__('watchItNow') %></a>
<% } %>

<% if (this.model.get('trailer')) { %>
<a href="" class="p_tooltip trailer-button"><%= i18n.__('trailer') %></a>
<% } %>
</div>

</div>
</div>
</div>
Expand Down Expand Up @@ -173,15 +179,18 @@ <h4><%= i18n.__('subtitledIn') %></h4>
<!-- App Initialization -->
<script src="js/app.js"></script>
<script src="js/language.js"></script>
<script src="js/tracking.js"></script>
<script src="js/updater.js"></script>

<!-- UI and UI-related Initialization -->
<script src="js/frontend/ui.js"></script>
<script src="js/frontend/player.js"></script>

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


<!-- Backbone Models, Views and Controllers -->
<script src="js/frontend/models/movie.js"></script>
Expand All @@ -200,8 +209,8 @@ <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>
</body>
</html>
2 changes: 0 additions & 2 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ if( ! Settings.get('disclaimerAccepted') ) {

$('.popcorn-disclaimer .btn.confirmation.continue').click(function(event){
event.preventDefault();
userTracking.event('App Disclaimer', 'Accepted', navigator.language.toLowerCase() ).send();
Settings.set('disclaimerAccepted', 1);
$('.popcorn-disclaimer').addClass('hidden');
});
Expand All @@ -157,7 +156,6 @@ if( ! Settings.get('disclaimerAccepted') ) {
if( $('.popcorn-disclaimer').hasClass('quitting') ){ return; }
$('.popcorn-disclaimer').addClass('quitting');

userTracking.event('App Disclaimer', 'Quit', navigator.language.toLowerCase() ).send();
setTimeout(function(){
gui.App.quit();
}, 2000);
Expand Down
2 changes: 0 additions & 2 deletions js/frontend/controllers/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ App.Controller.FilterGenre = function (genre, page) {
App.Page.FilterGenre.show();
}

userTracking.pageview('/movies/'+genre + ((page && page > 1) ? '?page='+page : ''), genre.capitalize() + ' Movies').send();

setTimeout(function(){
movieList.constructor.busy = false;
}, 5000);
Expand Down
2 changes: 0 additions & 2 deletions js/frontend/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ App.Controller.Home = function (page) {

App.Page.Home.show();
}

userTracking.pageview('/movies/popular'+((page && page > 1) ? '?page='+page : ''), 'Popular Movies').send();

setTimeout(function(){
movieList.constructor.busy = false;
Expand Down
2 changes: 0 additions & 2 deletions js/frontend/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ App.Controller.Search = function (searchTerm, page) {
App.Page.Search.show();
}

userTracking.pageview('/movies/search?q='+encodeURIComponent(searchTerm)+((page && page > 1) ? '&page='+page : '')).send();

setTimeout(function(){
movieList.constructor.busy = false;
}, 5000);
Expand Down
4 changes: 2 additions & 2 deletions js/frontend/models/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ App.Model.Movie = Backbone.Model.extend({

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

Expand Down
36 changes: 16 additions & 20 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,31 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
$('.vjs-fullscreen-control').trigger('click');
});

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

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

userTracking.pageview('/movies/watch/'+movieModel.get('slug'), movieModel.get('niceTitle') ).send();
// Init video.
var video = window.videoPlaying = videojs('video_player', options);


// Enter full-screen
$('.vjs-fullscreen-control').on('click', function () {
if(win.isFullscreen) {
win.leaveFullscreen();
userTracking.event('Video Size', 'Normal', movieModel.get('niceTitle') ).send();
win.focus();
} else {
win.enterFullscreen();
userTracking.event('Video Size', 'Fullscreen', movieModel.get('niceTitle') ).send();
win.focus();
}
});
Expand All @@ -171,7 +180,6 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
if (e.keyCode == 27) {
if(win.isFullscreen) {
win.leaveFullscreen();
userTracking.event('Video Size', 'Normal', movieModel.get('niceTitle') ).send();
win.focus();
}
}
Expand All @@ -183,7 +191,6 @@ 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();
});
}

Expand All @@ -207,22 +214,13 @@ 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();

}, 1000*60*10);


// Close player
$('#video_player_close').on('click', function () {

// 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();
}
else {
userTracking.event('Video Quit', movieModel.get('niceTitle'), getTimeLabel(), Math.round(video.currentTime()/60) ).send();
}

// Clear the status report interval so it doesn't leak
clearInterval(statusReportInterval);
Expand All @@ -240,14 +238,12 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
// Todo: delay these tracking events so we don't send two on double click
video.player().on('pause', function () {

//userTracking.event('Video Control', 'Pause Button', getTimeLabel(), Math.round(video.currentTime()/60) ).send();
});

video.player().on('play', function () {
// Trigger a resize so the subtitles are adjusted
$(window).trigger('resize');

//userTracking.event('Video Control', 'Play Button', getTimeLabel(), Math.round(video.currentTime()/60) ).send();
});

// There was an issue with the video
Expand Down
93 changes: 92 additions & 1 deletion js/frontend/providers/torrents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,95 @@
App.getTorrentsCollection = function (options) {

var url = 'http://subapi.com/';
var start = +new Date(),
url = 'http://yts.re/api/list.json?sort=seeds&limit=50';

if (options.keywords) {
url += '&keywords=' + options.keywords;
}

if (options.genre) {
url += '&genre=' + options.genre;
}

if (options.page && options.page.match(/\d+/)) {
url += '&set=' + options.page;
}

var MovieTorrentCollection = Backbone.Collection.extend({
url: url,
model: App.Model.Movie,
parse: function (data) {
var movies = [],
memory = {};

if (data.error || typeof data.MovieList === 'undefined') {
return movies;
}

data.MovieList.forEach(function (movie) {
// No imdb, no movie.
if( typeof movie.ImdbCode != 'string' || movie.ImdbCode.replace('tt', '') == '' ){ return; }

var torrents = {};
torrents[movie.Quality] = movie.TorrentUrl;

// Temporary object
var movieModel = {
imdb: movie.ImdbCode.replace('tt', ''),
title: movie.MovieTitleClean,
year: movie.MovieYear,
runtime: 0,
synopsis: "",
voteAverage:parseInt(movie.MovieRating, 10),

image: movie.CoverImage,
bigImage: movie.CoverImage,
backdrop: "",

quality: movie.Quality,
torrent: movie.TorrentUrl,
torrents: torrents,
videos: {},
subtitles: {},
seeders: movie.TorrentSeeds,
leechers: movie.TorrentPeers
};


var stored = memory[movieModel.imdb];

// Create it on memory map if it doesn't exist.
if (typeof stored === 'undefined') {
stored = memory[movieModel.imdb] = movieModel;
}

if (stored.quality !== movieModel.quality && movieModel.quality === '720p') {
stored.torrent = movieModel.torrent;
stored.quality = '720p';
}

// Set it's correspondent quality torrent URL.
stored.torrents[movie.Quality] = movie.TorrentUrl;

// Push it if not currently on array.
if (movies.indexOf(stored) === -1) {
movies.push(stored);
}
});

console.log('Torrents found:', data.MovieList.length);

return movies;
}
});

return new MovieTorrentCollection();
};


/*App.getTorrentsCollection = function (options) {

var url = 'http://yts.re/api/';

var supportedLanguages = ['english', 'french', 'dutch', 'portuguese', 'romanian', 'spanish', 'turkish', 'brazilian',
'italian', 'german', 'hungarian', 'russian', 'ukrainian', 'finnish', 'bulgarian', 'latvian'];
Expand Down Expand Up @@ -59,6 +148,7 @@ App.getTorrentsCollection = function (options) {
}

if( (typeof movie.subtitles == 'undefined' || movie.subtitles.length == 0) && (typeof movie.videos == 'undefined' || movie.videos.length == 0) ){ return; }


movies.push({
imdb: movie.imdb_id,
Expand Down Expand Up @@ -88,3 +178,4 @@ App.getTorrentsCollection = function (options) {

return new MovieTorrentCollection();
};
*/
Loading