Skip to content

Commit

Permalink
Fixed #286 (Probably). Refactored the subtitles loader so it download…
Browse files Browse the repository at this point in the history
…s the subtitle and then parses it in-memory, getting rid of CORS issues and the only reason we kept the TMP folder there.

Since that was a huge piece of crap, this should get rid of all subtitle issues in Mac and some Windows installs, since you can't write to the app folder. This also makes the app more efficient, since we only download the subtitles on demand.
Also rewrote the movie model so providers have to return standard movie models.
  • Loading branch information
Patineta committed Mar 11, 2014
1 parent 6cbce19 commit 55f8779
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
linux32: false, // We don't need linux32
linux64: true // We don't need linux64
},
src: ['./css/**', './fonts/**', './images/**', './js/**', './language/**', './node_modules/**', '!./node_modules/grunt*/**', './rc/**', './tmp/empty', './Config.rb', './index.html', './package.json', './README.md' ] // Your node-webkit app './**/*'
src: ['./css/**', './fonts/**', './images/**', './js/**', './language/**', './node_modules/**', '!./node_modules/grunt*/**', './rc/**', './Config.rb', './index.html', './package.json', './README.md' ] // Your node-webkit app './**/*'
},
copy: {
main: {
Expand Down
1 change: 0 additions & 1 deletion dist/windows/windows-installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Source: "..\..\js\*"; DestDir: "{app}\app\js\"; Flags: ignoreversion recursesubd
Source: "..\..\fonts\*"; DestDir: "{app}\app\fonts\"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\..\images\*"; DestDir: "{app}\app\images\"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\..\language\*"; DestDir: "{app}\app\language\"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\..\tmp\empty"; DestDir: "{app}\app\tmp\"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\..\node_modules\*"; DestDir: "{app}\app\node_modules\"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\..\node-webkit\windows\*"; DestDir: "{app}\node-webkit\"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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/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
73 changes: 33 additions & 40 deletions js/frontend/models/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ App.Model.Movie = Backbone.Model.extend({
buildBasicView: function () {

var model = this;

model.set('infoLoaded', true);
model.set('subtitlesLoaded', true);
model.set('image', model.get('coverImage'));
model.set('bigImage', model.get('coverImage'));
model.set('backdrop', model.get('backdropImage'));
model.set('title', model.get('title'));
model.set('synopsis', model.get('synopsis'));
model.set('voteAverage', model.get('voteAverage'));
model.set('runtime', model.get('runtime'));
model.set('subtitles', model.get('subtitles'));

// This is mostly used for reporting
model.set('slug', model.get('title').toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'_') +'.'+ model.get('imdb').slice(2) );
Expand Down Expand Up @@ -65,37 +54,41 @@ App.Model.Movie = Backbone.Model.extend({
},

initialize: function () {
// Movie Health
var seeders = this.get('seeders');
var leechers = this.get('leechers');
var ratio = leechers > 0 ? (seeders / leechers) : seeders;

if (seeders < 100) {
this.set('health', 'bad');
}
else if (seeders > 100 && seeders < 200) {
if( ratio > 5 ) {
this.set('health', 'good');
} else if( ratio > 3 ) {
this.set('health', 'medium');
} else {
this.set('health', 'bad');
}
}
else if (seeders > 200) {
if( ratio > 5 ) {
this.set('health', 'excellent');
} else if( ratio > 3 ) {
this.set('health', 'good');
} else if( ratio > 2 ) {
this.set('health', 'medium');
} else {
this.set('health', 'bad');
}
}

this.buildBasicView();
//this.setRottenInfo();
//this.setSubtitles();
this.calculateTorrentHealth();
},

calculateTorrentHealth: function () {
// Calculates the "health" of the torrent (how easy it is to stream)
var seeders = this.get('seeders');
var leechers = this.get('leechers');
var ratio = leechers > 0 ? (seeders / leechers) : seeders;

if (seeders < 100) {
this.set('health', 'bad');
}
else if (seeders > 100 && seeders < 200) {
if( ratio > 5 ) {
this.set('health', 'good');
} else if( ratio > 3 ) {
this.set('health', 'medium');
} else {
this.set('health', 'bad');
}
}
else if (seeders > 200) {
if( ratio > 5 ) {
this.set('health', 'excellent');
} else if( ratio > 3 ) {
this.set('health', 'good');
} else if( ratio > 2 ) {
this.set('health', 'medium');
} else {
this.set('health', 'bad');
}
}
}

});
77 changes: 4 additions & 73 deletions js/frontend/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
for (lang in subs) {
if( typeof SubtitleLanguages[lang] == 'undefined' ){ continue; }
subArray.push({
'language': SubtitleLanguages[lang],
'language': lang,
'languageName': SubtitleLanguages[lang],
'sub': subs[lang]
});
}
Expand All @@ -116,7 +117,7 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {

var subtracks = '';
for( index in subArray ) {
subtracks += '<track kind="subtitles" src="app://host/' + subArray[index].sub + '" srclang="es" label="' + subArray[index].language + '" charset="utf-8" />';
subtracks += '<track kind="subtitles" src="' + subArray[index].sub + '" srclang="'+ subArray[index].language +'" label="' + subArray[index].languageName + '" charset="utf-8" />';
}

var player =
Expand All @@ -130,76 +131,6 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
return alert('Weird, but it seems the application is broken and you can\'t play this video.');
}

videojs.BiggerSubtitleButton = videojs.Button.extend({
/** @constructor */
init: function(player, options){
videojs.Button.call(this, player, options);
this.on('click', this.onClick);
}
});

videojs.BiggerSubtitleButton.prototype.onClick = function() {
var $subs = $('#video_player.video-js .vjs-text-track-display');
var font_size = parseInt($subs.css('font-size'));
font_size = font_size + 3;
$subs.css('font-size', font_size+'px');

userTracking.event('Video Subtitle Size', 'Make Bigger', font_size+'px', font_size).send();
};

var createBiggerSubtitleButton = function() {
var props = {
className: 'vjs_biggersub_button vjs-control',
innerHTML: '<div class="vjs-control-content"><span class="vjs-control-text">A+</span></div>',
role: 'button',
'aria-live': 'polite', // let the screen reader user know that the text of the button may change
tabIndex: 0
};
return videojs.Component.prototype.createEl(null, props);
}

var biggerSubtitle;
videojs.plugin('biggerSubtitle', function() {
var options = { 'el' : createBiggerSubtitleButton() };
biggerSubtitle = new videojs.BiggerSubtitleButton(this, options);
this.controlBar.el().appendChild(biggerSubtitle.el());
});

videojs.SmallerSubtitleButton = videojs.Button.extend({
/** @constructor */
init: function(player, options){
videojs.Button.call(this, player, options);
this.on('click', this.onClick);
}
});

videojs.SmallerSubtitleButton.prototype.onClick = function() {
var $subs = $('#video_player.video-js .vjs-text-track-display');
var font_size = parseInt($subs.css('font-size'));
font_size = font_size - 3;
$subs.css('font-size', font_size+'px');

userTracking.event('Video Subtitle Size', 'Make Smaller', font_size+'px', font_size).send();
};

var createSmallerSubtitleButton = function() {
var props = {
className: 'vjs_smallersub_button vjs-control',
innerHTML: '<div class="vjs-control-content"><span class="vjs-control-text">A-</span></div>',
role: 'button',
'aria-live': 'polite', // let the screen reader user know that the text of the button may change
tabIndex: 0
};
return videojs.Component.prototype.createEl(null, props);
}

var smallerSubtitle;
videojs.plugin('smallerSubtitle', function() {
var options = { 'el' : createSmallerSubtitleButton() };
smallerSubtitle = new videojs.SmallerSubtitleButton(this, options);
this.controlBar.el().appendChild(smallerSubtitle.el());
});

// Move this to a separate view.
$('#video-container').html(player).show();
$('body').removeClass().addClass('watching');
Expand All @@ -213,7 +144,7 @@ window.spawnVideoPlayer = function (url, subs, movieModel) {
});

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


userTracking.pageview('/movies/watch/'+movieModel.get('slug'), movieModel.get('niceTitle') ).send();
Expand Down
28 changes: 20 additions & 8 deletions js/frontend/providers/torrents.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
App.getTorrentsCollection = function (options) {

var start = +new Date(),
url = 'http://subapi.com/';
var url = 'http://subapi.com/';

var supportedLanguages = ['english', 'french', 'dutch', 'portuguese', 'romanian', 'spanish', 'turkish', 'brazilian', 'italian'];

Expand Down Expand Up @@ -29,26 +28,37 @@ App.getTorrentsCollection = function (options) {

data.movies.forEach(function (movie) {

var videos = {};
var torrents = {};
torrent = '';
quality = '';
var subtitles = {};

for( var k in movie.torrents ) {
if( typeof torrents[movie.torrents[k].quality] == 'undefined' ) {
torrents[movie.torrents[k].quality] = movie.torrents[k].url;
// Put the video and torrent list into a {quality: url} format
for( var k in movie.videos ) {
if( typeof videos[movie.videos[k].quality] == 'undefined' ) {
videos[movie.videos[k].quality] = movie.videos[k].url;
}
}

for( var k in movie.torrents ) {
if( typeof torrents[movie.torrents[k].quality] == 'undefined' ) {
torrents[movie.torrents[k].quality] = movie.torrents[k].url;
}
}

// Pick the worst quality by default
if( typeof torrents['1080p'] != 'undefined' ){ quality = '1080p'; torrent = torrents['1080p']; }
if( typeof torrents['720p'] != 'undefined' ){ quality = '720p'; torrent = torrents['720p']; }
else if( typeof torrents['1080p'] != 'undefined' ){ quality = '1080p'; torrent = torrents['1080p']; }

for( var k in movie.subtitles ) {
if( supportedLanguages.indexOf(movie.subtitles[k].language) < 0 ){ continue; }
if( typeof subtitles[movie.subtitles[k].language] == 'undefined' ) {
subtitles[movie.subtitles[k].language] = movie.subtitles[k].url;
}
}

if( movie.subtitles.length == 0 && movie.videos.length == 0 ){ return; }

movies.push({
imdb: movie.imdb_id,
Expand All @@ -58,12 +68,14 @@ App.getTorrentsCollection = function (options) {
synopsis: movie.synopsis,
voteAverage:movie.vote_average,

coverImage: movie.poster,
backdropImage: movie.backdrop,
image: movie.poster,
bigImage: movie.poster,
backdrop: movie.backdrop,

quality: quality,
torrent: torrent,
torrents: torrents,
videos: videos,
subtitles: subtitles,
seeders: movie.seeders,
leechers: movie.leechers
Expand Down
2 changes: 1 addition & 1 deletion js/frontend/views/listview.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ App.View.MovieList = Backbone.View.extend({

// Check for IMDB id and also image loaded (required for view)
// We can also check if the subtitles loaded with this.get('subtitlesLoaded')
if (this.get('infoLoaded') && ! $movie.hasClass('fullyLoaded')) {
if (! $movie.hasClass('fullyLoaded')) {

$movie.addClass('fullyLoaded');

Expand Down
Loading

0 comments on commit 55f8779

Please sign in to comment.