1 import * as Bluebird from 'bluebird'
2 import { map, maxBy, truncate } from 'lodash'
3 import * as magnetUtil from 'magnet-uri'
4 import * as parseTorrent from 'parse-torrent'
5 import { join } from 'path'
6 import * as Sequelize from 'sequelize'
8 AfterDestroy, AllowNull, BelongsTo, BelongsToMany, Column, CreatedAt, DataType, Default, ForeignKey, HasMany, IFindOptions, Is,
9 IsInt, IsUUID, Min, Model, Scopes, Table, UpdatedAt
10 } from 'sequelize-typescript'
11 import { IIncludeOptions } from 'sequelize-typescript/lib/interfaces/IIncludeOptions'
12 import { VideoPrivacy, VideoResolution } from '../../../shared'
13 import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
14 import { Video, VideoDetails } from '../../../shared/models/videos'
15 import { activityPubCollection } from '../../helpers/activitypub'
16 import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
17 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
19 isVideoCategoryValid, isVideoDescriptionValid, isVideoDurationValid, isVideoLanguageValid, isVideoLicenceValid, isVideoNameValid,
20 isVideoNSFWValid, isVideoPrivacyValid
21 } from '../../helpers/custom-validators/videos'
22 import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils'
23 import { logger } from '../../helpers/logger'
25 API_VERSION, CONFIG, CONSTRAINTS_FIELDS, PREVIEWS_SIZE, REMOTE_SCHEME, STATIC_PATHS, THUMBNAILS_SIZE, VIDEO_CATEGORIES,
26 VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES
27 } from '../../initializers'
28 import { getAnnounceActivityPubUrl } from '../../lib/activitypub'
29 import { sendDeleteVideo } from '../../lib/activitypub/send'
30 import { AccountModel } from '../account/account'
31 import { AccountVideoRateModel } from '../account/account-video-rate'
32 import { ActorModel } from '../activitypub/actor'
33 import { ServerModel } from '../server/server'
34 import { getSort, throwIfNotValid } from '../utils'
35 import { TagModel } from './tag'
36 import { VideoAbuseModel } from './video-abuse'
37 import { VideoChannelModel } from './video-channel'
38 import { VideoCommentModel } from './video-comment'
39 import { VideoFileModel } from './video-file'
40 import { VideoShareModel } from './video-share'
41 import { VideoTagModel } from './video-tag'
44 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
45 WITH_ACCOUNT = 'WITH_ACCOUNT',
46 WITH_TAGS = 'WITH_TAGS',
47 WITH_FILES = 'WITH_FILES',
48 WITH_SHARES = 'WITH_SHARES',
49 WITH_RATES = 'WITH_RATES',
50 WITH_COMMENTS = 'WITH_COMMENTS'
54 [ScopeNames.AVAILABLE_FOR_LIST]: {
57 [Sequelize.Op.notIn]: Sequelize.literal(
58 '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
61 privacy: VideoPrivacy.PUBLIC
64 [ScopeNames.WITH_ACCOUNT]: {
67 model: () => VideoChannelModel,
71 model: () => AccountModel,
75 model: () => ActorModel,
79 model: () => ServerModel,
90 [ScopeNames.WITH_TAGS]: {
91 include: [ () => TagModel ]
93 [ScopeNames.WITH_FILES]: {
96 model: () => VideoFileModel,
101 [ScopeNames.WITH_SHARES]: {
104 model: () => VideoShareModel,
105 include: [ () => ActorModel ]
109 [ScopeNames.WITH_RATES]: {
112 model: () => AccountVideoRateModel,
113 include: [ () => AccountModel ]
117 [ScopeNames.WITH_COMMENTS]: {
120 model: () => VideoCommentModel
132 fields: [ 'createdAt' ]
135 fields: [ 'duration' ]
147 fields: [ 'channelId' ]
151 export class VideoModel extends Model<VideoModel> {
154 @Default(DataType.UUIDV4)
156 @Column(DataType.UUID)
160 @Is('VideoName', value => throwIfNotValid(value, isVideoNameValid, 'name'))
166 @Is('VideoCategory', value => throwIfNotValid(value, isVideoCategoryValid, 'category'))
172 @Is('VideoLicence', value => throwIfNotValid(value, isVideoLicenceValid, 'licence'))
178 @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language'))
183 @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy'))
188 @Is('VideoNSFW', value => throwIfNotValid(value, isVideoNSFWValid, 'NSFW boolean'))
194 @Is('VideoDescription', value => throwIfNotValid(value, isVideoDescriptionValid, 'description'))
195 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max))
199 @Is('VideoDuration', value => throwIfNotValid(value, isVideoDurationValid, 'duration'))
229 @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
230 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
239 @ForeignKey(() => VideoChannelModel)
243 @BelongsTo(() => VideoChannelModel, {
249 VideoChannel: VideoChannelModel
251 @BelongsToMany(() => TagModel, {
252 foreignKey: 'videoId',
253 through: () => VideoTagModel,
258 @HasMany(() => VideoAbuseModel, {
265 VideoAbuses: VideoAbuseModel[]
267 @HasMany(() => VideoFileModel, {
274 VideoFiles: VideoFileModel[]
276 @HasMany(() => VideoShareModel, {
283 VideoShares: VideoShareModel[]
285 @HasMany(() => AccountVideoRateModel, {
292 AccountVideoRates: AccountVideoRateModel[]
294 @HasMany(() => VideoCommentModel, {
301 VideoComments: VideoCommentModel[]
304 static removeFilesAndSendDelete (instance: VideoModel) {
308 instance.removeThumbnail()
311 if (instance.isOwned()) {
313 instance.removePreview(),
314 sendDeleteVideo(instance, undefined)
317 // Remove physical files and torrents
318 instance.VideoFiles.forEach(file => {
319 tasks.push(instance.removeFile(file))
320 tasks.push(instance.removeTorrent(file))
324 return Promise.all(tasks)
326 logger.error('Some errors when removing files of video %s in after destroy hook.', instance.uuid, err)
331 return VideoModel.scope(ScopeNames.WITH_FILES).findAll()
334 static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {
335 function getRawQuery (select: string) {
336 const queryVideo = 'SELECT ' + select + ' FROM "video" AS "Video" ' +
337 'INNER JOIN "videoChannel" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
338 'INNER JOIN "account" AS "Account" ON "Account"."id" = "VideoChannel"."accountId" ' +
339 'WHERE "Account"."actorId" = ' + actorId
340 const queryVideoShare = 'SELECT ' + select + ' FROM "videoShare" AS "VideoShare" ' +
341 'INNER JOIN "video" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' +
342 'WHERE "VideoShare"."actorId" = ' + actorId
344 return `(${queryVideo}) UNION (${queryVideoShare})`
347 const rawQuery = getRawQuery('"Video"."id"')
348 const rawCountQuery = getRawQuery('COUNT("Video"."id") as "total"')
354 order: [ getSort('createdAt'), [ 'Tags', 'name', 'ASC' ] ],
357 [Sequelize.Op.in]: Sequelize.literal('(' + rawQuery + ')')
362 model: VideoShareModel,
365 [Sequelize.Op.and]: [
368 [Sequelize.Op.not]: null
384 model: VideoChannelModel,
394 model: AccountVideoRateModel,
395 include: [ AccountModel ]
403 return Bluebird.all([
404 // FIXME: typing issue
405 VideoModel.findAll(query as any),
406 VideoModel.sequelize.query(rawCountQuery, { type: Sequelize.QueryTypes.SELECT })
407 ]).then(([ rows, totals ]) => {
408 // totals: totalVideos + totalVideoShares
410 let totalVideoShares = 0
411 if (totals[0]) totalVideos = parseInt(totals[0].total, 10)
412 if (totals[1]) totalVideoShares = parseInt(totals[1].total, 10)
414 const total = totalVideos + totalVideoShares
422 static listUserVideosForApi (userId: number, start: number, count: number, sort: string) {
426 order: [ getSort(sort) ],
429 model: VideoChannelModel,
444 return VideoModel.findAndCountAll(query).then(({ rows, count }) => {
452 static listForApi (start: number, count: number, sort: string) {
456 order: [ getSort(sort) ]
459 return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST, ScopeNames.WITH_ACCOUNT ])
460 .findAndCountAll(query)
461 .then(({ rows, count }) => {
469 static load (id: number) {
470 return VideoModel.findById(id)
473 static loadByUrl (url: string, t?: Sequelize.Transaction) {
474 const query: IFindOptions<VideoModel> = {
480 if (t !== undefined) query.transaction = t
482 return VideoModel.findOne(query)
485 static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
486 const query: IFindOptions<VideoModel> = {
492 if (t !== undefined) query.transaction = t
494 return VideoModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_FILES ]).findOne(query)
497 static loadByUUIDOrURL (uuid: string, url: string, t?: Sequelize.Transaction) {
498 const query: IFindOptions<VideoModel> = {
507 if (t !== undefined) query.transaction = t
509 return VideoModel.scope(ScopeNames.WITH_FILES).findOne(query)
512 static loadAndPopulateAccountAndServerAndTags (id: number) {
514 order: [ [ 'Tags', 'name', 'ASC' ] ]
518 .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
519 .findById(id, options)
522 static loadByUUID (uuid: string) {
530 .scope([ ScopeNames.WITH_FILES ])
534 static loadByUUIDAndPopulateAccountAndServerAndTags (uuid: string) {
536 order: [ [ 'Tags', 'name', 'ASC' ] ],
543 .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
547 static loadAndPopulateAll (id: number) {
549 order: [ [ 'Tags', 'name', 'ASC' ] ],
557 ScopeNames.WITH_RATES,
558 ScopeNames.WITH_SHARES,
559 ScopeNames.WITH_TAGS,
560 ScopeNames.WITH_FILES,
561 ScopeNames.WITH_ACCOUNT,
562 ScopeNames.WITH_COMMENTS
567 static searchAndPopulateAccountAndServerAndTags (value: string, start: number, count: number, sort: string) {
568 const serverInclude: IIncludeOptions = {
573 const accountInclude: IIncludeOptions = {
579 include: [ serverInclude ]
584 const videoChannelInclude: IIncludeOptions = {
585 model: VideoChannelModel,
586 include: [ accountInclude ],
590 const tagInclude: IIncludeOptions = {
594 const query: IFindOptions<VideoModel> = {
595 distinct: true, // Because we have tags
598 order: [ getSort(sort) ],
602 // TODO: search on tags too
603 // const escapedValue = Video['sequelize'].escape('%' + value + '%')
604 // query.where['id'][Sequelize.Op.in] = Video['sequelize'].literal(
605 // `(SELECT "VideoTags"."videoId"
607 // INNER JOIN "VideoTags" ON "Tags"."id" = "VideoTags"."tagId"
608 // WHERE name ILIKE ${escapedValue}
612 // TODO: search on account too
613 // accountInclude.where = {
615 // [Sequelize.Op.iLike]: '%' + value + '%'
618 query.where['name'] = {
619 [Sequelize.Op.iLike]: '%' + value + '%'
623 videoChannelInclude, tagInclude
626 return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST ])
627 .findAndCountAll(query).then(({ rows, count }) => {
636 if (Array.isArray(this.VideoFiles) === false) return undefined
638 // The original file is the file that have the higher resolution
639 return maxBy(this.VideoFiles, file => file.resolution)
642 getVideoFilename (videoFile: VideoFileModel) {
643 return this.uuid + '-' + videoFile.resolution + videoFile.extname
646 getThumbnailName () {
647 // We always have a copy of the thumbnail
648 const extension = '.jpg'
649 return this.uuid + extension
653 const extension = '.jpg'
654 return this.uuid + extension
657 getTorrentFileName (videoFile: VideoFileModel) {
658 const extension = '.torrent'
659 return this.uuid + '-' + videoFile.resolution + extension
663 return this.remote === false
666 createPreview (videoFile: VideoFileModel) {
667 const imageSize = PREVIEWS_SIZE.width + 'x' + PREVIEWS_SIZE.height
669 return generateImageFromVideoFile(
670 this.getVideoFilePath(videoFile),
671 CONFIG.STORAGE.PREVIEWS_DIR,
672 this.getPreviewName(),
677 createThumbnail (videoFile: VideoFileModel) {
678 const imageSize = THUMBNAILS_SIZE.width + 'x' + THUMBNAILS_SIZE.height
680 return generateImageFromVideoFile(
681 this.getVideoFilePath(videoFile),
682 CONFIG.STORAGE.THUMBNAILS_DIR,
683 this.getThumbnailName(),
688 getVideoFilePath (videoFile: VideoFileModel) {
689 return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
692 createTorrentAndSetInfoHash = async function (videoFile: VideoFileModel) {
695 [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
698 CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
702 const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options)
704 const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
705 logger.info('Creating torrent %s.', filePath)
707 await writeFilePromise(filePath, torrent)
709 const parsedTorrent = parseTorrent(torrent)
710 videoFile.infoHash = parsedTorrent.infoHash
714 return '/videos/embed/' + this.uuid
717 getThumbnailPath () {
718 return join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName())
722 return join(STATIC_PATHS.PREVIEWS, this.getPreviewName())
728 if (this.VideoChannel.Account.Actor.Server) {
729 serverHost = this.VideoChannel.Account.Actor.Server.host
731 // It means it's our video
732 serverHost = CONFIG.WEBSERVER.HOST
739 category: this.category,
740 categoryLabel: this.getCategoryLabel(),
741 licence: this.licence,
742 licenceLabel: this.getLicenceLabel(),
743 language: this.language,
744 languageLabel: this.getLanguageLabel(),
746 description: this.getTruncatedDescription(),
748 isLocal: this.isOwned(),
749 accountName: this.VideoChannel.Account.name,
750 duration: this.duration,
753 dislikes: this.dislikes,
754 thumbnailPath: this.getThumbnailPath(),
755 previewPath: this.getPreviewPath(),
756 embedPath: this.getEmbedPath(),
757 createdAt: this.createdAt,
758 updatedAt: this.updatedAt
762 toFormattedDetailsJSON () {
763 const formattedJson = this.toFormattedJSON()
765 // Maybe our server is not up to date and there are new privacy settings since our version
766 let privacyLabel = VIDEO_PRIVACIES[this.privacy]
767 if (!privacyLabel) privacyLabel = 'Unknown'
769 const detailsJson = {
771 privacy: this.privacy,
772 descriptionPath: this.getDescriptionPath(),
773 channel: this.VideoChannel.toFormattedJSON(),
774 account: this.VideoChannel.Account.toFormattedJSON(),
775 tags: map<TagModel, string>(this.Tags, 'name'),
779 // Format and sort video files
780 const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
781 detailsJson.files = this.VideoFiles
783 let resolutionLabel = videoFile.resolution + 'p'
786 resolution: videoFile.resolution,
788 magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs),
789 size: videoFile.size,
790 torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp),
791 fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp)
795 if (a.resolution < b.resolution) return 1
796 if (a.resolution === b.resolution) return 0
800 return Object.assign(formattedJson, detailsJson) as VideoDetails
803 toActivityPubObject (): VideoTorrentObject {
804 const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
805 if (!this.Tags) this.Tags = []
807 const tag = this.Tags.map(t => ({
808 type: 'Hashtag' as 'Hashtag',
815 identifier: this.language + '',
816 name: this.getLanguageLabel()
823 identifier: this.category + '',
824 name: this.getCategoryLabel()
831 identifier: this.licence + '',
832 name: this.getLicenceLabel()
839 if (Array.isArray(this.AccountVideoRates)) {
840 const likes: string[] = []
841 const dislikes: string[] = []
843 for (const rate of this.AccountVideoRates) {
844 if (rate.type === 'like') {
845 likes.push(rate.Account.Actor.url)
846 } else if (rate.type === 'dislike') {
847 dislikes.push(rate.Account.Actor.url)
851 likesObject = activityPubCollection(likes)
852 dislikesObject = activityPubCollection(dislikes)
856 if (Array.isArray(this.VideoShares)) {
857 const shares: string[] = []
859 for (const videoShare of this.VideoShares) {
860 const shareUrl = getAnnounceActivityPubUrl(this.url, videoShare.Actor)
861 shares.push(shareUrl)
864 sharesObject = activityPubCollection(shares)
868 if (Array.isArray(this.VideoComments)) {
869 const comments: string[] = []
871 for (const videoComment of this.VideoComments) {
872 comments.push(videoComment.url)
875 commentsObject = activityPubCollection(comments)
879 for (const file of this.VideoFiles) {
882 mimeType: 'video/' + file.extname.replace('.', ''),
883 url: this.getVideoFileUrl(file, baseUrlHttp),
884 width: file.resolution,
890 mimeType: 'application/x-bittorrent',
891 url: this.getTorrentUrl(file, baseUrlHttp),
892 width: file.resolution
897 mimeType: 'application/x-bittorrent;x-scheme-handler/magnet',
898 url: this.generateMagnetUri(file, baseUrlHttp, baseUrlWs),
899 width: file.resolution
906 mimeType: 'text/html',
907 url: CONFIG.WEBSERVER.URL + '/videos/watch/' + this.uuid
911 type: 'Video' as 'Video',
914 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
915 duration: 'PT' + this.duration + 'S',
923 published: this.createdAt.toISOString(),
924 updated: this.updatedAt.toISOString(),
925 mediaType: 'text/markdown',
926 content: this.getTruncatedDescription(),
929 url: this.getThumbnailUrl(baseUrlHttp),
930 mediaType: 'image/jpeg',
931 width: THUMBNAILS_SIZE.width,
932 height: THUMBNAILS_SIZE.height
936 dislikes: dislikesObject,
937 shares: sharesObject,
938 comments: commentsObject,
942 id: this.VideoChannel.Actor.url
948 getTruncatedDescription () {
949 if (!this.description) return null
952 length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
955 return truncate(this.description, options)
958 optimizeOriginalVideofile = async function () {
959 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
960 const newExtname = '.mp4'
961 const inputVideoFile = this.getOriginalFile()
962 const videoInputPath = join(videosDirectory, this.getVideoFilename(inputVideoFile))
963 const videoOutputPath = join(videosDirectory, this.id + '-transcoded' + newExtname)
965 const transcodeOptions = {
966 inputPath: videoInputPath,
967 outputPath: videoOutputPath
971 // Could be very long!
972 await transcode(transcodeOptions)
974 await unlinkPromise(videoInputPath)
976 // Important to do this before getVideoFilename() to take in account the new file extension
977 inputVideoFile.set('extname', newExtname)
979 await renamePromise(videoOutputPath, this.getVideoFilePath(inputVideoFile))
980 const stats = await statPromise(this.getVideoFilePath(inputVideoFile))
982 inputVideoFile.set('size', stats.size)
984 await this.createTorrentAndSetInfoHash(inputVideoFile)
985 await inputVideoFile.save()
988 // Auto destruction...
989 this.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', err))
995 transcodeOriginalVideofile = async function (resolution: VideoResolution) {
996 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
997 const extname = '.mp4'
999 // We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed
1000 const videoInputPath = join(videosDirectory, this.getVideoFilename(this.getOriginalFile()))
1002 const newVideoFile = new VideoFileModel({
1008 const videoOutputPath = join(videosDirectory, this.getVideoFilename(newVideoFile))
1010 const transcodeOptions = {
1011 inputPath: videoInputPath,
1012 outputPath: videoOutputPath,
1016 await transcode(transcodeOptions)
1018 const stats = await statPromise(videoOutputPath)
1020 newVideoFile.set('size', stats.size)
1022 await this.createTorrentAndSetInfoHash(newVideoFile)
1024 await newVideoFile.save()
1026 this.VideoFiles.push(newVideoFile)
1029 getOriginalFileHeight () {
1030 const originalFilePath = this.getVideoFilePath(this.getOriginalFile())
1032 return getVideoFileHeight(originalFilePath)
1035 getDescriptionPath () {
1036 return `/api/${API_VERSION}/videos/${this.uuid}/description`
1039 getCategoryLabel () {
1040 let categoryLabel = VIDEO_CATEGORIES[this.category]
1041 if (!categoryLabel) categoryLabel = 'Misc'
1043 return categoryLabel
1046 getLicenceLabel () {
1047 let licenceLabel = VIDEO_LICENCES[this.licence]
1048 if (!licenceLabel) licenceLabel = 'Unknown'
1053 getLanguageLabel () {
1054 let languageLabel = VIDEO_LANGUAGES[this.language]
1055 if (!languageLabel) languageLabel = 'Unknown'
1057 return languageLabel
1060 removeThumbnail () {
1061 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
1062 return unlinkPromise(thumbnailPath)
1066 // Same name than video thumbnail
1067 return unlinkPromise(CONFIG.STORAGE.PREVIEWS_DIR + this.getPreviewName())
1070 removeFile (videoFile: VideoFileModel) {
1071 const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
1072 return unlinkPromise(filePath)
1075 removeTorrent (videoFile: VideoFileModel) {
1076 const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
1077 return unlinkPromise(torrentPath)
1080 private getBaseUrls () {
1084 if (this.isOwned()) {
1085 baseUrlHttp = CONFIG.WEBSERVER.URL
1086 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
1088 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host
1089 baseUrlWs = REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host
1092 return { baseUrlHttp, baseUrlWs }
1095 private getThumbnailUrl (baseUrlHttp: string) {
1096 return baseUrlHttp + STATIC_PATHS.THUMBNAILS + this.getThumbnailName()
1099 private getTorrentUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
1100 return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile)
1103 private getVideoFileUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
1104 return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
1107 private generateMagnetUri (videoFile: VideoFileModel, baseUrlHttp: string, baseUrlWs: string) {
1108 const xs = this.getTorrentUrl(videoFile, baseUrlHttp)
1109 const announce = [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ]
1110 const urlList = [ this.getVideoFileUrl(videoFile, baseUrlHttp) ]
1112 const magnetHash = {
1116 infoHash: videoFile.infoHash,
1120 return magnetUtil.encode(magnetHash)