2016-11-22 22:12:13 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const fs = require('fs')
|
|
|
|
const parseTorrent = require('parse-torrent')
|
|
|
|
|
|
|
|
const constants = require('../server/initializers/constants')
|
2016-12-25 09:44:13 +01:00
|
|
|
const db = require('../server/initializers/database')
|
2016-11-22 22:12:13 +01:00
|
|
|
|
|
|
|
const friends = require('../server/lib/friends')
|
|
|
|
|
2016-12-25 09:44:13 +01:00
|
|
|
db.init(true, function () {
|
|
|
|
friends.hasFriends(function (err, hasFriends) {
|
2016-11-22 22:12:13 +01:00
|
|
|
if (err) throw err
|
|
|
|
|
2016-12-25 09:44:13 +01:00
|
|
|
if (hasFriends === true) {
|
|
|
|
console.log('Cannot update host because you have friends!')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
|
2016-11-22 22:12:13 +01:00
|
|
|
console.log('Updating torrent files.')
|
2016-12-25 09:44:13 +01:00
|
|
|
db.Video.list(function (err, videos) {
|
2016-11-22 22:12:13 +01:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
videos.forEach(function (video) {
|
2017-02-08 20:34:01 +01:00
|
|
|
const torrentName = video.id + '.torrent'
|
2016-11-22 22:12:13 +01:00
|
|
|
const torrentPath = constants.CONFIG.STORAGE.TORRENTS_DIR + torrentName
|
2017-02-08 20:34:01 +01:00
|
|
|
const filename = video.id + video.extname
|
2016-11-22 22:12:13 +01:00
|
|
|
|
|
|
|
const parsed = parseTorrent(fs.readFileSync(torrentPath))
|
|
|
|
parsed.announce = [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
|
|
|
|
parsed.urlList = [ constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + filename ]
|
|
|
|
|
|
|
|
const buf = parseTorrent.toTorrentFile(parsed)
|
|
|
|
fs.writeFileSync(torrentPath, buf)
|
|
|
|
})
|
|
|
|
|
|
|
|
process.exit(0)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|