magnet: {
infoHash: String
},
- podUrl: String,
+ podHost: String,
author: String,
duration: Number,
- thumbnail: String,
tags: [ String ],
createdDate: {
type: Date,
VideoSchema.path('name').validate(customVideosValidators.isVideoNameValid)
VideoSchema.path('description').validate(customVideosValidators.isVideoDescriptionValid)
-VideoSchema.path('podUrl').validate(customVideosValidators.isVideoPodUrlValid)
+VideoSchema.path('podHost').validate(customVideosValidators.isVideoPodHostValid)
VideoSchema.path('author').validate(customVideosValidators.isVideoAuthorValid)
VideoSchema.path('duration').validate(customVideosValidators.isVideoDurationValid)
-// The tumbnail can be the path or the data in base 64
-// The pre save hook will convert the base 64 data in a file on disk and replace the thumbnail key by the filename
-VideoSchema.path('thumbnail').validate(function (value) {
- return customVideosValidators.isVideoThumbnailValid(value) || customVideosValidators.isVideoThumbnail64Valid(value)
-})
VideoSchema.path('tags').validate(customVideosValidators.isVideoTagsValid)
VideoSchema.methods = {
}
VideoSchema.statics = {
+ generateThumbnailFromBase64,
getDurationFromFile,
listForApi,
- listByUrlAndRemoteId,
- listByUrl,
+ listByHostAndRemoteId,
+ listByHost,
listOwned,
listOwnedByAuthor,
listRemotes,
if (video.isOwned()) {
const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
- this.podUrl = constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT
+ this.podHost = constants.CONFIG.WEBSERVER.HOST
tasks.push(
// TODO: refractoring
const parsedTorrent = parseTorrent(torrent)
video.magnet.infoHash = parsedTorrent.infoHash
- console.log(parsedTorrent)
callback(null)
})
})
}
)
- parallel(tasks, next)
- } else {
- generateThumbnailFromBase64(video, video.thumbnail, next)
+ return parallel(tasks, next)
}
+
+ return next()
})
mongoose.model('Video', VideoSchema)
baseUrlHttp = constants.CONFIG.WEBSERVER.URL
baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT
} else {
- baseUrlHttp = constants.REMOTE_SCHEME.HTTP + this.podUrl
- baseUrlWs = constants.REMOTE_SCHEME.WS + this.podUrl
+ baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podHost
+ baseUrlWs = constants.REMOTE_SCHEME.WS + this.podHost
}
const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName()
id: this._id,
name: this.name,
description: this.description,
- podUrl: this.podUrl,
+ podHost: this.podHost,
isLocal: this.isOwned(),
magnetUri: this.generateMagnetUri(),
author: this.author,
thumbnailBase64: new Buffer(thumbnailData).toString('base64'),
tags: self.tags,
createdDate: self.createdDate,
- podUrl: self.podUrl
+ podHost: self.podHost
}
return callback(null, remoteVideo)
// ------------------------------ STATICS ------------------------------
+function generateThumbnailFromBase64 (video, thumbnailData, callback) {
+ // Creating the thumbnail for a remote video
+
+ const thumbnailName = video.getThumbnailName()
+ const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
+ fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) {
+ if (err) return callback(err)
+
+ return callback(null, thumbnailName)
+ })
+}
+
function getDurationFromFile (videoPath, callback) {
ffmpeg.ffprobe(videoPath, function (err, metadata) {
if (err) return callback(err)
return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)
}
-function listByUrlAndRemoteId (fromUrl, remoteId, callback) {
- this.find({ podUrl: fromUrl, remoteId: remoteId }, callback)
+function listByHostAndRemoteId (fromHost, remoteId, callback) {
+ this.find({ podHost: fromHost, remoteId: remoteId }, callback)
}
-function listByUrl (fromUrl, callback) {
- this.find({ podUrl: fromUrl }, callback)
+function listByHost (fromHost, callback) {
+ this.find({ podHost: fromHost }, callback)
}
function listOwned (callback) {
function search (value, field, start, count, sort, callback) {
const query = {}
// Make an exact search with the magnet
- if (field === 'magnetUri' || field === 'tags') {
+ if (field === 'magnetUri') {
+ const infoHash = magnetUtil.decode(value).infoHash
+ query.magnet = {
+ infoHash
+ }
+ } else if (field === 'tags') {
query[field] = value
} else {
query[field] = new RegExp(value, 'i')
generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback)
}
-function generateThumbnailFromBase64 (video, thumbnailData, callback) {
- // Creating the thumbnail for this remote video)
-
- const thumbnailName = video.getThumbnailName()
- const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
- fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) {
- if (err) return callback(err)
-
- return callback(null, thumbnailName)
- })
-}
-
function generateImage (video, videoPath, folder, imageName, size, callback) {
const options = {
filename: imageName,