-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Feature/continue seeding after closing player #607
base: master
Are you sure you want to change the base?
Changes from 4 commits
00e91f3
196198a
035bf02
1d04cb5
f29a031
c58e6ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,8 @@ | |
<script id="keyboard-tpl" src="templates/keyboard.tpl" type="text/x-template"></script> | ||
<script id="notification-tpl" src="templates/notification.tpl" type="text/x-template"></script> | ||
|
||
<!-- Global variables --> | ||
<script src="global.js"></script> | ||
<!-- Global variables --> | ||
<script src="global.js"></script> | ||
|
||
<!-- 3rd party Dependencies --> | ||
<script src="vendor/jquery/dist/jquery.min.js"></script> | ||
|
@@ -69,6 +69,7 @@ | |
<script src="httpapi.js"></script> | ||
<script src="language.js"></script> | ||
<script src="lib/streamer.js"></script> | ||
<script src="lib/seeder.js"></script> | ||
|
||
<script src="lib/device/generic.js"></script> | ||
<script src="lib/device/airplay.js"></script> | ||
|
@@ -84,32 +85,32 @@ | |
<script src="lib/models/lang.js"></script> | ||
<script src="lib/models/content_item.js"></script> | ||
<script src="lib/models/movie.js"></script> | ||
<script src="lib/models/show.js"></script> | ||
<script src="lib/models/show.js"></script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still has whitespace issues |
||
<script src="lib/models/generic_collection.js"></script> | ||
<script src="lib/models/movie_collection.js"></script> | ||
<script src="lib/models/stream_info.js"></script> | ||
<script src="lib/models/show_collection.js"></script> | ||
<script src="lib/models/anime_collection.js"></script> | ||
<script src="lib/models/anime_collection.js"></script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still has whitespace issues |
||
<script src="lib/models/indie_collection.js"></script> | ||
<script src="lib/models/favorite_collection.js"></script> | ||
<script src="lib/models/watchlist_collection.js"></script> | ||
<script src="lib/models/watchlist_collection.js"></script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still has whitespace issues |
||
<script src="lib/models/notification.js"></script> | ||
|
||
<!-- Data Sources --> | ||
<script src="lib/cache.js"></script> | ||
<script src="lib/cachev2.js"></script> | ||
<script src="lib/providers/generic.js"></script> | ||
<!-- | ||
<script src="lib/providers/generic.js"></script> | ||
<!-- | ||
<script src="lib/providers/cache_provider.js"></script> | ||
<script src="lib/providers/cache_providerv2.js"></script> | ||
<script src="lib/providers/trakttv.js"></script> | ||
<script src="lib/providers/vodo.js"></script> | ||
<script src="lib/providers/archive.js"></script> | ||
<script src="lib/providers/favorites.js"></script> | ||
<script src="lib/providers/watchlist.js"></script> | ||
<script src="lib/providers/watchlist.js"></script> | ||
<script src="lib/providers/opensubtitles.js"></script> | ||
<script src="lib/providers/torrent_cache.js"></script> | ||
--> | ||
--> | ||
<!-- Backbone Views and Controllers --> | ||
<script src="lib/views/title_bar.js"></script> | ||
<script src="lib/views/main_window.js"></script> | ||
|
@@ -131,19 +132,20 @@ | |
<script src="lib/views/player/loading.js"></script> | ||
<script src="lib/views/player/player.js"></script> | ||
|
||
<script src="lib/views/browser/generic_browser.js"></script> | ||
<script src="lib/views/browser/generic_browser.js"></script> | ||
<script src="lib/views/browser/movie_browser.js"></script> | ||
<script src="lib/views/browser/filter_bar.js"></script> | ||
<script src="lib/views/browser/item.js"></script> | ||
<script src="lib/views/browser/list.js"></script> | ||
|
||
<script src="lib/views/browser/show_browser.js"></script> | ||
<script src="lib/views/browser/anime_browser.js"></script> | ||
<script src="lib/views/browser/anime_browser.js"></script> | ||
<script src="lib/views/browser/indie_browser.js"></script> | ||
|
||
<script src="lib/views/browser/favorite_browser.js"></script> | ||
<script src="lib/views/browser/watchlist_browser.js"></script> | ||
<script src="lib/views/browser/watchlist_browser.js"></script> | ||
|
||
<script src="bootstrap.js"></script> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
(function (App) { | ||
|
||
var Seeder = function () { | ||
this.worker = null; | ||
}; | ||
|
||
Seeder.prototype = { | ||
start: function() { | ||
this.getWorkerInstance().send({action: 'start'}); | ||
}, | ||
|
||
stop: function() { | ||
if (this.getWorkerInstance()) { | ||
this.getWorkerInstance().send({action: 'stop'}); | ||
this.worker = null; | ||
} | ||
}, | ||
|
||
append: function(torrent) { | ||
this.getWorkerInstance().send({action: 'append', payload: torrent.name}); | ||
}, | ||
|
||
save: function(torrent) { | ||
var targetFile = path.join(App.settings.tmpLocation, 'TorrentCache', Common.md5(torrent.name) + '.torrent'); | ||
var wstream = fs.createWriteStream(targetFile); | ||
|
||
wstream.write(torrent.torrentFile); | ||
wstream.end(); | ||
}, | ||
|
||
getWorkerInstance: function () { | ||
if (this.worker === null) { | ||
var taskFile = 'src/app/lib/workers/seederTask.js'; | ||
// TODO: AdvSettings here should be trigger creation of worker instance | ||
var args = JSON.stringify({ | ||
connectionLimit: Settings.connectionLimit, | ||
trackerAnnouncement: Settings.trackers.forced, | ||
tmpLocation: App.settings.tmpLocation, | ||
seedLimit: Settings.seedLimit | ||
}); | ||
|
||
this.worker = child.fork(taskFile, [args], {silent: true, execPath:'node'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'node' will fail on machines that don't have nodejs installed (we bundle) |
||
|
||
this.worker.on('message', function(msg) { | ||
win.info(msg); | ||
}); | ||
} | ||
|
||
return this.worker; | ||
} | ||
}; | ||
|
||
var seeder = new Seeder(); | ||
|
||
App.vent.on('seed:start', seeder.start.bind(seeder)); | ||
App.vent.on('seed:stop', seeder.stop.bind(seeder)); | ||
App.vent.on('seed:save', seeder.save.bind(seeder)); | ||
App.vent.on('seed:append', seeder.append.bind(seeder)); | ||
|
||
})(window.App); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,17 +230,17 @@ | |
$('.events').css('display', 'block'); | ||
} | ||
|
||
if (AdvSettings.get('autoSeed')) { | ||
App.vent.trigger('seed:start'); | ||
} | ||
|
||
// set player from settings | ||
var players = App.Device.Collection.models; | ||
for (var i in players) { | ||
if (players[i].id === AdvSettings.get('chosenPlayer')) { | ||
App.Device.Collection.setDevice(AdvSettings.get('chosenPlayer')); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shouldn't be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. opps will add back. |
||
|
||
// Focus the window when the app opens | ||
win.focus(); | ||
|
||
}); | ||
|
||
// Cancel all new windows (Middle clicks / New Tab) | ||
|
@@ -250,7 +250,6 @@ | |
|
||
App.vent.trigger('updatePostersSizeStylesheet'); | ||
App.vent.trigger('main:ready'); | ||
|
||
}, | ||
|
||
movieTabShow: function (e) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
'use strict'; | ||
|
||
var _ = require('underscore'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var WebTorrent = require('webtorrent'); | ||
var child = require('child_process'); | ||
var crypt = require('crypto'); | ||
|
||
var SeederTask = function (opt) { | ||
this.webtorrent = null; | ||
this.torrentFiles = null; | ||
this.tmpLocation = opt.tmpLocation; | ||
this.seedLimit = opt.seedLimit; | ||
this.connectionLimit = opt.connectionLimit; | ||
this.trackerAnnouncement = opt.trackerAnnouncement; | ||
this.torrentDir = path.join(this.tmpLocation, 'TorrentCache'); | ||
}; | ||
|
||
SeederTask.prototype = { | ||
start: function() { | ||
if (this.webtorrent) { | ||
this.stop(); | ||
} | ||
|
||
process.send('Seeding started'); | ||
|
||
var seedTorrentFiles = this.seedLimit ? | ||
_.sample(this.getTorrentFiles(), this.seedLimit) : this.getTorrentFiles(); | ||
|
||
seedTorrentFiles.forEach(this.joinSwarm.bind(this)); | ||
}, | ||
|
||
stop: function() { | ||
if (this.webtorrent) { | ||
this.webtorrent.destroy(); | ||
} | ||
|
||
this.webtorrent = null; | ||
this.torrentFiles = []; | ||
|
||
process.send('Seeding stopped'); | ||
process.kill(); | ||
}, | ||
|
||
getTorrentFiles: function() { | ||
if (this.torrentFiles === null) { | ||
var regexp = /\.torrent$/i; | ||
var files = fs.readdirSync(this.torrentDir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of calling fs here, i think i'd rather maintain a registery of things that have been 'added/removed' to this module. |
||
|
||
this.torrentFiles = files.filter(function(val) { | ||
return regexp.test(val); | ||
}).map(function(filename) { | ||
return path.join(this.torrentDir, filename); | ||
}, this); | ||
} | ||
|
||
return this.torrentFiles; | ||
}, | ||
|
||
joinSwarm: function (torrentId) { | ||
var client = this.getWebTorrentInstance(); | ||
|
||
if (!client.get(torrentId)) { | ||
var torrent = client.add(torrentId, { | ||
path: this.tmpLocation | ||
}); | ||
|
||
torrent.on('ready', function () { | ||
process.send(`Seeding ${torrent.name} --- ${torrentId}`); | ||
}); | ||
} | ||
}, | ||
|
||
append: function(name) { | ||
var targetFile = path.join(this.torrentDir, this._md5(name) + '.torrent'); | ||
|
||
this.torrentFiles.push(targetFile); | ||
this.seedLimit += 1; | ||
this.joinSwarm(targetFile); | ||
}, | ||
|
||
_md5: function (arg) { | ||
return crypt.createHash('md5').update(arg).digest('hex'); | ||
}, | ||
|
||
getWebTorrentInstance: function() { | ||
if (this.webtorrent === null) { | ||
this.webtorrent = new WebTorrent({ | ||
maxConns: parseInt(this.connectionLimit, 10) || 55, | ||
tracker: { | ||
wrtc: false, | ||
announce: this.trackerAnnouncement | ||
} | ||
}); | ||
|
||
this.webtorrent.on('error', function (error) { | ||
process.send('WebTorrent fatal error', error); | ||
}); | ||
} | ||
|
||
return this.webtorrent; | ||
} | ||
}; | ||
|
||
var args = JSON.parse(process.argv[2]); | ||
var seederTask = new SeederTask(args); | ||
|
||
process.on('message', function (params) { | ||
if (params.action && seederTask[params.action]) { | ||
seederTask[params.action].call(seederTask, params.payload); | ||
} else { | ||
process.send(`Invalid seederTask function`); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still has whitespace issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you guys using tabs or spaces here? jshint doesn't seem to lint for me..