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'
18 import { isBooleanValid } from '../../helpers/custom-validators/misc'
20 isVideoCategoryValid, isVideoDescriptionValid, isVideoDurationValid, isVideoLanguageValid, isVideoLicenceValid, isVideoNameValid,
22 } from '../../helpers/custom-validators/videos'
23 import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils'
24 import { logger } from '../../helpers/logger'
26 API_VERSION, CONFIG, CONSTRAINTS_FIELDS, PREVIEWS_SIZE, REMOTE_SCHEME, STATIC_PATHS, THUMBNAILS_SIZE, VIDEO_CATEGORIES,
27 VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES
28 } from '../../initializers'
29 import { getAnnounceActivityPubUrl } from '../../lib/activitypub'
30 import { sendDeleteVideo } from '../../lib/activitypub/send'
31 import { AccountModel } from '../account/account'
32 import { AccountVideoRateModel } from '../account/account-video-rate'
33 import { ActorModel } from '../activitypub/actor'
34 import { ServerModel } from '../server/server'
35 import { getSort, throwIfNotValid } from '../utils'
36 import { TagModel } from './tag'
37 import { VideoAbuseModel } from './video-abuse'
38 import { VideoChannelModel } from './video-channel'
39 import { VideoCommentModel } from './video-comment'
40 import { VideoFileModel } from './video-file'
41 import { VideoShareModel } from './video-share'
42 import { VideoTagModel } from './video-tag'
45 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
46 WITH_ACCOUNT = 'WITH_ACCOUNT',
47 WITH_TAGS = 'WITH_TAGS',
48 WITH_FILES = 'WITH_FILES',
49 WITH_SHARES = 'WITH_SHARES',
50 WITH_RATES = 'WITH_RATES',
51 WITH_COMMENTS = 'WITH_COMMENTS'
55 [ScopeNames.AVAILABLE_FOR_LIST]: {
58 [Sequelize.Op.notIn]: Sequelize.literal(
59 '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
62 privacy: VideoPrivacy.PUBLIC
65 [ScopeNames.WITH_ACCOUNT]: {
68 model: () => VideoChannelModel,
72 model: () => AccountModel,
76 model: () => ActorModel,
80 model: () => ServerModel,
91 [ScopeNames.WITH_TAGS]: {
92 include: [ () => TagModel ]
94 [ScopeNames.WITH_FILES]: {
97 model: () => VideoFileModel,
102 [ScopeNames.WITH_SHARES]: {
105 model: () => VideoShareModel,
106 include: [ () => ActorModel ]
110 [ScopeNames.WITH_RATES]: {
113 model: () => AccountVideoRateModel,
114 include: [ () => AccountModel ]
118 [ScopeNames.WITH_COMMENTS]: {
121 model: () => VideoCommentModel
133 fields: [ 'createdAt' ]
136 fields: [ 'duration' ]
148 fields: [ 'channelId' ]
152 export class VideoModel extends Model<VideoModel> {
155 @Default(DataType.UUIDV4)
157 @Column(DataType.UUID)
161 @Is('VideoName', value => throwIfNotValid(value, isVideoNameValid, 'name'))
167 @Is('VideoCategory', value => throwIfNotValid(value, isVideoCategoryValid, 'category'))
173 @Is('VideoLicence', value => throwIfNotValid(value, isVideoLicenceValid, 'licence'))
179 @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language'))
184 @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy'))
189 @Is('VideoNSFW', value => throwIfNotValid(value, isBooleanValid, 'NSFW boolean'))
195 @Is('VideoDescription', value => throwIfNotValid(value, isVideoDescriptionValid, 'description'))
196 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max))
200 @Is('VideoDuration', value => throwIfNotValid(value, isVideoDurationValid, 'duration'))
230 @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
231 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
236 commentsEnabled: boolean
244 @ForeignKey(() => VideoChannelModel)
248 @BelongsTo(() => VideoChannelModel, {
254 VideoChannel: VideoChannelModel
256 @BelongsToMany(() => TagModel, {
257 foreignKey: 'videoId',
258 through: () => VideoTagModel,
263 @HasMany(() => VideoAbuseModel, {
270 VideoAbuses: VideoAbuseModel[]
272 @HasMany(() => VideoFileModel, {
279 VideoFiles: VideoFileModel[]
281 @HasMany(() => VideoShareModel, {
288 VideoShares: VideoShareModel[]
290 @HasMany(() => AccountVideoRateModel, {
297 AccountVideoRates: AccountVideoRateModel[]
299 @HasMany(() => VideoCommentModel, {
306 VideoComments: VideoCommentModel[]
309 static removeFilesAndSendDelete (instance: VideoModel) {
313 instance.removeThumbnail()
316 if (instance.isOwned()) {
318 instance.removePreview(),
319 sendDeleteVideo(instance, undefined)
322 // Remove physical files and torrents
323 instance.VideoFiles.forEach(file => {
324 tasks.push(instance.removeFile(file))
325 tasks.push(instance.removeTorrent(file))
329 return Promise.all(tasks)
331 logger.error('Some errors when removing files of video %s in after destroy hook.', instance.uuid, err)
336 return VideoModel.scope(ScopeNames.WITH_FILES).findAll()
339 static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {
340 function getRawQuery (select: string) {
341 const queryVideo = 'SELECT ' + select + ' FROM "video" AS "Video" ' +
342 'INNER JOIN "videoChannel" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
343 'INNER JOIN "account" AS "Account" ON "Account"."id" = "VideoChannel"."accountId" ' +
344 'WHERE "Account"."actorId" = ' + actorId
345 const queryVideoShare = 'SELECT ' + select + ' FROM "videoShare" AS "VideoShare" ' +
346 'INNER JOIN "video" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' +
347 'WHERE "VideoShare"."actorId" = ' + actorId
349 return `(${queryVideo}) UNION (${queryVideoShare})`
352 const rawQuery = getRawQuery('"Video"."id"')
353 const rawCountQuery = getRawQuery('COUNT("Video"."id") as "total"')
359 order: [ getSort('createdAt'), [ 'Tags', 'name', 'ASC' ] ],
362 [Sequelize.Op.in]: Sequelize.literal('(' + rawQuery + ')')
367 model: VideoShareModel,
370 [Sequelize.Op.and]: [
373 [Sequelize.Op.not]: null
389 model: VideoChannelModel,
399 model: AccountVideoRateModel,
400 include: [ AccountModel ]
408 return Bluebird.all([
409 // FIXME: typing issue
410 VideoModel.findAll(query as any),
411 VideoModel.sequelize.query(rawCountQuery, { type: Sequelize.QueryTypes.SELECT })
412 ]).then(([ rows, totals ]) => {
413 // totals: totalVideos + totalVideoShares
415 let totalVideoShares = 0
416 if (totals[0]) totalVideos = parseInt(totals[0].total, 10)
417 if (totals[1]) totalVideoShares = parseInt(totals[1].total, 10)
419 const total = totalVideos + totalVideoShares
427 static listUserVideosForApi (userId: number, start: number, count: number, sort: string) {
431 order: [ getSort(sort) ],
434 model: VideoChannelModel,
449 return VideoModel.findAndCountAll(query).then(({ rows, count }) => {
457 static listForApi (start: number, count: number, sort: string) {
461 order: [ getSort(sort) ]
464 return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST, ScopeNames.WITH_ACCOUNT ])
465 .findAndCountAll(query)
466 .then(({ rows, count }) => {
474 static load (id: number) {
475 return VideoModel.findById(id)
478 static loadByUrl (url: string, t?: Sequelize.Transaction) {
479 const query: IFindOptions<VideoModel> = {
485 if (t !== undefined) query.transaction = t
487 return VideoModel.findOne(query)
490 static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
491 const query: IFindOptions<VideoModel> = {
497 if (t !== undefined) query.transaction = t
499 return VideoModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_FILES ]).findOne(query)
502 static loadByUUIDOrURL (uuid: string, url: string, t?: Sequelize.Transaction) {
503 const query: IFindOptions<VideoModel> = {
512 if (t !== undefined) query.transaction = t
514 return VideoModel.scope(ScopeNames.WITH_FILES).findOne(query)
517 static loadAndPopulateAccountAndServerAndTags (id: number) {
519 order: [ [ 'Tags', 'name', 'ASC' ] ]
523 .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
524 .findById(id, options)
527 static loadByUUID (uuid: string) {
535 .scope([ ScopeNames.WITH_FILES ])
539 static loadByUUIDAndPopulateAccountAndServerAndTags (uuid: string) {
541 order: [ [ 'Tags', 'name', 'ASC' ] ],
548 .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
552 static loadAndPopulateAll (id: number) {
554 order: [ [ 'Tags', 'name', 'ASC' ] ],
562 ScopeNames.WITH_RATES,
563 ScopeNames.WITH_SHARES,
564 ScopeNames.WITH_TAGS,
565 ScopeNames.WITH_FILES,
566 ScopeNames.WITH_ACCOUNT,
567 ScopeNames.WITH_COMMENTS
572 static searchAndPopulateAccountAndServerAndTags (value: string, start: number, count: number, sort: string) {
573 const serverInclude: IIncludeOptions = {
578 const accountInclude: IIncludeOptions = {
584 include: [ serverInclude ]
589 const videoChannelInclude: IIncludeOptions = {
590 model: VideoChannelModel,
591 include: [ accountInclude ],
595 const tagInclude: IIncludeOptions = {
599 const query: IFindOptions<VideoModel> = {
600 distinct: true, // Because we have tags
603 order: [ getSort(sort) ],
607 // TODO: search on tags too
608 // const escapedValue = Video['sequelize'].escape('%' + value + '%')
609 // query.where['id'][Sequelize.Op.in] = Video['sequelize'].literal(
610 // `(SELECT "VideoTags"."videoId"
612 // INNER JOIN "VideoTags" ON "Tags"."id" = "VideoTags"."tagId"
613 // WHERE name ILIKE ${escapedValue}
617 // TODO: search on account too
618 // accountInclude.where = {
620 // [Sequelize.Op.iLike]: '%' + value + '%'
623 query.where['name'] = {
624 [Sequelize.Op.iLike]: '%' + value + '%'
628 videoChannelInclude, tagInclude
631 return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST ])
632 .findAndCountAll(query).then(({ rows, count }) => {
641 if (Array.isArray(this.VideoFiles) === false) return undefined
643 // The original file is the file that have the higher resolution
644 return maxBy(this.VideoFiles, file => file.resolution)
647 getVideoFilename (videoFile: VideoFileModel) {
648 return this.uuid + '-' + videoFile.resolution + videoFile.extname
651 getThumbnailName () {
652 // We always have a copy of the thumbnail
653 const extension = '.jpg'
654 return this.uuid + extension
658 const extension = '.jpg'
659 return this.uuid + extension
662 getTorrentFileName (videoFile: VideoFileModel) {
663 const extension = '.torrent'
664 return this.uuid + '-' + videoFile.resolution + extension
668 return this.remote === false
671 createPreview (videoFile: VideoFileModel) {
672 const imageSize = PREVIEWS_SIZE.width + 'x' + PREVIEWS_SIZE.height
674 return generateImageFromVideoFile(
675 this.getVideoFilePath(videoFile),
676 CONFIG.STORAGE.PREVIEWS_DIR,
677 this.getPreviewName(),
682 createThumbnail (videoFile: VideoFileModel) {
683 const imageSize = THUMBNAILS_SIZE.width + 'x' + THUMBNAILS_SIZE.height
685 return generateImageFromVideoFile(
686 this.getVideoFilePath(videoFile),
687 CONFIG.STORAGE.THUMBNAILS_DIR,
688 this.getThumbnailName(),
693 getVideoFilePath (videoFile: VideoFileModel) {
694 return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
697 createTorrentAndSetInfoHash = async function (videoFile: VideoFileModel) {
700 [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
703 CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
707 const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options)
709 const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
710 logger.info('Creating torrent %s.', filePath)
712 await writeFilePromise(filePath, torrent)
714 const parsedTorrent = parseTorrent(torrent)
715 videoFile.infoHash = parsedTorrent.infoHash
719 return '/videos/embed/' + this.uuid
722 getThumbnailPath () {
723 return join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName())
727 return join(STATIC_PATHS.PREVIEWS, this.getPreviewName())
733 if (this.VideoChannel.Account.Actor.Server) {
734 serverHost = this.VideoChannel.Account.Actor.Server.host
736 // It means it's our video
737 serverHost = CONFIG.WEBSERVER.HOST
744 category: this.category,
745 categoryLabel: this.getCategoryLabel(),
746 licence: this.licence,
747 licenceLabel: this.getLicenceLabel(),
748 language: this.language,
749 languageLabel: this.getLanguageLabel(),
751 description: this.getTruncatedDescription(),
753 isLocal: this.isOwned(),
754 accountName: this.VideoChannel.Account.name,
755 duration: this.duration,
758 dislikes: this.dislikes,
759 thumbnailPath: this.getThumbnailPath(),
760 previewPath: this.getPreviewPath(),
761 embedPath: this.getEmbedPath(),
762 createdAt: this.createdAt,
763 updatedAt: this.updatedAt
767 toFormattedDetailsJSON () {
768 const formattedJson = this.toFormattedJSON()
770 // Maybe our server is not up to date and there are new privacy settings since our version
771 let privacyLabel = VIDEO_PRIVACIES[this.privacy]
772 if (!privacyLabel) privacyLabel = 'Unknown'
774 const detailsJson = {
776 privacy: this.privacy,
777 descriptionPath: this.getDescriptionPath(),
778 channel: this.VideoChannel.toFormattedJSON(),
779 account: this.VideoChannel.Account.toFormattedJSON(),
780 tags: map<TagModel, string>(this.Tags, 'name'),
781 commentsEnabled: this.commentsEnabled,
785 // Format and sort video files
786 const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
787 detailsJson.files = this.VideoFiles
789 let resolutionLabel = videoFile.resolution + 'p'
792 resolution: videoFile.resolution,
794 magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs),
795 size: videoFile.size,
796 torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp),
797 fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp)
801 if (a.resolution < b.resolution) return 1
802 if (a.resolution === b.resolution) return 0
806 return Object.assign(formattedJson, detailsJson) as VideoDetails
809 toActivityPubObject (): VideoTorrentObject {
810 const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
811 if (!this.Tags) this.Tags = []
813 const tag = this.Tags.map(t => ({
814 type: 'Hashtag' as 'Hashtag',
821 identifier: this.language + '',
822 name: this.getLanguageLabel()
829 identifier: this.category + '',
830 name: this.getCategoryLabel()
837 identifier: this.licence + '',
838 name: this.getLicenceLabel()
845 if (Array.isArray(this.AccountVideoRates)) {
846 const likes: string[] = []
847 const dislikes: string[] = []
849 for (const rate of this.AccountVideoRates) {
850 if (rate.type === 'like') {
851 likes.push(rate.Account.Actor.url)
852 } else if (rate.type === 'dislike') {
853 dislikes.push(rate.Account.Actor.url)
857 likesObject = activityPubCollection(likes)
858 dislikesObject = activityPubCollection(dislikes)
862 if (Array.isArray(this.VideoShares)) {
863 const shares: string[] = []
865 for (const videoShare of this.VideoShares) {
866 const shareUrl = getAnnounceActivityPubUrl(this.url, videoShare.Actor)
867 shares.push(shareUrl)
870 sharesObject = activityPubCollection(shares)
874 if (Array.isArray(this.VideoComments)) {
875 const comments: string[] = []
877 for (const videoComment of this.VideoComments) {
878 comments.push(videoComment.url)
881 commentsObject = activityPubCollection(comments)
885 for (const file of this.VideoFiles) {
888 mimeType: 'video/' + file.extname.replace('.', ''),
889 url: this.getVideoFileUrl(file, baseUrlHttp),
890 width: file.resolution,
896 mimeType: 'application/x-bittorrent',
897 url: this.getTorrentUrl(file, baseUrlHttp),
898 width: file.resolution
903 mimeType: 'application/x-bittorrent;x-scheme-handler/magnet',
904 url: this.generateMagnetUri(file, baseUrlHttp, baseUrlWs),
905 width: file.resolution
912 mimeType: 'text/html',
913 url: CONFIG.WEBSERVER.URL + '/videos/watch/' + this.uuid
917 type: 'Video' as 'Video',
920 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
921 duration: 'PT' + this.duration + 'S',
929 commentsEnabled: this.commentsEnabled,
930 published: this.createdAt.toISOString(),
931 updated: this.updatedAt.toISOString(),
932 mediaType: 'text/markdown',
933 content: this.getTruncatedDescription(),
936 url: this.getThumbnailUrl(baseUrlHttp),
937 mediaType: 'image/jpeg',
938 width: THUMBNAILS_SIZE.width,
939 height: THUMBNAILS_SIZE.height
943 dislikes: dislikesObject,
944 shares: sharesObject,
945 comments: commentsObject,
949 id: this.VideoChannel.Actor.url
955 getTruncatedDescription () {
956 if (!this.description) return null
959 length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
962 return truncate(this.description, options)
965 optimizeOriginalVideofile = async function () {
966 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
967 const newExtname = '.mp4'
968 const inputVideoFile = this.getOriginalFile()
969 const videoInputPath = join(videosDirectory, this.getVideoFilename(inputVideoFile))
970 const videoOutputPath = join(videosDirectory, this.id + '-transcoded' + newExtname)
972 const transcodeOptions = {
973 inputPath: videoInputPath,
974 outputPath: videoOutputPath
978 // Could be very long!
979 await transcode(transcodeOptions)
981 await unlinkPromise(videoInputPath)
983 // Important to do this before getVideoFilename() to take in account the new file extension
984 inputVideoFile.set('extname', newExtname)
986 await renamePromise(videoOutputPath, this.getVideoFilePath(inputVideoFile))
987 const stats = await statPromise(this.getVideoFilePath(inputVideoFile))
989 inputVideoFile.set('size', stats.size)
991 await this.createTorrentAndSetInfoHash(inputVideoFile)
992 await inputVideoFile.save()
995 // Auto destruction...
996 this.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', err))
1002 transcodeOriginalVideofile = async function (resolution: VideoResolution) {
1003 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
1004 const extname = '.mp4'
1006 // We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed
1007 const videoInputPath = join(videosDirectory, this.getVideoFilename(this.getOriginalFile()))
1009 const newVideoFile = new VideoFileModel({
1015 const videoOutputPath = join(videosDirectory, this.getVideoFilename(newVideoFile))
1017 const transcodeOptions = {
1018 inputPath: videoInputPath,
1019 outputPath: videoOutputPath,
1023 await transcode(transcodeOptions)
1025 const stats = await statPromise(videoOutputPath)
1027 newVideoFile.set('size', stats.size)
1029 await this.createTorrentAndSetInfoHash(newVideoFile)
1031 await newVideoFile.save()
1033 this.VideoFiles.push(newVideoFile)
1036 getOriginalFileHeight () {
1037 const originalFilePath = this.getVideoFilePath(this.getOriginalFile())
1039 return getVideoFileHeight(originalFilePath)
1042 getDescriptionPath () {
1043 return `/api/${API_VERSION}/videos/${this.uuid}/description`
1046 getCategoryLabel () {
1047 let categoryLabel = VIDEO_CATEGORIES[this.category]
1048 if (!categoryLabel) categoryLabel = 'Misc'
1050 return categoryLabel
1053 getLicenceLabel () {
1054 let licenceLabel = VIDEO_LICENCES[this.licence]
1055 if (!licenceLabel) licenceLabel = 'Unknown'
1060 getLanguageLabel () {
1061 let languageLabel = VIDEO_LANGUAGES[this.language]
1062 if (!languageLabel) languageLabel = 'Unknown'
1064 return languageLabel
1067 removeThumbnail () {
1068 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
1069 return unlinkPromise(thumbnailPath)
1073 // Same name than video thumbnail
1074 return unlinkPromise(CONFIG.STORAGE.PREVIEWS_DIR + this.getPreviewName())
1077 removeFile (videoFile: VideoFileModel) {
1078 const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
1079 return unlinkPromise(filePath)
1082 removeTorrent (videoFile: VideoFileModel) {
1083 const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
1084 return unlinkPromise(torrentPath)
1087 private getBaseUrls () {
1091 if (this.isOwned()) {
1092 baseUrlHttp = CONFIG.WEBSERVER.URL
1093 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
1095 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host
1096 baseUrlWs = REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host
1099 return { baseUrlHttp, baseUrlWs }
1102 private getThumbnailUrl (baseUrlHttp: string) {
1103 return baseUrlHttp + STATIC_PATHS.THUMBNAILS + this.getThumbnailName()
1106 private getTorrentUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
1107 return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile)
1110 private getVideoFileUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
1111 return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
1114 private generateMagnetUri (videoFile: VideoFileModel, baseUrlHttp: string, baseUrlWs: string) {
1115 const xs = this.getTorrentUrl(videoFile, baseUrlHttp)
1116 const announce = [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ]
1117 const urlList = [ this.getVideoFileUrl(videoFile, baseUrlHttp) ]
1119 const magnetHash = {
1123 infoHash: videoFile.infoHash,
1127 return magnetUtil.encode(magnetHash)