1 import * as Bluebird from 'bluebird'
2 import { maxBy, minBy } from 'lodash'
3 import { join } from 'path'
36 } from 'sequelize-typescript'
37 import { UserRight, VideoPrivacy, VideoState } from '../../../shared'
38 import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
39 import { Video, VideoDetails } from '../../../shared/models/videos'
40 import { VideoFilter } from '../../../shared/models/videos/video-query.type'
41 import { peertubeTruncate } from '../../helpers/core-utils'
42 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
43 import { isBooleanValid } from '../../helpers/custom-validators/misc'
46 isVideoDescriptionValid,
54 } from '../../helpers/custom-validators/videos'
55 import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
56 import { logger } from '../../helpers/logger'
57 import { getServerActor } from '../../helpers/utils'
64 STATIC_DOWNLOAD_PATHS,
72 } from '../../initializers/constants'
73 import { sendDeleteVideo } from '../../lib/activitypub/send'
74 import { AccountModel } from '../account/account'
75 import { AccountVideoRateModel } from '../account/account-video-rate'
76 import { ActorModel } from '../activitypub/actor'
77 import { AvatarModel } from '../avatar/avatar'
78 import { ServerModel } from '../server/server'
80 buildBlockedAccountSQL,
81 buildTrigramSearchIndex,
84 createSimilarityAttribute,
89 import { TagModel } from './tag'
90 import { VideoAbuseModel } from './video-abuse'
91 import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel'
92 import { VideoCommentModel } from './video-comment'
93 import { VideoFileModel } from './video-file'
94 import { VideoShareModel } from './video-share'
95 import { VideoTagModel } from './video-tag'
96 import { ScheduleVideoUpdateModel } from './schedule-video-update'
97 import { VideoCaptionModel } from './video-caption'
98 import { VideoBlacklistModel } from './video-blacklist'
99 import { remove } from 'fs-extra'
100 import { VideoViewModel } from './video-views'
101 import { VideoRedundancyModel } from '../redundancy/video-redundancy'
103 videoFilesModelToFormattedJSON,
104 VideoFormattingJSONOptions,
105 videoModelToActivityPubObject,
106 videoModelToFormattedDetailsJSON,
107 videoModelToFormattedJSON
108 } from './video-format-utils'
109 import { UserVideoHistoryModel } from '../account/user-video-history'
110 import { VideoImportModel } from './video-import'
111 import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
112 import { VideoPlaylistElementModel } from './video-playlist-element'
113 import { CONFIG } from '../../initializers/config'
114 import { ThumbnailModel } from './thumbnail'
115 import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
116 import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
119 MChannelAccountDefault,
122 MStreamingPlaylistFilesVideo,
126 MVideoAccountLightBlacklistAllFiles,
131 MVideoFormattableDetails,
136 MVideoThumbnailBlacklist,
140 } from '../../typings/models'
141 import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
142 import { MThumbnail } from '../../typings/models/video/thumbnail'
143 import { VideoFile } from '@shared/models/videos/video-file.model'
144 import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
145 import validator from 'validator'
147 // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
148 const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [
149 buildTrigramSearchIndex('video_name_trigram', 'name'),
151 { fields: [ 'createdAt' ] },
154 { name: 'publishedAt', order: 'DESC' },
155 { name: 'id', order: 'ASC' }
158 { fields: [ 'duration' ] },
159 { fields: [ 'views' ] },
160 { fields: [ 'channelId' ] },
162 fields: [ 'originallyPublishedAt' ],
164 originallyPublishedAt: {
170 fields: [ 'category' ], // We don't care videos with an unknown category
178 fields: [ 'licence' ], // We don't care videos with an unknown licence
186 fields: [ 'language' ], // We don't care videos with an unknown language
194 fields: [ 'nsfw' ], // Most of the videos are not NSFW
200 fields: [ 'remote' ], // Only index local videos
215 export enum ScopeNames {
216 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
218 WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS',
219 WITH_TAGS = 'WITH_TAGS',
220 WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES',
221 WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE',
222 WITH_BLACKLISTED = 'WITH_BLACKLISTED',
223 WITH_USER_HISTORY = 'WITH_USER_HISTORY',
224 WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS',
225 WITH_USER_ID = 'WITH_USER_ID',
226 WITH_THUMBNAILS = 'WITH_THUMBNAILS'
229 export type ForAPIOptions = {
232 videoPlaylistId?: number
236 withAccountBlockerIds?: number[]
239 export type AvailableForListIDsOptions = {
240 serverAccountId: number
241 followerActorId: number
242 includeLocalVideos: boolean
244 attributesType?: 'none' | 'id' | 'all'
247 categoryOneOf?: number[]
249 licenceOneOf?: number[]
250 languageOneOf?: string[]
257 videoChannelId?: number
259 videoPlaylistId?: number
261 trendingDays?: number
262 user?: MUserAccountId
263 historyOfUser?: MUserId
265 baseWhere?: WhereOptions[]
269 [ ScopeNames.FOR_API ]: (options: ForAPIOptions) => {
270 const query: FindOptions = {
273 model: VideoChannelModel.scope({
275 VideoChannelScopeNames.SUMMARY, {
277 withAccountBlockerIds: options.withAccountBlockerIds
284 attributes: [ 'type', 'filename' ],
285 model: ThumbnailModel,
294 [ Op.in ]: options.ids // FIXME: sequelize ANY seems broken
299 if (options.withFiles === true) {
301 model: VideoFileModel.unscoped(),
306 if (options.videoPlaylistId) {
308 model: VideoPlaylistElementModel.unscoped(),
311 videoPlaylistId: options.videoPlaylistId
318 [ ScopeNames.AVAILABLE_FOR_LIST_IDS ]: (options: AvailableForListIDsOptions) => {
319 const whereAnd = options.baseWhere ? [].concat(options.baseWhere) : []
321 const query: FindOptions = {
326 const attributesType = options.attributesType || 'id'
328 if (attributesType === 'id') query.attributes = [ 'id' ]
329 else if (attributesType === 'none') query.attributes = [ ]
333 [ Op.notIn ]: Sequelize.literal(
334 '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
339 if (options.serverAccountId) {
342 [ Op.notIn ]: Sequelize.literal(
344 'SELECT id FROM "videoChannel" WHERE "accountId" IN (' +
345 buildBlockedAccountSQL(options.serverAccountId, options.user ? options.user.Account.id : undefined) +
353 // Only list public/published videos
354 if (!options.filter || options.filter !== 'all-local') {
356 const publishWhere = {
357 // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding
360 state: VideoState.PUBLISHED
364 state: VideoState.TO_TRANSCODE,
365 waitTranscoding: false
370 whereAnd.push(publishWhere)
372 // List internal videos if the user is logged in
374 const privacyWhere = {
377 privacy: VideoPrivacy.INTERNAL
380 privacy: VideoPrivacy.PUBLIC
385 whereAnd.push(privacyWhere)
386 } else { // Or only public videos
387 const privacyWhere = { privacy: VideoPrivacy.PUBLIC }
388 whereAnd.push(privacyWhere)
392 if (options.videoPlaylistId) {
395 model: VideoPlaylistElementModel.unscoped(),
398 videoPlaylistId: options.videoPlaylistId
402 query.subQuery = false
405 if (options.filter && (options.filter === 'local' || options.filter === 'all-local')) {
411 if (options.accountId || options.videoChannelId) {
412 const videoChannelInclude: IncludeOptions = {
414 model: VideoChannelModel.unscoped(),
418 if (options.videoChannelId) {
419 videoChannelInclude.where = {
420 id: options.videoChannelId
424 if (options.accountId) {
425 const accountInclude: IncludeOptions = {
427 model: AccountModel.unscoped(),
431 accountInclude.where = { id: options.accountId }
432 videoChannelInclude.include = [ accountInclude ]
435 query.include.push(videoChannelInclude)
438 if (options.followerActorId) {
439 let localVideosReq = ''
440 if (options.includeLocalVideos === true) {
441 localVideosReq = ' UNION ALL SELECT "video"."id" FROM "video" WHERE remote IS FALSE'
444 // Force actorId to be a number to avoid SQL injections
445 const actorIdNumber = parseInt(options.followerActorId.toString(), 10)
448 [Op.in]: Sequelize.literal(
450 'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' +
451 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
452 'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
454 'SELECT "video"."id" AS "id" FROM "video" ' +
455 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
456 'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' +
457 'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' +
458 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' +
459 'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
467 if (options.withFiles === true) {
470 [ Op.in ]: Sequelize.literal(
471 '(SELECT "videoId" FROM "videoFile")'
477 // FIXME: issues with sequelize count when making a join on n:m relation, so we just make a IN()
478 if (options.tagsAllOf || options.tagsOneOf) {
479 if (options.tagsOneOf) {
480 const tagsOneOfLower = options.tagsOneOf.map(t => t.toLowerCase())
484 [ Op.in ]: Sequelize.literal(
486 'SELECT "videoId" FROM "videoTag" ' +
487 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
488 'WHERE lower("tag"."name") IN (' + createSafeIn(VideoModel, tagsOneOfLower) + ')' +
495 if (options.tagsAllOf) {
496 const tagsAllOfLower = options.tagsAllOf.map(t => t.toLowerCase())
500 [ Op.in ]: Sequelize.literal(
502 'SELECT "videoId" FROM "videoTag" ' +
503 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
504 'WHERE lower("tag"."name") IN (' + createSafeIn(VideoModel, tagsAllOfLower) + ')' +
505 'GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + tagsAllOfLower.length +
513 if (options.nsfw === true || options.nsfw === false) {
514 whereAnd.push({ nsfw: options.nsfw })
517 if (options.categoryOneOf) {
520 [ Op.or ]: options.categoryOneOf
525 if (options.licenceOneOf) {
528 [ Op.or ]: options.licenceOneOf
533 if (options.languageOneOf) {
534 let videoLanguages = options.languageOneOf
535 if (options.languageOneOf.find(l => l === '_unknown')) {
536 videoLanguages = videoLanguages.concat([ null ])
543 [ Op.or ]: videoLanguages
548 [ Op.in ]: Sequelize.literal(
550 'SELECT "videoId" FROM "videoCaption" ' +
551 'WHERE "language" IN (' + createSafeIn(VideoModel, options.languageOneOf) + ') ' +
560 if (options.trendingDays) {
561 query.include.push(VideoModel.buildTrendingQuery(options.trendingDays))
563 query.subQuery = false
566 if (options.historyOfUser) {
568 model: UserVideoHistoryModel,
571 userId: options.historyOfUser.id
575 // Even if the relation is n:m, we know that a user only have 0..1 video history
576 // So we won't have multiple rows for the same video
577 // Without this, we would not be able to sort on "updatedAt" column of UserVideoHistoryModel
578 query.subQuery = false
587 [ ScopeNames.WITH_THUMBNAILS ]: {
590 model: ThumbnailModel,
595 [ ScopeNames.WITH_USER_ID ]: {
598 attributes: [ 'accountId' ],
599 model: VideoChannelModel.unscoped(),
603 attributes: [ 'userId' ],
604 model: AccountModel.unscoped(),
611 [ ScopeNames.WITH_ACCOUNT_DETAILS ]: {
614 model: VideoChannelModel.unscoped(),
619 exclude: [ 'privateKey', 'publicKey' ]
621 model: ActorModel.unscoped(),
625 attributes: [ 'host' ],
626 model: ServerModel.unscoped(),
630 model: AvatarModel.unscoped(),
636 model: AccountModel.unscoped(),
640 model: ActorModel.unscoped(),
642 exclude: [ 'privateKey', 'publicKey' ]
647 attributes: [ 'host' ],
648 model: ServerModel.unscoped(),
652 model: AvatarModel.unscoped(),
663 [ ScopeNames.WITH_TAGS ]: {
664 include: [ TagModel ]
666 [ ScopeNames.WITH_BLACKLISTED ]: {
669 attributes: [ 'id', 'reason', 'unfederated' ],
670 model: VideoBlacklistModel,
675 [ ScopeNames.WITH_WEBTORRENT_FILES ]: (withRedundancies = false) => {
676 let subInclude: any[] = []
678 if (withRedundancies === true) {
681 attributes: [ 'fileUrl' ],
682 model: VideoRedundancyModel.unscoped(),
691 model: VideoFileModel.unscoped(),
692 separate: true, // We may have multiple files, having multiple redundancies so let's separate this join
699 [ ScopeNames.WITH_STREAMING_PLAYLISTS ]: (withRedundancies = false) => {
700 const subInclude: IncludeOptions[] = [
702 model: VideoFileModel.unscoped(),
707 if (withRedundancies === true) {
709 attributes: [ 'fileUrl' ],
710 model: VideoRedundancyModel.unscoped(),
718 model: VideoStreamingPlaylistModel.unscoped(),
719 separate: true, // We may have multiple streaming playlists, having multiple redundancies so let's separate this join
726 [ ScopeNames.WITH_SCHEDULED_UPDATE ]: {
729 model: ScheduleVideoUpdateModel.unscoped(),
734 [ ScopeNames.WITH_USER_HISTORY ]: (userId: number) => {
738 attributes: [ 'currentTime' ],
739 model: UserVideoHistoryModel.unscoped(),
753 export class VideoModel extends Model<VideoModel> {
756 @Default(DataType.UUIDV4)
758 @Column(DataType.UUID)
762 @Is('VideoName', value => throwIfNotValid(value, isVideoNameValid, 'name'))
768 @Is('VideoCategory', value => throwIfNotValid(value, isVideoCategoryValid, 'category', true))
774 @Is('VideoLicence', value => throwIfNotValid(value, isVideoLicenceValid, 'licence', true))
780 @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language', true))
781 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max))
785 @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy'))
790 @Is('VideoNSFW', value => throwIfNotValid(value, isBooleanValid, 'NSFW boolean'))
796 @Is('VideoDescription', value => throwIfNotValid(value, isVideoDescriptionValid, 'description', true))
797 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max))
802 @Is('VideoSupport', value => throwIfNotValid(value, isVideoSupportValid, 'support', true))
803 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.SUPPORT.max))
807 @Is('VideoDuration', value => throwIfNotValid(value, isVideoDurationValid, 'duration'))
837 @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
838 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
843 commentsEnabled: boolean
847 downloadEnabled: boolean
851 waitTranscoding: boolean
855 @Is('VideoState', value => throwIfNotValid(value, isVideoStateValid, 'state'))
866 @Default(DataType.NOW)
873 originallyPublishedAt: Date
875 @ForeignKey(() => VideoChannelModel)
879 @BelongsTo(() => VideoChannelModel, {
885 VideoChannel: VideoChannelModel
887 @BelongsToMany(() => TagModel, {
888 foreignKey: 'videoId',
889 through: () => VideoTagModel,
894 @HasMany(() => ThumbnailModel, {
902 Thumbnails: ThumbnailModel[]
904 @HasMany(() => VideoPlaylistElementModel, {
911 VideoPlaylistElements: VideoPlaylistElementModel[]
913 @HasMany(() => VideoAbuseModel, {
920 VideoAbuses: VideoAbuseModel[]
922 @HasMany(() => VideoFileModel, {
930 VideoFiles: VideoFileModel[]
932 @HasMany(() => VideoStreamingPlaylistModel, {
940 VideoStreamingPlaylists: VideoStreamingPlaylistModel[]
942 @HasMany(() => VideoShareModel, {
949 VideoShares: VideoShareModel[]
951 @HasMany(() => AccountVideoRateModel, {
958 AccountVideoRates: AccountVideoRateModel[]
960 @HasMany(() => VideoCommentModel, {
968 VideoComments: VideoCommentModel[]
970 @HasMany(() => VideoViewModel, {
977 VideoViews: VideoViewModel[]
979 @HasMany(() => UserVideoHistoryModel, {
986 UserVideoHistories: UserVideoHistoryModel[]
988 @HasOne(() => ScheduleVideoUpdateModel, {
995 ScheduleVideoUpdate: ScheduleVideoUpdateModel
997 @HasOne(() => VideoBlacklistModel, {
1004 VideoBlacklist: VideoBlacklistModel
1006 @HasOne(() => VideoImportModel, {
1011 onDelete: 'set null'
1013 VideoImport: VideoImportModel
1015 @HasMany(() => VideoCaptionModel, {
1020 onDelete: 'cascade',
1022 [ 'separate' as any ]: true
1024 VideoCaptions: VideoCaptionModel[]
1027 static async sendDelete (instance: MVideoAccountLight, options) {
1028 if (instance.isOwned()) {
1029 if (!instance.VideoChannel) {
1030 instance.VideoChannel = await instance.$get('VideoChannel', {
1035 transaction: options.transaction
1036 }) as MChannelAccountDefault
1039 return sendDeleteVideo(instance, options.transaction)
1046 static async removeFiles (instance: VideoModel) {
1047 const tasks: Promise<any>[] = []
1049 logger.info('Removing files of video %s.', instance.url)
1051 if (instance.isOwned()) {
1052 if (!Array.isArray(instance.VideoFiles)) {
1053 instance.VideoFiles = await instance.$get('VideoFiles')
1056 // Remove physical files and torrents
1057 instance.VideoFiles.forEach(file => {
1058 tasks.push(instance.removeFile(file))
1059 tasks.push(instance.removeTorrent(file))
1062 // Remove playlists file
1063 if (!Array.isArray(instance.VideoStreamingPlaylists)) {
1064 instance.VideoStreamingPlaylists = await instance.$get('VideoStreamingPlaylists')
1067 for (const p of instance.VideoStreamingPlaylists) {
1068 tasks.push(instance.removeStreamingPlaylistFiles(p))
1072 // Do not wait video deletion because we could be in a transaction
1075 logger.error('Some errors when removing files of video %s in before destroy hook.', instance.uuid, { err })
1081 static listLocal (): Bluebird<MVideoWithAllFiles[]> {
1088 return VideoModel.scope([
1089 ScopeNames.WITH_WEBTORRENT_FILES,
1090 ScopeNames.WITH_STREAMING_PLAYLISTS,
1091 ScopeNames.WITH_THUMBNAILS
1095 static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {
1096 function getRawQuery (select: string) {
1097 const queryVideo = 'SELECT ' + select + ' FROM "video" AS "Video" ' +
1098 'INNER JOIN "videoChannel" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
1099 'INNER JOIN "account" AS "Account" ON "Account"."id" = "VideoChannel"."accountId" ' +
1100 'WHERE "Account"."actorId" = ' + actorId
1101 const queryVideoShare = 'SELECT ' + select + ' FROM "videoShare" AS "VideoShare" ' +
1102 'INNER JOIN "video" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' +
1103 'WHERE "VideoShare"."actorId" = ' + actorId
1105 return `(${queryVideo}) UNION (${queryVideoShare})`
1108 const rawQuery = getRawQuery('"Video"."id"')
1109 const rawCountQuery = getRawQuery('COUNT("Video"."id") as "total"')
1115 order: getVideoSort('createdAt', [ 'Tags', 'name', 'ASC' ] as any), // FIXME: sequelize typings
1118 [ Op.in ]: Sequelize.literal('(' + rawQuery + ')')
1121 { privacy: VideoPrivacy.PUBLIC },
1122 { privacy: VideoPrivacy.UNLISTED }
1127 attributes: [ 'language' ],
1128 model: VideoCaptionModel.unscoped(),
1132 attributes: [ 'id', 'url' ],
1133 model: VideoShareModel.unscoped(),
1135 // We only want videos shared by this actor
1150 attributes: [ 'id', 'url' ],
1151 model: ActorModel.unscoped()
1156 model: VideoChannelModel.unscoped(),
1160 attributes: [ 'name' ],
1161 model: AccountModel.unscoped(),
1165 attributes: [ 'id', 'url', 'followersUrl' ],
1166 model: ActorModel.unscoped(),
1172 attributes: [ 'id', 'url', 'followersUrl' ],
1173 model: ActorModel.unscoped(),
1183 return Bluebird.all([
1184 VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findAll(query),
1185 VideoModel.sequelize.query<{ total: string }>(rawCountQuery, { type: QueryTypes.SELECT })
1186 ]).then(([ rows, totals ]) => {
1187 // totals: totalVideos + totalVideoShares
1189 let totalVideoShares = 0
1190 if (totals[ 0 ]) totalVideos = parseInt(totals[ 0 ].total, 10)
1191 if (totals[ 1 ]) totalVideoShares = parseInt(totals[ 1 ].total, 10)
1193 const total = totalVideos + totalVideoShares
1201 static listUserVideosForApi (
1208 function buildBaseQuery (): FindOptions {
1212 order: getVideoSort(sort),
1215 model: VideoChannelModel,
1219 model: AccountModel,
1231 baseQuery = Object.assign(baseQuery, {
1234 [ Op.iLike ]: '%' + search + '%'
1243 const countQuery = buildBaseQuery()
1244 const findQuery = buildBaseQuery()
1246 const findScopes: (string | ScopeOptions)[] = [
1247 ScopeNames.WITH_SCHEDULED_UPDATE,
1248 ScopeNames.WITH_BLACKLISTED,
1249 ScopeNames.WITH_THUMBNAILS
1252 return Promise.all([
1253 VideoModel.count(countQuery),
1254 VideoModel.scope(findScopes).findAll<MVideoForUser>(findQuery)
1255 ]).then(([ count, rows ]) => {
1263 static async listForApi (options: {
1268 includeLocalVideos: boolean,
1270 categoryOneOf?: number[],
1271 licenceOneOf?: number[],
1272 languageOneOf?: string[],
1273 tagsOneOf?: string[],
1274 tagsAllOf?: string[],
1275 filter?: VideoFilter,
1277 videoChannelId?: number,
1278 followerActorId?: number
1279 videoPlaylistId?: number,
1280 trendingDays?: number,
1281 user?: MUserAccountId,
1282 historyOfUser?: MUserId,
1283 countVideos?: boolean
1285 if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
1286 throw new Error('Try to filter all-local but no user has not the see all videos right')
1289 const query: FindOptions & { where?: null } = {
1290 offset: options.start,
1291 limit: options.count,
1292 order: getVideoSort(options.sort)
1295 let trendingDays: number
1296 if (options.sort.endsWith('trending')) {
1297 trendingDays = CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS
1299 query.group = 'VideoModel.id'
1302 const serverActor = await getServerActor()
1304 // followerActorId === null has a meaning, so just check undefined
1305 const followerActorId = options.followerActorId !== undefined ? options.followerActorId : serverActor.id
1307 const queryOptions = {
1309 serverAccountId: serverActor.Account.id,
1311 categoryOneOf: options.categoryOneOf,
1312 licenceOneOf: options.licenceOneOf,
1313 languageOneOf: options.languageOneOf,
1314 tagsOneOf: options.tagsOneOf,
1315 tagsAllOf: options.tagsAllOf,
1316 filter: options.filter,
1317 withFiles: options.withFiles,
1318 accountId: options.accountId,
1319 videoChannelId: options.videoChannelId,
1320 videoPlaylistId: options.videoPlaylistId,
1321 includeLocalVideos: options.includeLocalVideos,
1323 historyOfUser: options.historyOfUser,
1327 return VideoModel.getAvailableForApi(query, queryOptions, options.countVideos)
1330 static async searchAndPopulateAccountAndServer (options: {
1331 includeLocalVideos: boolean
1336 startDate?: string // ISO 8601
1337 endDate?: string // ISO 8601
1338 originallyPublishedStartDate?: string
1339 originallyPublishedEndDate?: string
1341 categoryOneOf?: number[]
1342 licenceOneOf?: number[]
1343 languageOneOf?: string[]
1344 tagsOneOf?: string[]
1345 tagsAllOf?: string[]
1346 durationMin?: number // seconds
1347 durationMax?: number // seconds
1348 user?: MUserAccountId,
1349 filter?: VideoFilter
1353 if (options.startDate || options.endDate) {
1354 const publishedAtRange = {}
1356 if (options.startDate) publishedAtRange[ Op.gte ] = options.startDate
1357 if (options.endDate) publishedAtRange[ Op.lte ] = options.endDate
1359 whereAnd.push({ publishedAt: publishedAtRange })
1362 if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) {
1363 const originallyPublishedAtRange = {}
1365 if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Op.gte ] = options.originallyPublishedStartDate
1366 if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Op.lte ] = options.originallyPublishedEndDate
1368 whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange })
1371 if (options.durationMin || options.durationMax) {
1372 const durationRange = {}
1374 if (options.durationMin) durationRange[ Op.gte ] = options.durationMin
1375 if (options.durationMax) durationRange[ Op.lte ] = options.durationMax
1377 whereAnd.push({ duration: durationRange })
1380 const attributesInclude = []
1381 const escapedSearch = VideoModel.sequelize.escape(options.search)
1382 const escapedLikeSearch = VideoModel.sequelize.escape('%' + options.search + '%')
1383 if (options.search) {
1384 const trigramSearch = {
1386 [ Op.in ]: Sequelize.literal(
1388 'SELECT "video"."id" FROM "video" ' +
1390 'lower(immutable_unaccent("video"."name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' +
1391 'lower(immutable_unaccent("video"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' +
1393 'SELECT "video"."id" FROM "video" LEFT JOIN "videoTag" ON "videoTag"."videoId" = "video"."id" ' +
1394 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
1395 'WHERE lower("tag"."name") = lower(' + escapedSearch + ')' +
1401 if (validator.isUUID(options.search)) {
1406 uuid: options.search
1411 whereAnd.push(trigramSearch)
1414 attributesInclude.push(createSimilarityAttribute('VideoModel.name', options.search))
1417 // Cannot search on similarity if we don't have a search
1418 if (!options.search) {
1419 attributesInclude.push(
1420 Sequelize.literal('0 as similarity')
1426 include: attributesInclude
1428 offset: options.start,
1429 limit: options.count,
1430 order: getVideoSort(options.sort)
1433 const serverActor = await getServerActor()
1434 const queryOptions = {
1435 followerActorId: serverActor.id,
1436 serverAccountId: serverActor.Account.id,
1437 includeLocalVideos: options.includeLocalVideos,
1439 categoryOneOf: options.categoryOneOf,
1440 licenceOneOf: options.licenceOneOf,
1441 languageOneOf: options.languageOneOf,
1442 tagsOneOf: options.tagsOneOf,
1443 tagsAllOf: options.tagsAllOf,
1445 filter: options.filter,
1449 return VideoModel.getAvailableForApi(query, queryOptions)
1452 static load (id: number | string, t?: Transaction): Bluebird<MVideoThumbnail> {
1453 const where = buildWhereIdOrUUID(id)
1459 return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
1462 static loadWithBlacklist (id: number | string, t?: Transaction): Bluebird<MVideoThumbnailBlacklist> {
1463 const where = buildWhereIdOrUUID(id)
1469 return VideoModel.scope([
1470 ScopeNames.WITH_THUMBNAILS,
1471 ScopeNames.WITH_BLACKLISTED
1475 static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> {
1476 const where = buildWhereIdOrUUID(id)
1482 return VideoModel.scope([
1483 ScopeNames.WITH_BLACKLISTED,
1484 ScopeNames.WITH_USER_ID,
1485 ScopeNames.WITH_THUMBNAILS
1489 static loadOnlyId (id: number | string, t?: Transaction): Bluebird<MVideoIdThumbnail> {
1490 const where = buildWhereIdOrUUID(id)
1493 attributes: [ 'id' ],
1498 return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
1501 static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Bluebird<MVideoWithAllFiles> {
1502 const where = buildWhereIdOrUUID(id)
1510 return VideoModel.scope([
1511 ScopeNames.WITH_WEBTORRENT_FILES,
1512 ScopeNames.WITH_STREAMING_PLAYLISTS,
1513 ScopeNames.WITH_THUMBNAILS
1517 static loadByUUID (uuid: string): Bluebird<MVideoThumbnail> {
1524 return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
1527 static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoThumbnail> {
1528 const query: FindOptions = {
1535 return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query)
1538 static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> {
1539 const query: FindOptions = {
1546 return VideoModel.scope([
1547 ScopeNames.WITH_ACCOUNT_DETAILS,
1548 ScopeNames.WITH_WEBTORRENT_FILES,
1549 ScopeNames.WITH_STREAMING_PLAYLISTS,
1550 ScopeNames.WITH_THUMBNAILS,
1551 ScopeNames.WITH_BLACKLISTED
1555 static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Bluebird<MVideoFullLight> {
1556 const where = buildWhereIdOrUUID(id)
1559 order: [ [ 'Tags', 'name', 'ASC' ] ] as any,
1564 const scopes: (string | ScopeOptions)[] = [
1565 ScopeNames.WITH_TAGS,
1566 ScopeNames.WITH_BLACKLISTED,
1567 ScopeNames.WITH_ACCOUNT_DETAILS,
1568 ScopeNames.WITH_SCHEDULED_UPDATE,
1569 ScopeNames.WITH_WEBTORRENT_FILES,
1570 ScopeNames.WITH_STREAMING_PLAYLISTS,
1571 ScopeNames.WITH_THUMBNAILS
1575 scopes.push({ method: [ ScopeNames.WITH_USER_HISTORY, userId ] })
1583 static loadForGetAPI (parameters: {
1584 id: number | string,
1587 }): Bluebird<MVideoDetails> {
1588 const { id, t, userId } = parameters
1589 const where = buildWhereIdOrUUID(id)
1592 order: [ [ 'Tags', 'name', 'ASC' ] ] as any, // FIXME: sequelize typings
1597 const scopes: (string | ScopeOptions)[] = [
1598 ScopeNames.WITH_TAGS,
1599 ScopeNames.WITH_BLACKLISTED,
1600 ScopeNames.WITH_ACCOUNT_DETAILS,
1601 ScopeNames.WITH_SCHEDULED_UPDATE,
1602 ScopeNames.WITH_THUMBNAILS,
1603 { method: [ ScopeNames.WITH_WEBTORRENT_FILES, true ] },
1604 { method: [ ScopeNames.WITH_STREAMING_PLAYLISTS, true ] }
1608 scopes.push({ method: [ ScopeNames.WITH_USER_HISTORY, userId ] })
1616 static async getStats () {
1617 const totalLocalVideos = await VideoModel.count({
1622 const totalVideos = await VideoModel.count()
1624 let totalLocalVideoViews = await VideoModel.sum('views', {
1629 // Sequelize could return null...
1630 if (!totalLocalVideoViews) totalLocalVideoViews = 0
1634 totalLocalVideoViews,
1639 static incrementViews (id: number, views: number) {
1640 return VideoModel.increment('views', {
1648 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) {
1649 // Instances only share videos
1650 const query = 'SELECT 1 FROM "videoShare" ' +
1651 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
1652 'WHERE "actorFollow"."actorId" = $followerActorId AND "videoShare"."videoId" = $videoId ' +
1656 type: QueryTypes.SELECT as QueryTypes.SELECT,
1657 bind: { followerActorId, videoId },
1661 return VideoModel.sequelize.query(query, options)
1662 .then(results => results.length === 1)
1665 static bulkUpdateSupportField (videoChannel: MChannel, t: Transaction) {
1668 channelId: videoChannel.id
1673 return VideoModel.update({ support: videoChannel.support }, options)
1676 static getAllIdsFromChannel (videoChannel: MChannelId): Bluebird<number[]> {
1678 attributes: [ 'id' ],
1680 channelId: videoChannel.id
1684 return VideoModel.findAll(query)
1685 .then(videos => videos.map(v => v.id))
1688 // threshold corresponds to how many video the field should have to be returned
1689 static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) {
1690 const serverActor = await getServerActor()
1691 const followerActorId = serverActor.id
1693 const scopeOptions: AvailableForListIDsOptions = {
1694 serverAccountId: serverActor.Account.id,
1696 includeLocalVideos: true,
1697 attributesType: 'none' // Don't break aggregation
1700 const query: FindOptions = {
1701 attributes: [ field ],
1704 having: Sequelize.where(
1705 Sequelize.fn('COUNT', Sequelize.col(field)), { [ Op.gte ]: threshold }
1707 order: [ (this.sequelize as any).random() ]
1710 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST_IDS, scopeOptions ] })
1712 .then(rows => rows.map(r => r[ field ]))
1715 static buildTrendingQuery (trendingDays: number) {
1719 model: VideoViewModel,
1723 [ Op.gte ]: new Date(new Date().getTime() - (24 * 3600 * 1000) * trendingDays)
1729 private static async getAvailableForApi (
1730 query: FindOptions & { where?: null }, // Forbid where field in query
1731 options: AvailableForListIDsOptions,
1734 const idsScope: ScopeOptions = {
1736 ScopeNames.AVAILABLE_FOR_LIST_IDS, options
1740 // Remove trending sort on count, because it uses a group by
1741 const countOptions = Object.assign({}, options, { trendingDays: undefined })
1742 const countQuery: CountOptions = Object.assign({}, query, { attributes: undefined, group: undefined })
1743 const countScope: ScopeOptions = {
1745 ScopeNames.AVAILABLE_FOR_LIST_IDS, countOptions
1749 const [ count, rows ] = await Promise.all([
1751 ? VideoModel.scope(countScope).count(countQuery)
1752 : Promise.resolve<number>(undefined),
1754 VideoModel.scope(idsScope)
1755 .findAll(Object.assign({}, query, { raw: true }))
1756 .then(rows => rows.map(r => r.id))
1757 .then(ids => VideoModel.loadCompleteVideosForApi(ids, query, options))
1766 private static loadCompleteVideosForApi (ids: number[], query: FindOptions, options: AvailableForListIDsOptions) {
1767 if (ids.length === 0) return []
1769 const secondQuery: FindOptions = {
1772 attributes: query.attributes,
1773 order: [ // Keep original order
1775 ids.map(id => `"VideoModel".id = ${id} DESC`).join(', ')
1780 const apiScope: (string | ScopeOptions)[] = []
1783 apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] })
1788 ScopeNames.FOR_API, {
1790 withFiles: options.withFiles,
1791 videoPlaylistId: options.videoPlaylistId
1796 return VideoModel.scope(apiScope).findAll(secondQuery)
1799 private static isPrivacyForFederation (privacy: VideoPrivacy) {
1800 const castedPrivacy = parseInt(privacy + '', 10)
1802 return castedPrivacy === VideoPrivacy.PUBLIC || castedPrivacy === VideoPrivacy.UNLISTED
1805 static getCategoryLabel (id: number) {
1806 return VIDEO_CATEGORIES[ id ] || 'Misc'
1809 static getLicenceLabel (id: number) {
1810 return VIDEO_LICENCES[ id ] || 'Unknown'
1813 static getLanguageLabel (id: string) {
1814 return VIDEO_LANGUAGES[ id ] || 'Unknown'
1817 static getPrivacyLabel (id: number) {
1818 return VIDEO_PRIVACIES[ id ] || 'Unknown'
1821 static getStateLabel (id: number) {
1822 return VIDEO_STATES[ id ] || 'Unknown'
1826 return !!this.VideoBlacklist
1830 return (this.VideoChannel.Account.Actor.Server && this.VideoChannel.Account.Actor.Server.isBlocked()) ||
1831 this.VideoChannel.Account.isBlocked()
1834 getQualityFileBy <T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) {
1835 if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) {
1836 const file = fun(this.VideoFiles, file => file.resolution)
1838 return Object.assign(file, { Video: this })
1841 // No webtorrent files, try with streaming playlist files
1842 if (Array.isArray(this.VideoStreamingPlaylists) && this.VideoStreamingPlaylists.length !== 0) {
1843 const streamingPlaylistWithVideo = Object.assign(this.VideoStreamingPlaylists[0], { Video: this })
1845 const file = fun(streamingPlaylistWithVideo.VideoFiles, file => file.resolution)
1846 return Object.assign(file, { VideoStreamingPlaylist: streamingPlaylistWithVideo })
1852 getMaxQualityFile <T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo {
1853 return this.getQualityFileBy(maxBy)
1856 getMinQualityFile <T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo {
1857 return this.getQualityFileBy(minBy)
1860 getWebTorrentFile <T extends MVideoWithFile> (this: T, resolution: number): MVideoFileVideo {
1861 if (Array.isArray(this.VideoFiles) === false) return undefined
1863 const file = this.VideoFiles.find(f => f.resolution === resolution)
1864 if (!file) return undefined
1866 return Object.assign(file, { Video: this })
1869 async addAndSaveThumbnail (thumbnail: MThumbnail, transaction: Transaction) {
1870 thumbnail.videoId = this.id
1872 const savedThumbnail = await thumbnail.save({ transaction })
1874 if (Array.isArray(this.Thumbnails) === false) this.Thumbnails = []
1876 // Already have this thumbnail, skip
1877 if (this.Thumbnails.find(t => t.id === savedThumbnail.id)) return
1879 this.Thumbnails.push(savedThumbnail)
1882 generateThumbnailName () {
1883 return this.uuid + '.jpg'
1887 if (Array.isArray(this.Thumbnails) === false) return undefined
1889 return this.Thumbnails.find(t => t.type === ThumbnailType.MINIATURE)
1892 generatePreviewName () {
1893 return this.uuid + '.jpg'
1897 if (Array.isArray(this.Thumbnails) === false) return undefined
1899 return this.Thumbnails.find(t => t.type === ThumbnailType.PREVIEW)
1903 return this.remote === false
1906 getWatchStaticPath () {
1907 return '/videos/watch/' + this.uuid
1910 getEmbedStaticPath () {
1911 return '/videos/embed/' + this.uuid
1914 getMiniatureStaticPath () {
1915 const thumbnail = this.getMiniature()
1916 if (!thumbnail) return null
1918 return join(STATIC_PATHS.THUMBNAILS, thumbnail.filename)
1921 getPreviewStaticPath () {
1922 const preview = this.getPreview()
1923 if (!preview) return null
1925 // We use a local cache, so specify our cache endpoint instead of potential remote URL
1926 return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename)
1929 toFormattedJSON (this: MVideoFormattable, options?: VideoFormattingJSONOptions): Video {
1930 return videoModelToFormattedJSON(this, options)
1933 toFormattedDetailsJSON (this: MVideoFormattableDetails): VideoDetails {
1934 return videoModelToFormattedDetailsJSON(this)
1937 getFormattedVideoFilesJSON (): VideoFile[] {
1938 const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
1939 return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, this.VideoFiles)
1942 toActivityPubObject (this: MVideoAP): VideoTorrentObject {
1943 return videoModelToActivityPubObject(this)
1946 getTruncatedDescription () {
1947 if (!this.description) return null
1949 const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
1950 return peertubeTruncate(this.description, { length: maxLength })
1953 getMaxQualityResolution () {
1954 const file = this.getMaxQualityFile()
1955 const videoOrPlaylist = file.getVideoOrStreamingPlaylist()
1956 const originalFilePath = getVideoFilePath(videoOrPlaylist, file)
1958 return getVideoFileResolution(originalFilePath)
1961 getDescriptionAPIPath () {
1962 return `/api/${API_VERSION}/videos/${this.uuid}/description`
1965 getHLSPlaylist (): MStreamingPlaylistFilesVideo {
1966 if (!this.VideoStreamingPlaylists) return undefined
1968 const playlist = this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
1969 playlist.Video = this
1974 setHLSPlaylist (playlist: MStreamingPlaylist) {
1975 const toAdd = [ playlist ] as [ VideoStreamingPlaylistModel ]
1977 if (Array.isArray(this.VideoStreamingPlaylists) === false || this.VideoStreamingPlaylists.length === 0) {
1978 this.VideoStreamingPlaylists = toAdd
1982 this.VideoStreamingPlaylists = this.VideoStreamingPlaylists
1983 .filter(s => s.type !== VideoStreamingPlaylistType.HLS)
1987 removeFile (videoFile: MVideoFile, isRedundancy = false) {
1988 const filePath = getVideoFilePath(this, videoFile, isRedundancy)
1989 return remove(filePath)
1990 .catch(err => logger.warn('Cannot delete file %s.', filePath, { err }))
1993 removeTorrent (videoFile: MVideoFile) {
1994 const torrentPath = getTorrentFilePath(this, videoFile)
1995 return remove(torrentPath)
1996 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
1999 async removeStreamingPlaylistFiles (streamingPlaylist: MStreamingPlaylist, isRedundancy = false) {
2000 const directoryPath = getHLSDirectory(this, isRedundancy)
2002 await remove(directoryPath)
2004 if (isRedundancy !== true) {
2005 let streamingPlaylistWithFiles = streamingPlaylist as MStreamingPlaylistFilesVideo
2006 streamingPlaylistWithFiles.Video = this
2008 if (!Array.isArray(streamingPlaylistWithFiles.VideoFiles)) {
2009 streamingPlaylistWithFiles.VideoFiles = await streamingPlaylistWithFiles.$get('VideoFiles')
2012 // Remove physical files and torrents
2014 streamingPlaylistWithFiles.VideoFiles.map(file => streamingPlaylistWithFiles.removeTorrent(file))
2020 if (this.isOwned()) return false
2022 return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL)
2025 hasPrivacyForFederation () {
2026 return VideoModel.isPrivacyForFederation(this.privacy)
2029 isNewVideo (newPrivacy: VideoPrivacy) {
2030 return this.hasPrivacyForFederation() === false && VideoModel.isPrivacyForFederation(newPrivacy) === true
2034 this.changed('updatedAt', true)
2040 return this.privacy === VideoPrivacy.PRIVATE || this.privacy === VideoPrivacy.INTERNAL || !!this.VideoBlacklist
2043 setPrivacy (newPrivacy: VideoPrivacy) {
2044 if (this.privacy === VideoPrivacy.PRIVATE && newPrivacy !== VideoPrivacy.PRIVATE) {
2045 this.publishedAt = new Date()
2048 this.privacy = newPrivacy
2052 return this.privacy === VideoPrivacy.PRIVATE ||
2053 this.privacy === VideoPrivacy.UNLISTED ||
2054 this.privacy === VideoPrivacy.INTERNAL
2057 async publishIfNeededAndSave (t: Transaction) {
2058 if (this.state !== VideoState.PUBLISHED) {
2059 this.state = VideoState.PUBLISHED
2060 this.publishedAt = new Date()
2061 await this.save({ transaction: t })
2070 if (this.isOwned()) {
2072 baseUrlHttp: WEBSERVER.URL,
2073 baseUrlWs: WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT
2078 baseUrlHttp: REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host,
2079 baseUrlWs: REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host
2083 getTrackerUrls (baseUrlHttp: string, baseUrlWs: string) {
2084 return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ]
2087 getTorrentUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2088 return baseUrlHttp + STATIC_PATHS.TORRENTS + getTorrentFileName(this, videoFile)
2091 getTorrentDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2092 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + getTorrentFileName(this, videoFile)
2095 getVideoFileUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2096 return baseUrlHttp + STATIC_PATHS.WEBSEED + getVideoFilename(this, videoFile)
2099 getVideoRedundancyUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2100 return baseUrlHttp + STATIC_PATHS.REDUNDANCY + getVideoFilename(this, videoFile)
2103 getVideoFileDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2104 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + getVideoFilename(this, videoFile)
2107 getBandwidthBits (videoFile: MVideoFile) {
2108 return Math.ceil((videoFile.size * 8) / this.duration)