Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add tag filters in my videos

Chocobozzz05f2889381dd
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.html b/client/src/app/+my-library/my-videos/my-videos.component.html
index c0244f3369..4bdae07712 100644
--- a/client/src/app/+my-library/my-videos/my-videos.component.html
+++ b/client/src/app/+my-library/my-videos/my-videos.component.html
@@ -41,10 +41,25 @@
</td>
}
+ @if (table.isColumnDisplayed('tags')) {
+ <td>
+ <div class="badges tags">
+ @for (tag of video.tags; track tag) {
+ <a class="pt-badge badge-secondary pt-badge-keep-case" routerLink="." [queryParams]="{ tagsOneOf: tag }">
+ {{ tag }}
+ </a>
+ }
+ </div>
+ </td>
+ }
+
@if (table.isColumnDisplayed('privacy')) {
<td>
<div class="pt-badges-container">
- <my-privacy-badge [video]="video"></my-privacy-badge>
+ <a routerLink="." [queryParams]="{ privacyOneOf: video.privacy.id }" [title]="getPrivacyFilterTitle(video.privacy.label)">
+ <my-privacy-badge displayTooltip="false" [video]="video"></my-privacy-badge>
+ </a>
+
@if (video.blacklisted) {
<span class="pt-badge badge-red" i18n [ngbTooltip]="video.blacklistedReason">Blocked</span>
}
@@ -58,18 +73,6 @@
</td>
}
- @if (table.isColumnDisplayed('playlists')) {
- <td>
- <div class="badges playlists">
- @for (playlist of (videosContainedInPlaylists[video.id] || []); track playlist) {
- <a class="pt-badge badge-secondary pt-badge-keep-case" [routerLink]="['/w/p/', playlist.playlistShortUUID]">
- {{ playlist.playlistDisplayName }}
- </a>
- }
- </div>
- </td>
- }
-
@if (table.isColumnDisplayed('insights')) {
<td>
<a class="pt" [routerLink]="[ '/videos/manage', video.shortUUID, 'stats' ]" i18n-title title="Navigate to the video stats page">
@@ -108,6 +111,18 @@
}
</td>
}
+
+ @if (table.isColumnDisplayed('playlists')) {
+ <td>
+ <div class="badges playlists">
+ @for (playlist of (videosContainedInPlaylists[video.id] || []); track playlist) {
+ <a class="pt-badge pt-badge-keep-case" [class]="getPlaylistBadge(playlist.playlistDisplayName)" [routerLink]="['/w/p/', playlist.playlistShortUUID]">
+ {{ playlist.playlistDisplayName }}
+ </a>
+ }
+ </div>
+ </td>
+ }
</ng-template>
<ng-template #actionCell let-video>
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.scss b/client/src/app/+my-library/my-videos/my-videos.component.scss
index 3aef325256..0bd8b61961 100644
--- a/client/src/app/+my-library/my-videos/my-videos.component.scss
+++ b/client/src/app/+my-library/my-videos/my-videos.component.scss
@@ -10,7 +10,7 @@ my-select-checkbox {
@include margin-right(5px);
}
-.playlists {
+.badges {
.pt-badge {
max-width: 200px;
vertical-align: bottom;
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.ts b/client/src/app/+my-library/my-videos/my-videos.component.ts
index 92c5242ba0..5ad1b32cc2 100644
--- a/client/src/app/+my-library/my-videos/my-videos.component.ts
+++ b/client/src/app/+my-library/my-videos/my-videos.component.ts
@@ -4,8 +4,9 @@ import { RouterLink } from '@angular/router'
import { AuthService, AuthUser, ConfirmService, Notifier, RestPagination, ServerService } from '@app/core'
import { HeaderService } from '@app/header/header.service'
import { formatICU } from '@app/helpers'
-import { AdvancedFilterDef } from '@app/shared/shared-forms/advanced-input-filter.component'
import { ChannelToggleComponent } from '@app/shared/shared-channels/channel-toggle.component'
+import { AdvancedFilterDef } from '@app/shared/shared-forms/advanced-input-filter.component'
+import { PeerTubeBadgeService } from '@app/shared/shared-main/common/peertube-badge.service'
import { Video } from '@app/shared/shared-main/video/video.model'
import { VideoService } from '@app/shared/shared-main/video/video.service'
import { TableColumnInfo, TableComponent, TableQueryParams } from '@app/shared/shared-tables/table.component'
@@ -30,7 +31,18 @@ import { VideoNSFWBadgeComponent } from '../../shared/shared-video/video-nsfw-ba
import { VideoStateBadgeComponent } from '../../shared/shared-video/video-state-badge.component'
import { VideoChangeOwnershipComponent } from './modals/video-change-ownership.component'
-type ColumnName = 'duration' | 'name' | 'language' | 'privacy' | 'sensitive' | 'playlists' | 'insights' | 'published' | 'state' | 'comments'
+type ColumnName =
+ | 'duration'
+ | 'name'
+ | 'tags'
+ | 'language'
+ | 'privacy'
+ | 'sensitive'
+ | 'playlists'
+ | 'insights'
+ | 'published'
+ | 'state'
+ | 'comments'
type QueryParams = TableQueryParams & {
channelNameOneOf?: string[]
@@ -66,6 +78,7 @@ export class MyVideosComponent implements OnInit, OnDestroy {
private playlistService = inject(VideoPlaylistService)
private server = inject(ServerService)
private headerService = inject(HeaderService)
+ private badgeService = inject(PeerTubeBadgeService)
readonly videoChangeOwnershipModal = viewChild<VideoChangeOwnershipComponent>('videoChangeOwnershipModal')
readonly table = viewChild<TableComponent<Video, DataLoaderParameter, ColumnName, QueryParams>>('table')
@@ -117,14 +130,15 @@ export class MyVideosComponent implements OnInit, OnDestroy {
this.columns = [
{ id: 'duration', label: $localize`Duration`, selected: true, sortable: true },
{ id: 'name', label: $localize`Name`, selected: true, sortable: true },
+ { id: 'tags', label: $localize`Tags`, selected: true, sortable: false },
{ id: 'privacy', label: $localize`Privacy`, selected: true, sortable: false },
{ id: 'sensitive', label: $localize`Sensitive`, selected: true, sortable: false },
- { id: 'playlists', label: $localize`Playlists`, selected: true, sortable: false },
{ id: 'insights', label: $localize`Insights`, selected: true, sortable: true, sortKey: 'views' },
{ id: 'comments', label: $localize`Comments`, selected: true, sortable: true },
{ id: 'published', label: $localize`Published`, selected: true, sortable: true, sortKey: 'publishedAt' },
{ id: 'state', label: $localize`State`, selected: true, sortable: false },
- { id: 'language', label: $localize`Language`, selected: false, sortable: false }
+ { id: 'language', label: $localize`Language`, selected: false, sortable: false },
+ { id: 'playlists', label: $localize`Playlists`, selected: true, sortable: false }
]
this.inputFilters = [
@@ -151,6 +165,12 @@ export class MyVideosComponent implements OnInit, OnDestroy {
{ value: VideoPrivacy.PASSWORD_PROTECTED, label: $localize`Password protected videos` },
{ value: VideoPrivacy.PRIVATE, label: $localize`Private videos` }
]
+ },
+
+ {
+ type: 'tags',
+ key: 'tagsOneOf',
+ title: $localize`One of these tags`
}
]
@@ -206,8 +226,9 @@ export class MyVideosComponent implements OnInit, OnDestroy {
search: string
isLive?: boolean
privacyOneOf?: VideoPrivacyType
+ tagsOneOf?: string[]
}) {
- const { pagination, sort, search, isLive, privacyOneOf } = options
+ const { pagination, sort, search, isLive, privacyOneOf, tagsOneOf } = options
const channelNameOneOf = this.channels.filter(c => c.selected).map(c => c.name)
@@ -222,9 +243,12 @@ export class MyVideosComponent implements OnInit, OnDestroy {
: undefined,
isLive,
+
privacyOneOf: privacyOneOf !== undefined
? [ privacyOneOf ]
- : undefined
+ : undefined,
+
+ tagsOneOf
}).pipe(tap(({ data }) => this.fetchVideosContainedInPlaylists(data)))
}
@@ -238,6 +262,10 @@ export class MyVideosComponent implements OnInit, OnDestroy {
})
}
+ getPlaylistBadge (playlistName: string) {
+ return this.badgeService.getRandomBadge('playlist', playlistName)
+ }
+
async removeVideos (videos: Video[]) {
const message = formatICU(
$localize`Are you sure you want to delete {count, plural, =1 {this video} other {these {count} videos}}?`,
@@ -275,4 +303,8 @@ export class MyVideosComponent implements OnInit, OnDestroy {
]
]
}
+
+ getPrivacyFilterTitle (privacy: string) {
+ return $localize`Filter by privacy: ${privacy}`
+ }
}
diff --git a/client/src/app/shared/shared-main/video/video-details.model.ts b/client/src/app/shared/shared-main/video/video-details.model.ts
index 0ca12a9bd7..ca416b441d 100644
--- a/client/src/app/shared/shared-main/video/video-details.model.ts
+++ b/client/src/app/shared/shared-main/video/video-details.model.ts
@@ -19,7 +19,6 @@ export class VideoDetails extends Video implements VideoDetailsServerModel {
declare account: Account
support: string
- tags: string[]
downloadEnabled: boolean
commentsPolicy: ConstantLabel<VideoCommentPolicyType>
@@ -38,6 +37,7 @@ export class VideoDetails extends Video implements VideoDetailsServerModel {
declare streamingPlaylists: VideoStreamingPlaylist[]
declare waitTranscoding: boolean
declare state: ConstantLabel<VideoStateType>
+ declare tags: string[]
constructor (hash: VideoDetailsServerModel, translations = {}) {
super(hash, translations)
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts
index 6a7db68c13..8379a13cea 100644
--- a/client/src/app/shared/shared-main/video/video.model.ts
+++ b/client/src/app/shared/shared-main/video/video.model.ts
@@ -123,6 +123,7 @@ export class Video implements VideoServerModel {
videoSource?: VideoSource
+ tags?: string[]
automaticTags?: string[]
comments: number
@@ -228,6 +229,7 @@ export class Video implements VideoServerModel {
this.aspectRatio = hash.aspectRatio
+ this.tags = hash.tags
this.automaticTags = hash.automaticTags
this.comments = hash.comments
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts
index 00c2e93af8..f19e981068 100644
--- a/client/src/app/shared/shared-main/video/video.service.ts
+++ b/client/src/app/shared/shared-main/video/video.service.ts
@@ -128,10 +128,11 @@ export class VideoService {
isLive?: boolean
privacyOneOf?: VideoPrivacyType[]
+ tagsOneOf?: string[]
channelNameOneOf: string[]
search?: string
}): Observable<ResultList<Video>> {
- const { videoPagination, restPagination, sort, channelNameOneOf, privacyOneOf, search, includeCollaborations } = options
+ const { videoPagination, restPagination, sort, channelNameOneOf, privacyOneOf, tagsOneOf, search, includeCollaborations } = options
const pagination = videoPagination
? this.restService.componentToRestPagination(videoPagination)
@@ -145,6 +146,7 @@ export class VideoService {
if (exists(options.isLive)) commonFilters.isLive = options.isLive
if (options.search) commonFilters.search = search
if (options.privacyOneOf) commonFilters.privacyOneOf = privacyOneOf
+ if (options.tagsOneOf) commonFilters.tagsOneOf = tagsOneOf
params = this.restService.addObjectParams(params, commonFilters)
diff --git a/client/src/app/shared/shared-tables/table.component.ts b/client/src/app/shared/shared-tables/table.component.ts
index 8e7f254327..a9724cc314 100644
--- a/client/src/app/shared/shared-tables/table.component.ts
+++ b/client/src/app/shared/shared-tables/table.component.ts
@@ -329,7 +329,12 @@ export class TableComponent<
// ---------------------------------------------------------------------------
saveSelectedColumns () {
- const enabled = this.columns.filter(c => c.selected !== false).map(c => c.id)
+ const enabled = this.columns.reduce((p, c) => {
+ return {
+ ...p,
+ [c.id as string]: c.selected !== false
+ }
+ }, {} as Record<string, boolean>)
this.peertubeLocalStorage.setItem(this.getColumnLocalStorageKey(), JSON.stringify(enabled))
}
@@ -338,11 +343,14 @@ export class TableComponent<
const enabledString = this.peertubeLocalStorage.getItem(this.getColumnLocalStorageKey())
if (!enabledString) return
+
try {
const enabled = JSON.parse(enabledString)
for (const column of this.columns) {
- column.selected = enabled.includes(column.id)
+ if (enabled[column.id] !== undefined) {
+ column.selected = enabled[column.id] === true
+ }
}
} catch (err) {
logger.error('Cannot load selected columns.', err)
@@ -350,7 +358,7 @@ export class TableComponent<
}
private getColumnLocalStorageKey () {
- return 'rest-table-columns-' + this.key()
+ return 'rest-table-columns-' + this.key() + '-state'
}
// ---------------------------------------------------------------------------
diff --git a/client/src/app/shared/shared-video/privacy-badge.component.ts b/client/src/app/shared/shared-video/privacy-badge.component.ts
index e19a284d04..1026a9b8e8 100644
--- a/client/src/app/shared/shared-video/privacy-badge.component.ts
+++ b/client/src/app/shared/shared-video/privacy-badge.component.ts
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common'
-import { Component, inject, input, LOCALE_ID, OnChanges } from '@angular/core'
+import { booleanAttribute, Component, inject, input, LOCALE_ID, OnChanges } from '@angular/core'
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'
import { Video, VideoPlaylistPrivacy, VideoPlaylistPrivacyType, VideoPrivacy, VideoPrivacyType } from '@peertube/peertube-models'
import { VideoPlaylist } from '../shared-video-playlist/video-playlist.model'
@@ -14,6 +14,7 @@ export class PrivacyBadgeComponent implements OnChanges {
readonly video = input<Pick<Video, 'privacy' | 'scheduledUpdate'>>(undefined)
readonly playlist = input<Pick<VideoPlaylist, 'privacy'>>(undefined)
+ readonly displayTooltip = input(true, { transform: booleanAttribute })
private videoBadges: { [id in VideoPrivacyType]: string } = {
[VideoPrivacy.PUBLIC]: 'badge-green',
@@ -36,7 +37,10 @@ export class PrivacyBadgeComponent implements OnChanges {
ngOnChanges (): void {
this.label = this.buildLabel()
this.badgeClass = this.buildBadgeClass()
- this.tooltip = this.buildTooltip()
+
+ this.tooltip = this.displayTooltip()
+ ? this.buildTooltip()
+ : undefined
}
buildBadgeClass () {
diff --git a/packages/models/src/videos/video.model.ts b/packages/models/src/videos/video.model.ts
index 40e6b65a0b..bdf8924337 100644
--- a/packages/models/src/videos/video.model.ts
+++ b/packages/models/src/videos/video.model.ts
@@ -107,6 +107,7 @@ export interface VideoAdditionalAttributes {
videoSource: VideoSource
automaticTags: string[]
+ tags: string[]
liveSchedules: LiveVideoScheduleEdit[]
}
diff --git a/packages/tests/src/api/check-params/runners.ts b/packages/tests/src/api/check-params/runners.ts
index 9cb6a4eaea..fba47d9675 100644
--- a/packages/tests/src/api/check-params/runners.ts
+++ b/packages/tests/src/api/check-params/runners.ts
@@ -23,7 +23,6 @@ import {
VideoStudioCommand,
waitJobs
} from '@peertube/peertube-server-commands'
-import { isRunnerJobTypeValid } from '@peertube/peertube-server/core/helpers/custom-validators/runners/jobs.js'
import { checkBadCountPagination, checkBadSort, checkBadStartPagination } from '@tests/shared/checks.js'
import { basename } from 'path'
diff --git a/packages/tests/src/api/users/user-videos.ts b/packages/tests/src/api/users/user-videos.ts
index 927ccdc84e..03230aa54c 100644
--- a/packages/tests/src/api/users/user-videos.ts
+++ b/packages/tests/src/api/users/user-videos.ts
@@ -111,11 +111,14 @@ describe('Test user videos', function () {
it('Should be able to upload a video with a user', async function () {
this.timeout(30000)
- const attributes = {
- name: 'super user video',
- fixture: 'video_short.webm'
- }
- await server.videos.upload({ token, attributes })
+ await server.videos.upload({
+ token,
+ attributes: {
+ name: 'super user video',
+ fixture: 'video_short.webm',
+ tags: [ 'tag1', 'tag2' ]
+ }
+ })
await server.channels.create({ token, attributes: { name: 'other_channel' } })
})
@@ -139,6 +142,8 @@ describe('Test user videos', function () {
const video = data[0]
expect(video.name).to.equal('super user video')
expect(video.thumbnails).to.have.lengthOf(5)
+
+ expect(video.tags).to.have.members([ 'tag1', 'tag2' ])
})
it('Should be able to filter by a specific channel in my videos', async function () {
diff --git a/server/core/controllers/api/users/me.ts b/server/core/controllers/api/users/me.ts
index 7dbfca8b9f..7d6c4716c9 100644
--- a/server/core/controllers/api/users/me.ts
+++ b/server/core/controllers/api/users/me.ts
@@ -147,7 +147,7 @@ async function listMyVideos (req: express.Request, res: express.Response) {
const query = pickCommonVideoQuery(req.query)
const include = (query.include || VideoInclude.NONE) | VideoInclude.BLACKLISTED | VideoInclude.NOT_PUBLISHED_STATE |
- VideoInclude.BLOCKED_OWNER
+ VideoInclude.BLOCKED_OWNER | VideoInclude.TAGS
const apiOptions = await Hooks.wrapObject(
{
diff --git a/server/core/models/video/formatter/video-api-format.ts b/server/core/models/video/formatter/video-api-format.ts
index e3c0671471..980dffb751 100644
--- a/server/core/models/video/formatter/video-api-format.ts
+++ b/server/core/models/video/formatter/video-api-format.ts
@@ -11,8 +11,8 @@ import {
import { uuidToShort } from '@peertube/peertube-node-utils'
import { tracer } from '@server/lib/opentelemetry/tracing.js'
import { getHLSResolutionPlaylistFilename } from '@server/lib/paths.js'
-import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls.js'
import { VideoStatsManager } from '@server/lib/stats/video-stats-manager.js'
+import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls.js'
import { generateMagnetUri } from '@server/lib/webtorrent.js'
import { isArray } from '../../../helpers/custom-validators/misc.js'
import {
@@ -41,6 +41,7 @@ export type VideoFormattingJSONOptions = {
blockedOwner?: boolean
automaticTags?: boolean
liveSchedules?: boolean
+ tags?: boolean
}
}
@@ -57,6 +58,7 @@ export function guessAdditionalAttributesFromQuery (
source: !!(query.include & VideoInclude.SOURCE),
blockedOwner: !!(query.include & VideoInclude.BLOCKED_OWNER),
automaticTags: !!(query.include & VideoInclude.AUTOMATIC_TAGS),
+ tags: !!(query.include & VideoInclude.TAGS),
liveSchedules: query.includeScheduledLive
}
}
@@ -384,5 +386,9 @@ function buildAdditionalAttributes (video: MVideoFormattable, options: VideoForm
result.liveSchedules = (video.VideoLive?.LiveSchedules || []).map(s => s.toFormattedJSON())
}
+ if (add?.tags === true) {
+ result.tags = (video.Tags || []).map(t => t.name)
+ }
+
return result
}
diff --git a/server/core/types/models/video/video.ts b/server/core/types/models/video/video.ts
index 471604f960..871a2ad979 100644
--- a/server/core/types/models/video/video.ts
+++ b/server/core/types/models/video/video.ts
@@ -250,6 +250,7 @@ export type MVideoFormattable =
& PickWithOpt<VideoModel, 'VideoFiles', MVideoFile[]>
& PickWithOpt<VideoModel, 'VideoLive', MVideoLiveWithSchedules>
& PickWithOpt<VideoModel, 'VideoAutomaticTags', MVideoAutomaticTagWithTag[]>
+ & PickWithOpt<VideoModel, 'Tags', MTag[]>
& PickWithOpt<VideoModel, 'VideoSource', MVideoSource>
export type MVideoFormattableDetails =