Skip to content

Commit

Permalink
Various Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Jan 4, 2016
1 parent eac99c0 commit bfe79e7
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 299 deletions.
3 changes: 2 additions & 1 deletion src/actions/torrentActions.js
Expand Up @@ -8,6 +8,7 @@ import path from 'path';
import ipc from 'ipc';
import ls from 'local-storage';
import parser from '../components/Player/utils/parser';
import metaParser from '../components/Player/utils/metaParser';

class torrentActions {

Expand Down Expand Up @@ -81,7 +82,7 @@ class torrentActions {
_.delay(() => {
if (queueParser.length) {
queueParser.forEach( el => {
PlayerActions.parseURL(el);
metaParser.push(el);
});
}
},1000);
Expand Down
1 change: 1 addition & 0 deletions src/components/Framework.react.js
Expand Up @@ -42,6 +42,7 @@ const Framework = React.createClass({
ipc.send('app:startup', new Date().getTime());

// login trakt
if (ls('traktTokens') == '{}') ls.remove('traktTokens');
if (ls('traktTokens'))
traktUtil.autoLogin();

Expand Down
3 changes: 2 additions & 1 deletion src/components/MainMenu/actions.js
Expand Up @@ -8,6 +8,7 @@ import TorrentActions from '../../actions/torrentActions';

import sorter from './../Player/utils/sort';
import parser from './../Player/utils/parser';
import metaParser from './../Player/utils/metaParser';

import _ from 'lodash';

Expand Down Expand Up @@ -77,7 +78,7 @@ class MainMenuActions {
// start searching for thumbnails after 1 second
_.delay(() => {
queueParser.forEach( el => {
PlayerActions.parseURL(el);
metaParser.push(el);
});
},1000);

Expand Down
6 changes: 4 additions & 2 deletions src/components/MainMenu/index.js
Expand Up @@ -12,6 +12,8 @@ import MainMenuActions from './actions';
import PlayerActions from '../../components/Player/actions';
import ModalActions from './../Modal/actions';
import MessageActions from '../Message/actions';
import metaParser from '../../components/Player/utils/metaParser';

import remote from 'remote';

import webFrame from 'web-frame';
Expand Down Expand Up @@ -94,13 +96,13 @@ default React.createClass({
filename: file.name
});
});

PlayerActions.addPlaylist(newFiles);

// start searching for thumbnails after 1 second
_.delay(() => {
queueParser.forEach( el => {
PlayerActions.parseURL(el);
metaParser.push(el);
});
},1000);
} else {
Expand Down
213 changes: 2 additions & 211 deletions src/components/Player/actions.js
@@ -1,7 +1,7 @@
import alt from '../../alt'
import _ from 'lodash';
import ipc from 'ipc';
import ls from 'local-storage';
import subUtil from './utils/subtitles';

class PlayerActions {
constructor() {
Expand Down Expand Up @@ -40,7 +40,6 @@ class PlayerActions {
'toggleSubtitles',
'toggleSettings',
'setPlaylist',
'parseURL',
'replaceMRL',
'setSubtitle',
'setSubDelay',
Expand All @@ -63,215 +62,7 @@ class PlayerActions {
);
}


onParseURL(qTask) {
if (!this.urlParserQueue) {
var player = this;
var parserQueue = async.queue((task, cb) => {
if (task.url && !task.filename) {
var client = new MetaInspector(task.url, {
timeout: 5000
});

client.on("fetch", function() {
var idx = task.idx;
var itemDesc = player.itemDesc(task.idx);
if (!(itemDesc && itemDesc.mrl == task.url)) {
for (var i = 1; i < player.wcjs.playlist.items.count; i++) {
if (player.itemDesc(i).mrl == task.url) {
idx = i;
break;
}
}
}
if (idx > -1 && client.image && client.title) {

if (document.getElementById('item' + idx)) {
document.getElementById('item' + idx).style.background = "url('" + client.image + "')";
document.getElementById('itemTitle' + idx).innerHTML = client.title;
}

playerActions.setDesc({
idx: idx,
title: client.title,
image: client.image
});

if (idx == player.wcjs.playlist.currentItem) {
player.setState({
title: client.title
});
}

}
_.delay(() => {
cb()
}, 500)
});

client.on("error", function(err) {
_.delay(() => {
cb()
}, 500)
});

client.fetch();
} else if (task.filename) {

var parsedFilename = parseVideo(task.filename);

if (!parsedFilename.season && !task.secondTry && parser(task.filename).shortSzEp()) {
parsedFilename.type = 'series';
parsedFilename.season = parser(task.filename).season();
parsedFilename.episode = [parser(task.filename).episode()];
parsedFilename.name = parser(task.filename).showName();
}

if (parsedFilename.type == 'series' && parsedFilename.year) {
delete parsedFilename.year;
}

nameToImdb(parsedFilename, function(err, res, inf) {

if (err) {
// handle error
_.delay(() => {
cb()
}, 500)
return;
}

if (res) {
// handle imdb

parsedFilename.imdb = res;
parsedFilename.extended = 'full,images';
if (parsedFilename.type == 'movie') {
var buildQuery = {
id: parsedFilename.imdb,
id_type: 'imdb',
extended: parsedFilename.extended
};
var summary = traktUtil.movieInfo;
} else if (parsedFilename.type == 'series') {
var buildQuery = {
id: parsedFilename.imdb,
id_type: 'imdb',
season: parsedFilename.season,
episode: parsedFilename.episode[0],
extended: parsedFilename.extended
};
var summary = traktUtil.episodeInfo;
}

summary(buildQuery).then(results => {

var idx = task.idx;

var itemDesc = player.itemDesc(task.idx);

if (!(itemDesc && itemDesc.mrl == task.url)) {

for (var i = 1; i < player.wcjs.playlist.items.count; i++) {
if (player.itemDesc(i).mrl.endsWith(task.url)) {
idx = i;
break;
}
}

}

if (idx > -1 && results && results.title) {

var newObj = {
idx: idx
};

// this is the episode title for series
newObj.title = parsedFilename.name.split(' ').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(' ');

if (results.season && results.number) {
newObj.title += ' S' + ('0' + results.season).slice(-2) + 'E' + ('0' + results.number).slice(-2);
} else if (results.year) {
newObj.title += ' ' + results.year;
}

if (results.images) {
if (results.images.screenshot && results.images.screenshot.thumb) {
newObj.image = results.images.screenshot.thumb;
} else if (results.images.fanart && results.images.fanart.thumb) {
newObj.image = results.images.fanart.thumb;
}
}

if (document.getElementById('item' + idx)) {
if (newObj.image)
document.getElementById('item' + idx).style.background = "url('" + newObj.image + "')";

if (newObj.title)
document.getElementById('itemTitle' + idx).innerHTML = newObj.title;
}

newObj.parsed = parsedFilename;
newObj.trakt = results;

playerActions.setDesc(newObj);
if (idx == player.wcjs.playlist.currentItem) {
player.setState({
title: newObj.title
});
if (!player.foundTrakt) {
player.setState({
foundTrakt: true
});

var shouldScrobble = traktUtil.loggedIn && (ls.isSet('traktScrobble') ? ls('traktScrobble') : true);
if (shouldScrobble) {
if (!ls.isSet('playerNotifs') || ls('playerNotifs'))
player.notifier.info('Scrobbling', '', 6000);
traktUtil.scrobble('start', player.wcjs.position, results);
}
}
}

_.delay(() => {
cb()
}, 500)

}
}).catch(err => {
if (!task.secondTry && parsedFilename.type == 'series') {
task.secondTry = true;
parserQueue.push(task);
} else {
console.log('Error: ' + err.message);
}
_.delay(() => {
cb()
}, 500)
});
return;
}

_.delay(() => {
cb()
}, 500)

})

}

}, 1);

this.urlParserQueue = parserQueue;

}

this.urlParserQueue.push(qTask);
}


loadSub(sub) {
loadSub(subLink) {
subUtil.loadSubtitle(subLink, parsedSub => {
this.actions.setSubtitle(parsedSub);
this.actions.setSubDelay(0);
Expand Down
1 change: 1 addition & 0 deletions src/components/Player/components/Renderer.react.js
Expand Up @@ -64,6 +64,7 @@ default React.createClass({
componentWillMount() {
PlayerStore.listen(this.update);
window.addEventListener('resize', this.handleResize);
PlayerStore.getState().events.on('resizeNow', this.handleResize);
},
componentDidMount() {
if (!PlayerStore.getState().wcjs) {
Expand Down

0 comments on commit bfe79e7

Please sign in to comment.