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