]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/video/video-interface.ts
Implement video transcoding on server side
[github/Chocobozzz/PeerTube.git] / server / models / video / video-interface.ts
1 import * as Sequelize from 'sequelize'
2 import * as Promise from 'bluebird'
3
4 import { AuthorInstance } from './author-interface'
5 import { TagAttributes, TagInstance } from './tag-interface'
6 import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
7
8 // Don't use barrel, import just what we need
9 import { Video as FormattedVideo } from '../../../shared/models/videos/video.model'
10 import { RemoteVideoUpdateData } from '../../../shared/models/pods/remote-video/remote-video-update-request.model'
11 import { RemoteVideoCreateData } from '../../../shared/models/pods/remote-video/remote-video-create-request.model'
12 import { ResultList } from '../../../shared/models/result-list.model'
13
14 export namespace VideoMethods {
15 export type GetThumbnailName = (this: VideoInstance) => string
16 export type GetPreviewName = (this: VideoInstance) => string
17 export type IsOwned = (this: VideoInstance) => boolean
18 export type ToFormattedJSON = (this: VideoInstance) => FormattedVideo
19
20 export type GetOriginalFile = (this: VideoInstance) => VideoFileInstance
21 export type GenerateMagnetUri = (this: VideoInstance, videoFile: VideoFileInstance) => string
22 export type GetTorrentFileName = (this: VideoInstance, videoFile: VideoFileInstance) => string
23 export type GetVideoFilename = (this: VideoInstance, videoFile: VideoFileInstance) => string
24 export type CreatePreview = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
25 export type CreateThumbnail = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
26 export type GetVideoFilePath = (this: VideoInstance, videoFile: VideoFileInstance) => string
27 export type CreateTorrentAndSetInfoHash = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
28
29 export type ToAddRemoteJSON = (this: VideoInstance) => Promise<RemoteVideoCreateData>
30 export type ToUpdateRemoteJSON = (this: VideoInstance) => RemoteVideoUpdateData
31
32 export type OptimizeOriginalVideofile = (this: VideoInstance) => Promise<void>
33 export type TranscodeOriginalVideofile = (this: VideoInstance, resolution: number) => Promise<void>
34 export type GetOriginalFileHeight = (this: VideoInstance) => Promise<number>
35
36 // Return thumbnail name
37 export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise<string>
38 export type GetDurationFromFile = (videoPath: string) => Promise<number>
39
40 export type List = () => Promise<VideoInstance[]>
41 export type ListOwnedAndPopulateAuthorAndTags = () => Promise<VideoInstance[]>
42 export type ListOwnedByAuthor = (author: string) => Promise<VideoInstance[]>
43
44 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoInstance> >
45 export type SearchAndPopulateAuthorAndPodAndTags = (
46 value: string,
47 field: string,
48 start: number,
49 count: number,
50 sort: string
51 ) => Promise< ResultList<VideoInstance> >
52
53 export type Load = (id: number) => Promise<VideoInstance>
54 export type LoadByUUID = (uuid: string) => Promise<VideoInstance>
55 export type LoadByHostAndUUID = (fromHost: string, uuid: string) => Promise<VideoInstance>
56 export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance>
57 export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance>
58 export type LoadByUUIDAndPopulateAuthorAndPodAndTags = (uuid: string) => Promise<VideoInstance>
59
60 export type RemoveThumbnail = (this: VideoInstance) => Promise<void>
61 export type RemovePreview = (this: VideoInstance) => Promise<void>
62 export type RemoveFile = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
63 export type RemoveTorrent = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
64 }
65
66 export interface VideoClass {
67 generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
68 getDurationFromFile: VideoMethods.GetDurationFromFile
69 list: VideoMethods.List
70 listForApi: VideoMethods.ListForApi
71 listOwnedAndPopulateAuthorAndTags: VideoMethods.ListOwnedAndPopulateAuthorAndTags
72 listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
73 load: VideoMethods.Load
74 loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
75 loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
76 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
77 loadByUUID: VideoMethods.LoadByUUID
78 loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
79 searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
80 }
81
82 export interface VideoAttributes {
83 id?: number
84 uuid?: string
85 name: string
86 category: number
87 licence: number
88 language: number
89 nsfw: boolean
90 description: string
91 duration: number
92 views?: number
93 likes?: number
94 dislikes?: number
95 remote: boolean
96
97 Author?: AuthorInstance
98 Tags?: TagInstance[]
99 VideoFiles?: VideoFileInstance[]
100 }
101
102 export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
103 createdAt: Date
104 updatedAt: Date
105
106 createPreview: VideoMethods.CreatePreview
107 createThumbnail: VideoMethods.CreateThumbnail
108 createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash
109 getOriginalFile: VideoMethods.GetOriginalFile
110 generateMagnetUri: VideoMethods.GenerateMagnetUri
111 getPreviewName: VideoMethods.GetPreviewName
112 getThumbnailName: VideoMethods.GetThumbnailName
113 getTorrentFileName: VideoMethods.GetTorrentFileName
114 getVideoFilename: VideoMethods.GetVideoFilename
115 getVideoFilePath: VideoMethods.GetVideoFilePath
116 isOwned: VideoMethods.IsOwned
117 removeFile: VideoMethods.RemoveFile
118 removePreview: VideoMethods.RemovePreview
119 removeThumbnail: VideoMethods.RemoveThumbnail
120 removeTorrent: VideoMethods.RemoveTorrent
121 toAddRemoteJSON: VideoMethods.ToAddRemoteJSON
122 toFormattedJSON: VideoMethods.ToFormattedJSON
123 toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON
124 optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
125 transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile
126 getOriginalFileHeight: VideoMethods.GetOriginalFileHeight
127
128 setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
129 addVideoFile: Sequelize.HasManyAddAssociationMixin<VideoFileAttributes, string>
130 setVideoFiles: Sequelize.HasManySetAssociationsMixin<VideoFileAttributes, string>
131 }
132
133 export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}