]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/video/video-interface.ts
Add ability to download a video from direct link or torrent file
[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 GetTorrentFileName = (this: VideoInstance, videoFile: VideoFileInstance) => string
22 export type GetVideoFilename = (this: VideoInstance, videoFile: VideoFileInstance) => string
23 export type CreatePreview = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
24 export type CreateThumbnail = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
25 export type GetVideoFilePath = (this: VideoInstance, videoFile: VideoFileInstance) => string
26 export type CreateTorrentAndSetInfoHash = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
27
28 export type ToAddRemoteJSON = (this: VideoInstance) => Promise<RemoteVideoCreateData>
29 export type ToUpdateRemoteJSON = (this: VideoInstance) => RemoteVideoUpdateData
30
31 export type OptimizeOriginalVideofile = (this: VideoInstance) => Promise<void>
32 export type TranscodeOriginalVideofile = (this: VideoInstance, resolution: number) => Promise<void>
33 export type GetOriginalFileHeight = (this: VideoInstance) => Promise<number>
34 export type GetEmbedPath = (this: VideoInstance) => string
35 export type GetThumbnailPath = (this: VideoInstance) => string
36 export type GetPreviewPath = (this: VideoInstance) => string
37
38 // Return thumbnail name
39 export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise<string>
40
41 export type List = () => Promise<VideoInstance[]>
42 export type ListOwnedAndPopulateAuthorAndTags = () => Promise<VideoInstance[]>
43 export type ListOwnedByAuthor = (author: string) => Promise<VideoInstance[]>
44
45 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoInstance> >
46 export type SearchAndPopulateAuthorAndPodAndTags = (
47 value: string,
48 field: string,
49 start: number,
50 count: number,
51 sort: string
52 ) => Promise< ResultList<VideoInstance> >
53
54 export type Load = (id: number) => Promise<VideoInstance>
55 export type LoadByUUID = (uuid: string) => Promise<VideoInstance>
56 export type LoadByHostAndUUID = (fromHost: string, uuid: string) => Promise<VideoInstance>
57 export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance>
58 export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance>
59 export type LoadByUUIDAndPopulateAuthorAndPodAndTags = (uuid: string) => Promise<VideoInstance>
60
61 export type RemoveThumbnail = (this: VideoInstance) => Promise<void>
62 export type RemovePreview = (this: VideoInstance) => Promise<void>
63 export type RemoveFile = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
64 export type RemoveTorrent = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
65 }
66
67 export interface VideoClass {
68 generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
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 getPreviewName: VideoMethods.GetPreviewName
111 getPreviewPath: VideoMethods.GetPreviewPath
112 getThumbnailName: VideoMethods.GetThumbnailName
113 getThumbnailPath: VideoMethods.GetThumbnailPath
114 getTorrentFileName: VideoMethods.GetTorrentFileName
115 getVideoFilename: VideoMethods.GetVideoFilename
116 getVideoFilePath: VideoMethods.GetVideoFilePath
117 isOwned: VideoMethods.IsOwned
118 removeFile: VideoMethods.RemoveFile
119 removePreview: VideoMethods.RemovePreview
120 removeThumbnail: VideoMethods.RemoveThumbnail
121 removeTorrent: VideoMethods.RemoveTorrent
122 toAddRemoteJSON: VideoMethods.ToAddRemoteJSON
123 toFormattedJSON: VideoMethods.ToFormattedJSON
124 toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON
125 optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
126 transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile
127 getOriginalFileHeight: VideoMethods.GetOriginalFileHeight
128 getEmbedPath: VideoMethods.GetEmbedPath
129
130 setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
131 addVideoFile: Sequelize.HasManyAddAssociationMixin<VideoFileAttributes, string>
132 setVideoFiles: Sequelize.HasManySetAssociationsMixin<VideoFileAttributes, string>
133 }
134
135 export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}