diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 80 |
1 files changed, 45 insertions, 35 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 14eb64102..a4d4c42f0 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -802,6 +802,27 @@ export class VideoModel extends Model<VideoModel> { | |||
802 | return {} | 802 | return {} |
803 | } | 803 | } |
804 | 804 | ||
805 | private static getCategoryLabel (id: number) { | ||
806 | let categoryLabel = VIDEO_CATEGORIES[id] | ||
807 | if (!categoryLabel) categoryLabel = 'Misc' | ||
808 | |||
809 | return categoryLabel | ||
810 | } | ||
811 | |||
812 | private static getLicenceLabel (id: number) { | ||
813 | let licenceLabel = VIDEO_LICENCES[id] | ||
814 | if (!licenceLabel) licenceLabel = 'Unknown' | ||
815 | |||
816 | return licenceLabel | ||
817 | } | ||
818 | |||
819 | private static getLanguageLabel (id: number) { | ||
820 | let languageLabel = VIDEO_LANGUAGES[id] | ||
821 | if (!languageLabel) languageLabel = 'Unknown' | ||
822 | |||
823 | return languageLabel | ||
824 | } | ||
825 | |||
805 | getOriginalFile () { | 826 | getOriginalFile () { |
806 | if (Array.isArray(this.VideoFiles) === false) return undefined | 827 | if (Array.isArray(this.VideoFiles) === false) return undefined |
807 | 828 | ||
@@ -896,12 +917,18 @@ export class VideoModel extends Model<VideoModel> { | |||
896 | id: this.id, | 917 | id: this.id, |
897 | uuid: this.uuid, | 918 | uuid: this.uuid, |
898 | name: this.name, | 919 | name: this.name, |
899 | category: this.category, | 920 | category: { |
900 | categoryLabel: this.getCategoryLabel(), | 921 | id: this.category, |
901 | licence: this.licence, | 922 | label: VideoModel.getCategoryLabel(this.category) |
902 | licenceLabel: this.getLicenceLabel(), | 923 | }, |
903 | language: this.language, | 924 | licence: { |
904 | languageLabel: this.getLanguageLabel(), | 925 | id: this.licence, |
926 | label: VideoModel.getLicenceLabel(this.licence) | ||
927 | }, | ||
928 | language: { | ||
929 | id: this.language, | ||
930 | label: VideoModel.getLanguageLabel(this.language) | ||
931 | }, | ||
905 | nsfw: this.nsfw, | 932 | nsfw: this.nsfw, |
906 | description: this.getTruncatedDescription(), | 933 | description: this.getTruncatedDescription(), |
907 | isLocal: this.isOwned(), | 934 | isLocal: this.isOwned(), |
@@ -932,8 +959,10 @@ export class VideoModel extends Model<VideoModel> { | |||
932 | if (!privacyLabel) privacyLabel = 'Unknown' | 959 | if (!privacyLabel) privacyLabel = 'Unknown' |
933 | 960 | ||
934 | const detailsJson = { | 961 | const detailsJson = { |
935 | privacyLabel, | 962 | privacy: { |
936 | privacy: this.privacy, | 963 | id: this.privacy, |
964 | label: privacyLabel | ||
965 | }, | ||
937 | support: this.support, | 966 | support: this.support, |
938 | descriptionPath: this.getDescriptionPath(), | 967 | descriptionPath: this.getDescriptionPath(), |
939 | channel: this.VideoChannel.toFormattedJSON(), | 968 | channel: this.VideoChannel.toFormattedJSON(), |
@@ -950,8 +979,10 @@ export class VideoModel extends Model<VideoModel> { | |||
950 | let resolutionLabel = videoFile.resolution + 'p' | 979 | let resolutionLabel = videoFile.resolution + 'p' |
951 | 980 | ||
952 | return { | 981 | return { |
953 | resolution: videoFile.resolution, | 982 | resolution: { |
954 | resolutionLabel, | 983 | id: videoFile.resolution, |
984 | label: resolutionLabel | ||
985 | }, | ||
955 | magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs), | 986 | magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs), |
956 | size: videoFile.size, | 987 | size: videoFile.size, |
957 | torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp), | 988 | torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp), |
@@ -979,8 +1010,8 @@ export class VideoModel extends Model<VideoModel> { | |||
979 | let language | 1010 | let language |
980 | if (this.language) { | 1011 | if (this.language) { |
981 | language = { | 1012 | language = { |
982 | identifier: this.language + '', | 1013 | id: this.language + '', |
983 | name: this.getLanguageLabel() | 1014 | name: VideoModel.getLanguageLabel(this.language) |
984 | } | 1015 | } |
985 | } | 1016 | } |
986 | 1017 | ||
@@ -988,7 +1019,7 @@ export class VideoModel extends Model<VideoModel> { | |||
988 | if (this.category) { | 1019 | if (this.category) { |
989 | category = { | 1020 | category = { |
990 | identifier: this.category + '', | 1021 | identifier: this.category + '', |
991 | name: this.getCategoryLabel() | 1022 | name: VideoModel.getCategoryLabel(this.category) |
992 | } | 1023 | } |
993 | } | 1024 | } |
994 | 1025 | ||
@@ -996,7 +1027,7 @@ export class VideoModel extends Model<VideoModel> { | |||
996 | if (this.licence) { | 1027 | if (this.licence) { |
997 | licence = { | 1028 | licence = { |
998 | identifier: this.licence + '', | 1029 | identifier: this.licence + '', |
999 | name: this.getLicenceLabel() | 1030 | name: VideoModel.getLicenceLabel(this.licence) |
1000 | } | 1031 | } |
1001 | } | 1032 | } |
1002 | 1033 | ||
@@ -1224,27 +1255,6 @@ export class VideoModel extends Model<VideoModel> { | |||
1224 | return `/api/${API_VERSION}/videos/${this.uuid}/description` | 1255 | return `/api/${API_VERSION}/videos/${this.uuid}/description` |
1225 | } | 1256 | } |
1226 | 1257 | ||
1227 | getCategoryLabel () { | ||
1228 | let categoryLabel = VIDEO_CATEGORIES[this.category] | ||
1229 | if (!categoryLabel) categoryLabel = 'Misc' | ||
1230 | |||
1231 | return categoryLabel | ||
1232 | } | ||
1233 | |||
1234 | getLicenceLabel () { | ||
1235 | let licenceLabel = VIDEO_LICENCES[this.licence] | ||
1236 | if (!licenceLabel) licenceLabel = 'Unknown' | ||
1237 | |||
1238 | return licenceLabel | ||
1239 | } | ||
1240 | |||
1241 | getLanguageLabel () { | ||
1242 | let languageLabel = VIDEO_LANGUAGES[this.language] | ||
1243 | if (!languageLabel) languageLabel = 'Unknown' | ||
1244 | |||
1245 | return languageLabel | ||
1246 | } | ||
1247 | |||
1248 | removeThumbnail () { | 1258 | removeThumbnail () { |
1249 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) | 1259 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) |
1250 | return unlinkPromise(thumbnailPath) | 1260 | return unlinkPromise(thumbnailPath) |