+ getVideo (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo {
+ return extractVideo(this.getVideoOrStreamingPlaylist())
+ }
+
+ isAudio () {
+ return this.resolution === VideoResolution.H_NOVIDEO
+ }
+
+ isLive () {
+ return this.size === -1
+ }
+
+ isHLS () {
+ return !!this.videoStreamingPlaylistId
+ }
+
+ getObjectStorageUrl () {
+ if (this.isHLS()) {
+ return getHLSPublicFileUrl(this.fileUrl)
+ }
+
+ return getWebTorrentPublicFileUrl(this.fileUrl)
+ }
+
+ getFileUrl (video: MVideo) {
+ if (this.storage === VideoStorage.OBJECT_STORAGE) {
+ return this.getObjectStorageUrl()
+ }
+
+ if (!this.Video) this.Video = video as VideoModel
+ if (video.isOwned()) return WEBSERVER.URL + this.getFileStaticPath(video)
+
+ return this.fileUrl
+ }
+
+ getFileStaticPath (video: MVideo) {
+ if (this.isHLS()) return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, video.uuid, this.filename)
+
+ return join(STATIC_PATHS.WEBSEED, this.filename)
+ }
+
+ getFileDownloadUrl (video: MVideoWithHost) {
+ const path = this.isHLS()
+ ? join(STATIC_DOWNLOAD_PATHS.HLS_VIDEOS, `${video.uuid}-${this.resolution}-fragmented${this.extname}`)
+ : join(STATIC_DOWNLOAD_PATHS.VIDEOS, `${video.uuid}-${this.resolution}${this.extname}`)
+
+ if (video.isOwned()) return WEBSERVER.URL + path
+
+ // FIXME: don't guess remote URL
+ return buildRemoteVideoBaseUrl(video, path)
+ }
+
+ getRemoteTorrentUrl (video: MVideo) {
+ if (video.isOwned()) throw new Error(`Video ${video.url} is not a remote video`)
+
+ return this.torrentUrl
+ }
+
+ // We proxify torrent requests so use a local URL
+ getTorrentUrl () {
+ if (!this.torrentFilename) return null
+
+ return WEBSERVER.URL + this.getTorrentStaticPath()
+ }
+
+ getTorrentStaticPath () {
+ if (!this.torrentFilename) return null
+
+ return join(LAZY_STATIC_PATHS.TORRENTS, this.torrentFilename)
+ }
+
+ getTorrentDownloadUrl () {
+ if (!this.torrentFilename) return null
+
+ return WEBSERVER.URL + join(STATIC_DOWNLOAD_PATHS.TORRENTS, this.torrentFilename)
+ }
+
+ removeTorrent () {
+ if (!this.torrentFilename) return null
+
+ const torrentPath = getFSTorrentFilePath(this)
+ return remove(torrentPath)
+ .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
+ }
+
+ hasSameUniqueKeysThan (other: MVideoFile) {