itube-specs 0.0.776 → 0.0.777
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
import type { IRawVideoData, IVideoData } from '../../../types';
|
|
1
|
+
import type { IRawVideoData, IVideoData, ISceneGroup, ITimelineGroup } from '../../../types';
|
|
2
|
+
|
|
3
|
+
// «locations» → «Locations», «living_room» → «Living room».
|
|
4
|
+
const humanize = (value: string): string => {
|
|
5
|
+
const text = value.replace(/_/g, ' ').trim();
|
|
6
|
+
return text ? text.charAt(0).toUpperCase() + text.slice(1) : text;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// timelines_groups ({ name, actions:[{ duration?, title }] }) → sceneGroups ({ id, title, scenes:[{ start, title }] }).
|
|
10
|
+
const cleanTimelineGroups = (raw: ITimelineGroup[] | null): ISceneGroup[] | null => {
|
|
11
|
+
if (!Array.isArray(raw)) return null;
|
|
12
|
+
|
|
13
|
+
const groups = raw
|
|
14
|
+
.filter((group) => Array.isArray(group?.actions) && group.actions.length > 0)
|
|
15
|
+
.map((group) => ({
|
|
16
|
+
id: group.name,
|
|
17
|
+
title: humanize(group.name),
|
|
18
|
+
scenes: group.actions.map((action) => ({
|
|
19
|
+
start: Number(action.duration) || 0,
|
|
20
|
+
title: humanize(action.title),
|
|
21
|
+
})),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
return groups.length ? groups : null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// hotspots (string[]) → number[] (значения кривой популярности по корзинам).
|
|
28
|
+
const cleanHotspots = (raw: string[] | null): number[] | null => {
|
|
29
|
+
if (!Array.isArray(raw)) return null;
|
|
30
|
+
|
|
31
|
+
const values = raw.map(Number).filter((value) => Number.isFinite(value));
|
|
32
|
+
return values.length ? values : null;
|
|
33
|
+
};
|
|
2
34
|
|
|
3
35
|
/** Нормализует сырые данные видео к типу IVideoData. */
|
|
4
36
|
export const cleanVideoData = (data: IRawVideoData): IVideoData => ({
|
|
@@ -30,6 +62,6 @@ export const cleanVideoData = (data: IRawVideoData): IVideoData => ({
|
|
|
30
62
|
thumbNum: data.thumb_number || 0,
|
|
31
63
|
description: data.description || '',
|
|
32
64
|
dislikes: data.dislikes || 0,
|
|
33
|
-
hotspots: data.hotspots
|
|
34
|
-
timelinesGroups: data.timelines_groups
|
|
65
|
+
hotspots: cleanHotspots(data.hotspots),
|
|
66
|
+
timelinesGroups: cleanTimelineGroups(data.timelines_groups),
|
|
35
67
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IRawThumbUrls } from './raw-thumbs-urls';
|
|
2
|
+
import type { ITimelineGroup } from '../video-data';
|
|
2
3
|
|
|
3
4
|
export interface IRawVideoData {
|
|
4
5
|
guid: string;
|
|
@@ -51,6 +52,6 @@ export interface IRawVideoData {
|
|
|
51
52
|
reels_url: string; // unused
|
|
52
53
|
vtt_url: string;
|
|
53
54
|
vtt_sprite_url: string;
|
|
54
|
-
hotspots:
|
|
55
|
-
timelines_groups:
|
|
55
|
+
hotspots: string[],
|
|
56
|
+
timelines_groups: ITimelineGroup[] | null
|
|
56
57
|
}
|
package/types/video-data.d.ts
CHANGED
|
@@ -5,6 +5,29 @@ export interface ITimestamp {
|
|
|
5
5
|
title: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
// Сырые группы таймлайна, как приходят с бека.
|
|
9
|
+
export interface ITimelineGroupAction {
|
|
10
|
+
duration?: number;
|
|
11
|
+
title: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ITimelineGroup {
|
|
15
|
+
name: string;
|
|
16
|
+
actions: ITimelineGroupAction[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Очищенная форма: id (сырое имя, для иконок), человекочитаемый title, сцены со start.
|
|
20
|
+
export interface ISceneGroupScene {
|
|
21
|
+
start: number;
|
|
22
|
+
title: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ISceneGroup {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
scenes: ISceneGroupScene[];
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
export interface IVideoData {
|
|
9
32
|
guid: string;
|
|
10
33
|
md5: string;
|
|
@@ -38,6 +61,6 @@ export interface IVideoData {
|
|
|
38
61
|
isDeleted: boolean;
|
|
39
62
|
thumbNum: number;
|
|
40
63
|
description: string;
|
|
41
|
-
hotspots:
|
|
42
|
-
timelinesGroups:
|
|
64
|
+
hotspots: number[] | null,
|
|
65
|
+
timelinesGroups: ISceneGroup[] | null
|
|
43
66
|
}
|