+createPreview = function (this: VideoInstance, videoFile: VideoFileInstance) {
+ return generateImage(this, this.getVideoFilePath(videoFile), CONFIG.STORAGE.PREVIEWS_DIR, this.getPreviewName(), null)
+}
+
+createThumbnail = function (this: VideoInstance, videoFile: VideoFileInstance) {
+ return generateImage(this, this.getVideoFilePath(videoFile), CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName(), THUMBNAILS_SIZE)
+}
+
+getVideoFilePath = function (this: VideoInstance, videoFile: VideoFileInstance) {
+ return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
+}
+
+createTorrentAndSetInfoHash = function (this: VideoInstance, videoFile: VideoFileInstance) {
+ const options = {
+ announceList: [
+ [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
+ ],
+ urlList: [
+ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
+ ]
+ }
+
+ return createTorrentPromise(this.getVideoFilePath(videoFile), options)
+ .then(torrent => {
+ const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
+ return writeFilePromise(filePath, torrent).then(() => torrent)
+ })
+ .then(torrent => {
+ const parsedTorrent = parseTorrent(torrent)
+
+ videoFile.infoHash = parsedTorrent.infoHash
+ })
+}
+
+generateMagnetUri = function (this: VideoInstance, videoFile: VideoFileInstance) {
+ let baseUrlHttp
+ let baseUrlWs
+
+ if (this.isOwned()) {
+ baseUrlHttp = CONFIG.WEBSERVER.URL
+ baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
+ } else {
+ baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.Author.Pod.host
+ baseUrlWs = REMOTE_SCHEME.WS + '://' + this.Author.Pod.host
+ }
+
+ const xs = baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile)
+ const announce = [ baseUrlWs + '/tracker/socket' ]
+ const urlList = [ baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) ]
+
+ const magnetHash = {
+ xs,
+ announce,
+ urlList,
+ infoHash: videoFile.infoHash,
+ name: this.name
+ }
+
+ return magnetUtil.encode(magnetHash)
+}
+
+toFormattedJSON = function (this: VideoInstance) {