]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/videos.js
Add ffmpeg dependency to travis
[github/Chocobozzz/PeerTube.git] / server / lib / videos.js
CommitLineData
9f10b292
C
1'use strict'
2
f0f5567b
C
3const async = require('async')
4const config = require('config')
5const pathUtils = require('path')
6const webtorrent = require('../lib/webtorrent')
9f10b292 7
f0f5567b
C
8const logger = require('../helpers/logger')
9const Videos = require('../models/videos')
9f10b292 10
f0f5567b 11const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads'))
9f10b292 12
f0f5567b 13const videos = {
5101105e 14 getVideoState: getVideoState,
9f10b292
C
15 seed: seed,
16 seedAllExisting: seedAllExisting
17}
18
2df82d42 19function getVideoState (video) {
f0f5567b
C
20 const exist = (video !== null)
21 let owned = false
5101105e
C
22 if (exist === true) {
23 owned = (video.namePath !== null)
24 }
25
2df82d42 26 return { exist: exist, owned: owned }
5101105e
C
27}
28
9f10b292
C
29function seed (path, callback) {
30 logger.info('Seeding %s...', path)
31
32 webtorrent.seed(path, function (torrent) {
33 logger.info('%s seeded (%s).', path, torrent.magnetURI)
34
35 return callback(null, torrent)
36 })
37}
38
39function seedAllExisting (callback) {
40 Videos.listOwned(function (err, videos_list) {
41 if (err) {
42 logger.error('Cannot get list of the videos to seed.')
43 return callback(err)
44 }
45
46 async.each(videos_list, function (video, each_callback) {
47 seed(uploadDir + video.namePath, function (err) {
48 if (err) {
49 logger.error('Cannot seed this video.')
50 return callback(err)
51 }
52
53 each_callback(null)
54 })
55 }, callback)
56 })
57}
58
59// ---------------------------------------------------------------------------
60
61module.exports = videos