2021-10-27 11:42:05 +02:00
|
|
|
import { SortMeta } from 'primeng/api'
|
2022-06-21 15:31:25 +02:00
|
|
|
import { from, Observable, of } from 'rxjs'
|
2021-10-27 11:42:05 +02:00
|
|
|
import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators'
|
2021-06-05 11:05:25 +02:00
|
|
|
import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http'
|
2017-12-01 18:56:26 +01:00
|
|
|
import { Injectable } from '@angular/core'
|
2022-04-15 15:07:20 +02:00
|
|
|
import { AuthService, ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { objectToFormData } from '@app/helpers'
|
2022-07-27 13:44:40 +02:00
|
|
|
import { arrayify } from '@shared/core-utils'
|
2018-09-04 16:21:07 +02:00
|
|
|
import {
|
2021-08-19 09:24:29 +02:00
|
|
|
BooleanBothQuery,
|
2020-06-23 14:10:17 +02:00
|
|
|
FeedFormat,
|
|
|
|
NSFWPolicyType,
|
|
|
|
ResultList,
|
2018-09-04 16:21:07 +02:00
|
|
|
UserVideoRate,
|
2018-11-14 15:01:28 +01:00
|
|
|
UserVideoRateType,
|
2018-09-04 16:21:07 +02:00
|
|
|
UserVideoRateUpdate,
|
2020-06-23 14:10:17 +02:00
|
|
|
Video as VideoServerModel,
|
2021-10-20 09:05:43 +02:00
|
|
|
VideoChannel as VideoChannelServerModel,
|
2018-09-04 16:21:07 +02:00
|
|
|
VideoConstant,
|
2020-06-23 14:10:17 +02:00
|
|
|
VideoDetails as VideoDetailsServerModel,
|
2020-08-12 10:40:04 +02:00
|
|
|
VideoFileMetadata,
|
2021-10-27 14:37:04 +02:00
|
|
|
VideoInclude,
|
2018-09-04 16:21:07 +02:00
|
|
|
VideoPrivacy,
|
2020-06-23 14:10:17 +02:00
|
|
|
VideoSortField,
|
2021-11-18 14:35:08 +01:00
|
|
|
VideoTranscodingCreate,
|
2020-11-09 16:25:27 +01:00
|
|
|
VideoUpdate
|
2020-06-23 14:10:17 +02:00
|
|
|
} from '@shared/models'
|
2022-06-21 15:31:25 +02:00
|
|
|
import { VideoSource } from '@shared/models/videos/video-source'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { environment } from '../../../../environments/environment'
|
2020-08-14 17:28:54 +02:00
|
|
|
import { Account } from '../account/account.model'
|
|
|
|
import { AccountService } from '../account/account.service'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { VideoChannel, VideoChannelService } from '../video-channel'
|
2017-10-25 16:43:19 +02:00
|
|
|
import { VideoDetails } from './video-details.model'
|
|
|
|
import { VideoEdit } from './video-edit.model'
|
2017-12-01 18:56:26 +01:00
|
|
|
import { Video } from './video.model'
|
2016-03-14 13:50:19 +01:00
|
|
|
|
2021-08-19 09:24:29 +02:00
|
|
|
export type CommonVideoParams = {
|
2021-10-27 11:42:05 +02:00
|
|
|
videoPagination?: ComponentPaginationLight
|
|
|
|
sort: VideoSortField | SortMeta
|
2021-10-27 14:37:04 +02:00
|
|
|
include?: VideoInclude
|
|
|
|
isLocal?: boolean
|
2021-08-19 09:24:29 +02:00
|
|
|
categoryOneOf?: number[]
|
|
|
|
languageOneOf?: string[]
|
2021-11-12 14:19:56 +01:00
|
|
|
privacyOneOf?: VideoPrivacy[]
|
2021-08-19 09:24:29 +02:00
|
|
|
isLive?: boolean
|
|
|
|
skipCount?: boolean
|
2021-10-27 14:37:04 +02:00
|
|
|
|
2021-08-19 09:24:29 +02:00
|
|
|
// FIXME: remove?
|
|
|
|
nsfwPolicy?: NSFWPolicyType
|
|
|
|
nsfw?: BooleanBothQuery
|
2018-08-31 17:19:21 +02:00
|
|
|
}
|
|
|
|
|
2016-03-14 13:50:19 +01:00
|
|
|
@Injectable()
|
2021-08-19 09:24:29 +02:00
|
|
|
export class VideoService {
|
2021-11-02 11:00:40 +01:00
|
|
|
static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos'
|
2018-07-12 19:02:00 +02:00
|
|
|
static BASE_FEEDS_URL = environment.apiUrl + '/feeds/videos.'
|
2020-11-09 16:25:27 +01:00
|
|
|
static BASE_SUBSCRIPTION_FEEDS_URL = environment.apiUrl + '/feeds/subscriptions.'
|
2016-03-14 13:50:19 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
constructor (
|
2022-04-15 15:07:20 +02:00
|
|
|
private auth: AuthService,
|
2017-09-14 11:57:49 +02:00
|
|
|
private authHttp: HttpClient,
|
2016-08-23 16:54:21 +02:00
|
|
|
private restExtractor: RestExtractor,
|
2018-06-06 16:46:42 +02:00
|
|
|
private restService: RestService,
|
2020-11-09 16:25:27 +01:00
|
|
|
private serverService: ServerService
|
2016-05-27 17:49:18 +02:00
|
|
|
) {}
|
|
|
|
|
2018-02-14 17:16:32 +01:00
|
|
|
getVideoViewUrl (uuid: string) {
|
2021-11-02 11:50:03 +01:00
|
|
|
return `${VideoService.BASE_VIDEO_URL}/${uuid}/views`
|
2018-02-14 17:16:32 +01:00
|
|
|
}
|
|
|
|
|
2019-07-22 15:40:13 +02:00
|
|
|
getVideo (options: { videoId: string }): Observable<VideoDetails> {
|
2019-12-18 15:31:54 +01:00
|
|
|
return this.serverService.getServerLocale()
|
2018-05-15 11:55:51 +02:00
|
|
|
.pipe(
|
2018-06-06 16:46:42 +02:00
|
|
|
switchMap(translations => {
|
2021-11-02 11:50:03 +01:00
|
|
|
return this.authHttp.get<VideoDetailsServerModel>(`${VideoService.BASE_VIDEO_URL}/${options.videoId}`)
|
2018-06-06 17:37:13 +02:00
|
|
|
.pipe(map(videoHash => ({ videoHash, translations })))
|
2018-06-06 16:46:42 +02:00
|
|
|
}),
|
|
|
|
map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)),
|
2018-07-09 15:56:02 +02:00
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
2018-05-15 11:55:51 +02:00
|
|
|
)
|
2016-05-27 17:49:18 +02:00
|
|
|
}
|
2016-03-14 13:50:19 +01:00
|
|
|
|
2017-10-25 16:43:19 +02:00
|
|
|
updateVideo (video: VideoEdit) {
|
2018-05-09 11:23:14 +02:00
|
|
|
const language = video.language || null
|
|
|
|
const licence = video.licence || null
|
|
|
|
const category = video.category || null
|
|
|
|
const description = video.description || null
|
|
|
|
const support = video.support || null
|
2018-06-18 10:24:53 +02:00
|
|
|
const scheduleUpdate = video.scheduleUpdate || null
|
2019-01-12 14:45:23 +01:00
|
|
|
const originallyPublishedAt = video.originallyPublishedAt || null
|
2017-05-05 14:29:58 +02:00
|
|
|
|
2017-07-10 19:43:21 +02:00
|
|
|
const body: VideoUpdate = {
|
2017-04-10 21:15:28 +02:00
|
|
|
name: video.name,
|
2017-12-08 08:39:15 +01:00
|
|
|
category,
|
|
|
|
licence,
|
2017-05-05 14:29:58 +02:00
|
|
|
language,
|
2018-02-21 08:49:05 +01:00
|
|
|
support,
|
2017-12-08 08:39:15 +01:00
|
|
|
description,
|
2018-05-11 15:10:13 +02:00
|
|
|
channelId: video.channelId,
|
2017-10-31 11:52:52 +01:00
|
|
|
privacy: video.privacy,
|
2017-07-10 19:43:21 +02:00
|
|
|
tags: video.tags,
|
2018-01-03 10:12:36 +01:00
|
|
|
nsfw: video.nsfw,
|
2018-06-12 20:04:58 +02:00
|
|
|
waitTranscoding: video.waitTranscoding,
|
2018-02-16 16:35:32 +01:00
|
|
|
commentsEnabled: video.commentsEnabled,
|
2018-10-08 14:45:22 +02:00
|
|
|
downloadEnabled: video.downloadEnabled,
|
2018-02-16 16:35:32 +01:00
|
|
|
thumbnailfile: video.thumbnailfile,
|
2018-06-15 16:52:15 +02:00
|
|
|
previewfile: video.previewfile,
|
2020-08-20 16:18:16 +02:00
|
|
|
pluginData: video.pluginData,
|
2019-01-12 14:45:23 +01:00
|
|
|
scheduleUpdate,
|
|
|
|
originallyPublishedAt
|
2017-06-16 14:32:15 +02:00
|
|
|
}
|
2017-05-05 14:29:58 +02:00
|
|
|
|
2018-02-16 16:35:32 +01:00
|
|
|
const data = objectToFormData(body)
|
|
|
|
|
2021-11-02 11:50:03 +01:00
|
|
|
return this.authHttp.put(`${VideoService.BASE_VIDEO_URL}/${video.id}`, data)
|
2022-01-18 11:37:29 +01:00
|
|
|
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
2017-04-10 21:15:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-09 19:12:40 +02:00
|
|
|
uploadVideo (video: FormData) {
|
2021-11-02 11:50:03 +01:00
|
|
|
const req = new HttpRequest('POST', `${VideoService.BASE_VIDEO_URL}/upload`, video, { reportProgress: true })
|
2017-09-14 17:06:31 +02:00
|
|
|
|
2017-10-31 11:52:52 +01:00
|
|
|
return this.authHttp
|
2018-06-12 20:04:58 +02:00
|
|
|
.request<{ video: { id: number, uuid: string } }>(req)
|
2018-07-09 15:56:02 +02:00
|
|
|
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
2017-09-14 17:06:31 +02:00
|
|
|
}
|
|
|
|
|
2021-10-20 09:05:43 +02:00
|
|
|
getMyVideos (options: {
|
|
|
|
videoPagination: ComponentPaginationLight
|
|
|
|
sort: VideoSortField
|
|
|
|
userChannels?: VideoChannelServerModel[]
|
|
|
|
search?: string
|
|
|
|
}): Observable<ResultList<Video>> {
|
|
|
|
const { videoPagination, sort, userChannels = [], search } = options
|
|
|
|
|
2021-10-19 09:44:43 +02:00
|
|
|
const pagination = this.restService.componentToRestPagination(videoPagination)
|
2016-05-23 11:07:42 +02:00
|
|
|
|
2017-09-14 11:57:49 +02:00
|
|
|
let params = new HttpParams()
|
|
|
|
params = this.restService.addRestGetParams(params, pagination, sort)
|
2021-05-03 11:06:19 +02:00
|
|
|
|
|
|
|
if (search) {
|
|
|
|
const filters = this.restService.parseQueryStringFilter(search, {
|
|
|
|
isLive: {
|
|
|
|
prefix: 'isLive:',
|
2021-05-03 15:53:07 +02:00
|
|
|
isBoolean: true
|
2021-10-20 09:05:43 +02:00
|
|
|
},
|
|
|
|
channelId: {
|
|
|
|
prefix: 'channel:',
|
|
|
|
handler: (name: string) => {
|
|
|
|
const channel = userChannels.find(c => c.name === name)
|
|
|
|
|
|
|
|
if (channel) return channel.id
|
|
|
|
|
|
|
|
return undefined
|
|
|
|
}
|
2021-05-03 11:06:19 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
params = this.restService.addObjectParams(params, filters)
|
|
|
|
}
|
2016-03-14 13:50:19 +01:00
|
|
|
|
2018-06-06 16:46:42 +02:00
|
|
|
return this.authHttp
|
2019-12-28 01:10:26 +01:00
|
|
|
.get<ResultList<Video>>(UserService.BASE_USERS_URL + 'me/videos', { params })
|
2018-05-15 11:55:51 +02:00
|
|
|
.pipe(
|
2018-06-06 16:46:42 +02:00
|
|
|
switchMap(res => this.extractVideos(res)),
|
2018-07-09 15:56:02 +02:00
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
2018-05-15 11:55:51 +02:00
|
|
|
)
|
2016-03-14 13:50:19 +01:00
|
|
|
}
|
|
|
|
|
2021-08-19 09:24:29 +02:00
|
|
|
getAccountVideos (parameters: CommonVideoParams & {
|
2021-08-17 14:42:53 +02:00
|
|
|
account: Pick<Account, 'nameWithHost'>
|
2021-01-19 13:43:33 +01:00
|
|
|
search?: string
|
2020-11-18 15:29:38 +01:00
|
|
|
}): Observable<ResultList<Video>> {
|
2021-08-19 09:24:29 +02:00
|
|
|
const { account, search } = parameters
|
2018-04-24 15:10:54 +02:00
|
|
|
|
|
|
|
let params = new HttpParams()
|
2021-08-19 09:24:29 +02:00
|
|
|
params = this.buildCommonVideosParams({ params, ...parameters })
|
2020-11-18 15:29:38 +01:00
|
|
|
|
2021-08-19 09:24:29 +02:00
|
|
|
if (search) params = params.set('search', search)
|
2021-01-19 13:43:33 +01:00
|
|
|
|
2018-04-24 15:10:54 +02:00
|
|
|
return this.authHttp
|
2018-06-06 16:46:42 +02:00
|
|
|
.get<ResultList<Video>>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params })
|
2018-05-15 11:55:51 +02:00
|
|
|
.pipe(
|
2018-06-06 16:46:42 +02:00
|
|
|
switchMap(res => this.extractVideos(res)),
|
2018-07-09 15:56:02 +02:00
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
2018-05-15 11:55:51 +02:00
|
|
|
)
|
2018-04-24 15:10:54 +02:00
|
|
|
}
|
|
|
|
|
2021-08-19 09:24:29 +02:00
|
|
|
getVideoChannelVideos (parameters: CommonVideoParams & {
|
2021-08-17 14:42:53 +02:00
|
|
|
videoChannel: Pick<VideoChannel, 'nameWithHost'>
|
2020-11-18 15:29:38 +01:00
|
|
|
}): Observable<ResultList<Video>> {
|
2021-08-19 09:24:29 +02:00
|
|
|
const { videoChannel } = parameters
|
2018-04-25 16:56:13 +02:00
|
|
|
|
|
|
|
let params = new HttpParams()
|
2021-08-19 09:24:29 +02:00
|
|
|
params = this.buildCommonVideosParams({ params, ...parameters })
|
2020-11-18 15:29:38 +01:00
|
|
|
|
2018-04-25 16:56:13 +02:00
|
|
|
return this.authHttp
|
2018-08-24 11:04:02 +02:00
|
|
|
.get<ResultList<Video>>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost + '/videos', { params })
|
2018-05-15 11:55:51 +02:00
|
|
|
.pipe(
|
2018-06-06 16:46:42 +02:00
|
|
|
switchMap(res => this.extractVideos(res)),
|
2018-08-21 16:18:59 +02:00
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-08-19 09:24:29 +02:00
|
|
|
getVideos (parameters: CommonVideoParams): Observable<ResultList<Video>> {
|
2017-10-31 11:52:52 +01:00
|
|
|
let params = new HttpParams()
|
2021-08-19 09:24:29 +02:00
|
|
|
params = this.buildCommonVideosParams({ params, ...parameters })
|
2020-06-16 11:00:35 +02:00
|
|
|
|
2017-10-31 11:52:52 +01:00
|
|
|
return this.authHttp
|
2018-06-06 16:46:42 +02:00
|
|
|
.get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
|
2018-05-15 11:55:51 +02:00
|
|
|
.pipe(
|
2018-06-06 16:46:42 +02:00
|
|
|
switchMap(res => this.extractVideos(res)),
|
2018-07-09 15:56:02 +02:00
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
2018-05-15 11:55:51 +02:00
|
|
|
)
|
2017-10-31 11:52:52 +01:00
|
|
|
}
|
|
|
|
|
2020-11-09 16:25:27 +01:00
|
|
|
buildBaseFeedUrls (params: HttpParams, base = VideoService.BASE_FEEDS_URL) {
|
2018-04-17 10:35:08 +02:00
|
|
|
const feeds = [
|
|
|
|
{
|
2018-09-26 09:39:41 +02:00
|
|
|
format: FeedFormat.RSS,
|
2020-07-02 16:25:16 +02:00
|
|
|
label: 'media rss 2.0',
|
2020-11-09 16:25:27 +01:00
|
|
|
url: base + FeedFormat.RSS.toLowerCase()
|
2018-04-17 10:35:08 +02:00
|
|
|
},
|
|
|
|
{
|
2018-09-26 09:39:41 +02:00
|
|
|
format: FeedFormat.ATOM,
|
2018-04-17 10:35:08 +02:00
|
|
|
label: 'atom 1.0',
|
2020-11-09 16:25:27 +01:00
|
|
|
url: base + FeedFormat.ATOM.toLowerCase()
|
2018-04-17 10:35:08 +02:00
|
|
|
},
|
|
|
|
{
|
2018-09-26 09:39:41 +02:00
|
|
|
format: FeedFormat.JSON,
|
2018-04-17 10:35:08 +02:00
|
|
|
label: 'json 1.0',
|
2020-11-09 16:25:27 +01:00
|
|
|
url: base + FeedFormat.JSON.toLowerCase()
|
2018-04-17 10:35:08 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-04-17 10:56:27 +02:00
|
|
|
if (params && params.keys().length !== 0) {
|
|
|
|
for (const feed of feeds) {
|
|
|
|
feed.url += '?' + params.toString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 10:35:08 +02:00
|
|
|
return feeds
|
2018-04-17 00:49:04 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 14:37:04 +02:00
|
|
|
getVideoFeedUrls (sort: VideoSortField, isLocal: boolean, categoryOneOf?: number[]) {
|
2018-04-17 10:56:27 +02:00
|
|
|
let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort)
|
2018-04-17 00:49:04 +02:00
|
|
|
|
2021-10-27 14:37:04 +02:00
|
|
|
if (isLocal) params = params.set('isLocal', isLocal)
|
2018-04-17 10:35:08 +02:00
|
|
|
|
2020-06-16 11:00:35 +02:00
|
|
|
if (categoryOneOf) {
|
|
|
|
for (const c of categoryOneOf) {
|
|
|
|
params = params.append('categoryOneOf[]', c + '')
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 14:24:49 +02:00
|
|
|
|
2018-04-17 10:56:27 +02:00
|
|
|
return this.buildBaseFeedUrls(params)
|
2018-04-17 00:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 10:35:08 +02:00
|
|
|
getAccountFeedUrls (accountId: number) {
|
2018-04-17 00:49:04 +02:00
|
|
|
let params = this.restService.addRestGetParams(new HttpParams())
|
|
|
|
params = params.set('accountId', accountId.toString())
|
2018-04-17 10:35:08 +02:00
|
|
|
|
2018-04-17 10:56:27 +02:00
|
|
|
return this.buildBaseFeedUrls(params)
|
2018-04-17 00:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 16:56:13 +02:00
|
|
|
getVideoChannelFeedUrls (videoChannelId: number) {
|
|
|
|
let params = this.restService.addRestGetParams(new HttpParams())
|
|
|
|
params = params.set('videoChannelId', videoChannelId.toString())
|
|
|
|
|
|
|
|
return this.buildBaseFeedUrls(params)
|
|
|
|
}
|
|
|
|
|
2020-11-09 16:25:27 +01:00
|
|
|
getVideoSubscriptionFeedUrls (accountId: number, feedToken: string) {
|
2020-08-13 15:07:23 +02:00
|
|
|
let params = this.restService.addRestGetParams(new HttpParams())
|
|
|
|
params = params.set('accountId', accountId.toString())
|
|
|
|
params = params.set('token', feedToken)
|
|
|
|
|
2020-11-09 16:25:27 +01:00
|
|
|
return this.buildBaseFeedUrls(params, VideoService.BASE_SUBSCRIPTION_FEEDS_URL)
|
2020-08-13 15:07:23 +02:00
|
|
|
}
|
|
|
|
|
2020-03-10 14:39:40 +01:00
|
|
|
getVideoFileMetadata (metadataUrl: string) {
|
|
|
|
return this.authHttp
|
2020-06-26 08:37:26 +02:00
|
|
|
.get<VideoFileMetadata>(metadataUrl)
|
2020-03-10 14:39:40 +01:00
|
|
|
.pipe(
|
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-27 11:42:05 +02:00
|
|
|
removeVideo (idArg: number | number[]) {
|
2022-07-27 13:44:40 +02:00
|
|
|
const ids = arrayify(idArg)
|
2021-10-27 11:42:05 +02:00
|
|
|
|
|
|
|
return from(ids)
|
|
|
|
.pipe(
|
2021-11-02 11:50:03 +01:00
|
|
|
concatMap(id => this.authHttp.delete(`${VideoService.BASE_VIDEO_URL}/${id}`)),
|
2021-10-27 11:42:05 +02:00
|
|
|
toArray(),
|
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
|
|
|
)
|
2016-05-27 17:49:18 +02:00
|
|
|
}
|
|
|
|
|
2021-11-17 16:04:53 +01:00
|
|
|
removeVideoFiles (videoIds: (number | string)[], type: 'hls' | 'webtorrent') {
|
|
|
|
return from(videoIds)
|
|
|
|
.pipe(
|
|
|
|
concatMap(id => this.authHttp.delete(VideoService.BASE_VIDEO_URL + '/' + id + '/' + type)),
|
|
|
|
toArray(),
|
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
removeFile (videoId: number | string, fileId: number, type: 'hls' | 'webtorrent') {
|
|
|
|
return this.authHttp.delete(VideoService.BASE_VIDEO_URL + '/' + videoId + '/' + type + '/' + fileId)
|
|
|
|
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
|
|
|
}
|
|
|
|
|
2021-11-18 14:35:08 +01:00
|
|
|
runTranscoding (videoIds: (number | string)[], type: 'hls' | 'webtorrent') {
|
|
|
|
const body: VideoTranscodingCreate = { transcodingType: type }
|
|
|
|
|
|
|
|
return from(videoIds)
|
|
|
|
.pipe(
|
|
|
|
concatMap(id => this.authHttp.post(VideoService.BASE_VIDEO_URL + '/' + id + '/transcoding', body)),
|
|
|
|
toArray(),
|
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:26:06 +01:00
|
|
|
loadCompleteDescription (descriptionPath: string) {
|
|
|
|
return this.authHttp
|
2018-10-18 14:35:31 +02:00
|
|
|
.get<{ description: string }>(environment.apiUrl + descriptionPath)
|
2018-05-15 11:55:51 +02:00
|
|
|
.pipe(
|
2018-10-18 14:35:31 +02:00
|
|
|
map(res => res.description),
|
2018-07-09 15:56:02 +02:00
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
2018-05-15 11:55:51 +02:00
|
|
|
)
|
2017-03-08 21:35:43 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 15:31:25 +02:00
|
|
|
getSource (videoId: number) {
|
|
|
|
return this.authHttp
|
|
|
|
.get<{ source: VideoSource }>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/source')
|
|
|
|
.pipe(
|
|
|
|
catchError(err => {
|
|
|
|
if (err.status === 404) {
|
|
|
|
return of(undefined)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.restExtractor.handleError(err)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-24 14:47:32 +02:00
|
|
|
setVideoLike (id: string) {
|
2017-06-16 14:32:15 +02:00
|
|
|
return this.setVideoRate(id, 'like')
|
2017-03-08 21:35:43 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 14:47:32 +02:00
|
|
|
setVideoDislike (id: string) {
|
2017-06-16 14:32:15 +02:00
|
|
|
return this.setVideoRate(id, 'dislike')
|
2017-03-08 21:35:43 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 14:47:32 +02:00
|
|
|
unsetVideoLike (id: string) {
|
2018-01-07 14:48:10 +01:00
|
|
|
return this.setVideoRate(id, 'none')
|
|
|
|
}
|
|
|
|
|
2022-06-24 14:47:32 +02:00
|
|
|
getUserVideoRating (id: string) {
|
2017-10-13 08:14:40 +02:00
|
|
|
const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating'
|
2017-03-08 21:35:43 +01:00
|
|
|
|
2018-05-16 11:00:57 +02:00
|
|
|
return this.authHttp.get<UserVideoRate>(url)
|
2018-07-09 15:56:02 +02:00
|
|
|
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
2017-03-08 21:35:43 +01:00
|
|
|
}
|
|
|
|
|
2018-07-19 16:17:54 +02:00
|
|
|
extractVideos (result: ResultList<VideoServerModel>) {
|
2019-12-18 15:31:54 +01:00
|
|
|
return this.serverService.getServerLocale()
|
2018-06-12 20:04:58 +02:00
|
|
|
.pipe(
|
|
|
|
map(translations => {
|
|
|
|
const videosJson = result.data
|
|
|
|
const totalVideos = result.total
|
|
|
|
const videos: Video[] = []
|
|
|
|
|
|
|
|
for (const videoJson of videosJson) {
|
|
|
|
videos.push(new Video(videoJson, translations))
|
|
|
|
}
|
|
|
|
|
2019-07-22 15:40:13 +02:00
|
|
|
return { total: totalVideos, data: videos }
|
2018-06-12 20:04:58 +02:00
|
|
|
})
|
|
|
|
)
|
2016-05-21 18:03:34 +02:00
|
|
|
}
|
2018-07-19 16:17:54 +02:00
|
|
|
|
2021-07-12 14:48:57 +02:00
|
|
|
explainedPrivacyLabels (serverPrivacies: VideoConstant<VideoPrivacy>[], defaultPrivacyId = VideoPrivacy.PUBLIC) {
|
2021-07-26 14:03:21 +02:00
|
|
|
const descriptions = {
|
|
|
|
[VideoPrivacy.PRIVATE]: $localize`Only I can see this video`,
|
|
|
|
[VideoPrivacy.UNLISTED]: $localize`Only shareable via a private link`,
|
|
|
|
[VideoPrivacy.PUBLIC]: $localize`Anyone can see this video`,
|
|
|
|
[VideoPrivacy.INTERNAL]: $localize`Only users of this instance can see this video`
|
|
|
|
}
|
|
|
|
|
|
|
|
const videoPrivacies = serverPrivacies.map(p => {
|
|
|
|
return {
|
|
|
|
...p,
|
|
|
|
|
|
|
|
description: descriptions[p.id]
|
2019-12-12 15:47:47 +01:00
|
|
|
}
|
2021-07-26 14:03:21 +02:00
|
|
|
})
|
2018-09-04 16:21:07 +02:00
|
|
|
|
2021-06-05 11:05:25 +02:00
|
|
|
return {
|
2021-07-26 14:03:21 +02:00
|
|
|
videoPrivacies,
|
|
|
|
defaultPrivacyId: serverPrivacies.find(p => p.id === defaultPrivacyId)?.id || serverPrivacies[0].id
|
2021-06-05 11:05:25 +02:00
|
|
|
}
|
2018-09-04 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:46:51 +02:00
|
|
|
getHighestAvailablePrivacy (serverPrivacies: VideoConstant<VideoPrivacy>[]) {
|
|
|
|
const order = [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL, VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC ]
|
|
|
|
|
|
|
|
for (const privacy of order) {
|
|
|
|
if (serverPrivacies.find(p => p.id === privacy)) {
|
|
|
|
return privacy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('No highest privacy available')
|
|
|
|
}
|
|
|
|
|
2020-06-16 11:00:35 +02:00
|
|
|
nsfwPolicyToParam (nsfwPolicy: NSFWPolicyType) {
|
|
|
|
return nsfwPolicy === 'do_not_list'
|
|
|
|
? 'false'
|
|
|
|
: 'both'
|
|
|
|
}
|
|
|
|
|
2023-02-15 13:50:40 +01:00
|
|
|
// Choose if we display by default the account or the channel
|
|
|
|
buildDefaultOwnerDisplayType (video: Video) {
|
|
|
|
const accountName = video.account.name
|
|
|
|
|
|
|
|
// If the video channel name is an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
|
|
|
|
// Or has not been customized (default created channel display name)
|
|
|
|
// -> Use the account name
|
|
|
|
if (
|
|
|
|
video.channel.displayName === `Default ${accountName} channel` ||
|
|
|
|
video.channel.displayName === `Main ${accountName} channel` ||
|
|
|
|
video.channel.name.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
|
|
|
|
) {
|
|
|
|
return 'account' as 'account'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'videoChannel' as 'videoChannel'
|
|
|
|
}
|
|
|
|
|
2021-11-02 14:14:26 +01:00
|
|
|
buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) {
|
2021-10-27 11:42:05 +02:00
|
|
|
const {
|
|
|
|
params,
|
|
|
|
videoPagination,
|
|
|
|
sort,
|
2021-10-27 14:37:04 +02:00
|
|
|
isLocal,
|
|
|
|
include,
|
2021-10-27 11:42:05 +02:00
|
|
|
categoryOneOf,
|
|
|
|
languageOneOf,
|
2021-11-12 14:19:56 +01:00
|
|
|
privacyOneOf,
|
2021-10-27 11:42:05 +02:00
|
|
|
skipCount,
|
|
|
|
nsfwPolicy,
|
|
|
|
isLive,
|
|
|
|
nsfw
|
|
|
|
} = options
|
|
|
|
|
|
|
|
const pagination = videoPagination
|
|
|
|
? this.restService.componentToRestPagination(videoPagination)
|
|
|
|
: undefined
|
2021-08-19 09:24:29 +02:00
|
|
|
|
2022-04-15 15:07:20 +02:00
|
|
|
let newParams = this.restService.addRestGetParams(params, pagination, this.buildListSort(sort))
|
2021-08-19 09:24:29 +02:00
|
|
|
|
|
|
|
if (skipCount) newParams = newParams.set('skipCount', skipCount + '')
|
|
|
|
|
2022-06-27 13:51:46 +02:00
|
|
|
if (isLocal !== undefined) newParams = newParams.set('isLocal', isLocal)
|
|
|
|
if (include !== undefined) newParams = newParams.set('include', include)
|
|
|
|
if (isLive !== undefined) newParams = newParams.set('isLive', isLive)
|
|
|
|
if (nsfw !== undefined) newParams = newParams.set('nsfw', nsfw)
|
|
|
|
if (nsfwPolicy !== undefined) newParams = newParams.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy))
|
|
|
|
if (languageOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'languageOneOf', languageOneOf)
|
|
|
|
if (categoryOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'categoryOneOf', categoryOneOf)
|
|
|
|
if (privacyOneOf !== undefined) newParams = this.restService.addArrayParams(newParams, 'privacyOneOf', privacyOneOf)
|
2021-08-19 09:24:29 +02:00
|
|
|
|
|
|
|
return newParams
|
|
|
|
}
|
2021-10-27 11:42:05 +02:00
|
|
|
|
2022-04-15 15:07:20 +02:00
|
|
|
private buildListSort (sortArg: VideoSortField | SortMeta) {
|
|
|
|
const sort = this.restService.buildSortString(sortArg)
|
|
|
|
|
|
|
|
if (typeof sort === 'string') {
|
|
|
|
// Silently use the best algorithm for logged in users if they chose the hot algorithm
|
|
|
|
if (
|
|
|
|
this.auth.isLoggedIn() &&
|
|
|
|
(sort === 'hot' || sort === '-hot')
|
|
|
|
) {
|
|
|
|
return sort.replace('hot', 'best')
|
|
|
|
}
|
|
|
|
|
|
|
|
return sort
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 14:47:32 +02:00
|
|
|
private setVideoRate (id: string, rateType: UserVideoRateType) {
|
2021-11-02 14:14:26 +01:00
|
|
|
const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate`
|
|
|
|
const body: UserVideoRateUpdate = {
|
|
|
|
rating: rateType
|
2021-11-02 11:50:03 +01:00
|
|
|
}
|
|
|
|
|
2021-11-02 14:14:26 +01:00
|
|
|
return this.authHttp
|
|
|
|
.put(url, body)
|
2022-01-18 11:37:29 +01:00
|
|
|
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
2021-10-27 11:42:05 +02:00
|
|
|
}
|
2016-03-14 13:50:19 +01:00
|
|
|
}
|