+ }
+
+ createThumbnail (videoFile: VideoFileModel) {
+ return generateImageFromVideoFile(
+ this.getVideoFilePath(videoFile),
+ CONFIG.STORAGE.THUMBNAILS_DIR,
+ this.getThumbnailName(),
+ THUMBNAILS_SIZE
+ )
+ }
+
+ getTorrentFilePath (videoFile: VideoFileModel) {
+ return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
+ }
+
+ getVideoFilePath (videoFile: VideoFileModel) {
+ return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
+ }
+
+ async createTorrentAndSetInfoHash (videoFile: VideoFileModel) {
+ const options = {
+ // Keep the extname, it's used by the client to stream the file inside a web browser
+ name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`,
+ createdBy: 'PeerTube',
+ announceList: [
+ [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ],
+ [ CONFIG.WEBSERVER.URL + '/tracker/announce' ]
+ ],
+ urlList: [
+ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
+ ]
+ }
+
+ const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options)
+
+ const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
+ logger.info('Creating torrent %s.', filePath)
+
+ await writeFile(filePath, torrent)
+
+ const parsedTorrent = parseTorrent(torrent)
+ videoFile.infoHash = parsedTorrent.infoHash
+ }
+
+ getEmbedStaticPath () {
+ return '/videos/embed/' + this.uuid
+ }
+
+ getThumbnailStaticPath () {
+ return join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName())
+ }
+
+ getPreviewStaticPath () {
+ return join(STATIC_PATHS.PREVIEWS, this.getPreviewName())
+ }
+
+ toFormattedJSON (options?: {
+ additionalAttributes: {
+ state?: boolean,
+ waitTranscoding?: boolean,
+ scheduledUpdate?: boolean,
+ blacklistInfo?: boolean
+ }
+ }): Video {
+ const formattedAccount = this.VideoChannel.Account.toFormattedJSON()
+ const formattedVideoChannel = this.VideoChannel.toFormattedJSON()
+
+ const videoObject: Video = {
+ id: this.id,
+ uuid: this.uuid,
+ name: this.name,
+ category: {
+ id: this.category,
+ label: VideoModel.getCategoryLabel(this.category)
+ },
+ licence: {
+ id: this.licence,
+ label: VideoModel.getLicenceLabel(this.licence)
+ },
+ language: {
+ id: this.language,
+ label: VideoModel.getLanguageLabel(this.language)
+ },
+ privacy: {
+ id: this.privacy,
+ label: VideoModel.getPrivacyLabel(this.privacy)
+ },
+ nsfw: this.nsfw,
+ description: this.getTruncatedDescription(),
+ isLocal: this.isOwned(),
+ duration: this.duration,
+ views: this.views,
+ likes: this.likes,
+ dislikes: this.dislikes,
+ thumbnailPath: this.getThumbnailStaticPath(),
+ previewPath: this.getPreviewStaticPath(),
+ embedPath: this.getEmbedStaticPath(),
+ createdAt: this.createdAt,
+ updatedAt: this.updatedAt,
+ publishedAt: this.publishedAt,
+ account: {
+ id: formattedAccount.id,
+ uuid: formattedAccount.uuid,
+ name: formattedAccount.name,
+ displayName: formattedAccount.displayName,
+ url: formattedAccount.url,
+ host: formattedAccount.host,
+ avatar: formattedAccount.avatar
+ },
+ channel: {
+ id: formattedVideoChannel.id,
+ uuid: formattedVideoChannel.uuid,
+ name: formattedVideoChannel.name,
+ displayName: formattedVideoChannel.displayName,
+ url: formattedVideoChannel.url,
+ host: formattedVideoChannel.host,
+ avatar: formattedVideoChannel.avatar