Skip to content

Commit bb8de19

Browse files
Merge pull request OwnTube-tv#372 from mykhailodanilenko/feature/premium-content-ads
Enable premium content ads for premium videos
2 parents e0ddcfd + f4f175e commit bb8de19

File tree

14 files changed

+96
-70
lines changed

14 files changed

+96
-70
lines changed

OwnTube.tv/api/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export enum QUERY_KEYS {
3434
homepageLatestVideosView = "homepageLatestVideosView",
3535
categoryVideosView = "categoryVideosView",
3636
channelLatestVideosView = "channelLatestVideosView",
37+
premiumAdsCollection = "premiumAdsCollection",
38+
premiumAdsCaptionsCollection = "premiumAdsCaptionsCollection",
3739
}
3840

3941
export const WRONG_SERVER_VERSION_STATUS_CODE = 444;

OwnTube.tv/api/queries/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ export * from "./channels";
33
export * from "./instances";
44
export * from "./playlists";
55
export * from "./videos";
6-
export * from "./liveStreams";

OwnTube.tv/api/queries/liveStreams.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

OwnTube.tv/api/queries/videos.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useLocalSearchParams } from "expo-router";
22
import { RootStackParams } from "../../app/_layout";
3-
import { Query, useInfiniteQuery, useMutation, useQuery } from "@tanstack/react-query";
4-
import { GetVideosVideo } from "../models";
3+
import { Query, useInfiniteQuery, useMutation, useQueries, useQuery } from "@tanstack/react-query";
4+
import { GetVideosVideo, OwnTubeError } from "../models";
55
import { ApiServiceImpl } from "../peertubeVideosApi";
6-
import { VideosCommonQuery, Video } from "@peertube/peertube-types";
6+
import { VideosCommonQuery, Video, VideoCaption } from "@peertube/peertube-types";
77
import { SOURCES } from "../../types";
88
import { getLocalData, retry } from "../helpers";
99

@@ -142,3 +142,48 @@ export const useGetVideoCaptionsQuery = (id?: string, enabled = true) => {
142142
retry,
143143
});
144144
};
145+
146+
export const useGetVideoCaptionsCollectionQuery = (videoIds: string[] = [], queryKey: string) => {
147+
const { backend } = useLocalSearchParams<RootStackParams["index"]>();
148+
149+
return useQueries({
150+
queries: videoIds.map((videoId) => ({
151+
queryKey: [queryKey, videoId, "captions"],
152+
queryFn: async () => {
153+
try {
154+
return await ApiServiceImpl.getVideoCaptions(backend!, videoId!);
155+
} catch (e) {
156+
throw new OwnTubeError({ message: (e as unknown as { message: string }).message });
157+
}
158+
},
159+
retry,
160+
enabled: !!backend && videoIds.length > 0,
161+
})),
162+
combine: (result) => {
163+
return result.filter(({ data }) => !!data).map(({ data }) => data || ([] as VideoCaption[]));
164+
},
165+
});
166+
};
167+
168+
export const useGetVideoFullInfoCollectionQuery = (videoIds: string[] = [], queryKey: string) => {
169+
const { backend } = useLocalSearchParams<RootStackParams["index"]>();
170+
171+
return useQueries({
172+
queries: videoIds.map((videoId) => ({
173+
queryKey: [queryKey, videoId],
174+
queryFn: async () => {
175+
try {
176+
const res = await ApiServiceImpl.getVideo(backend!, videoId!);
177+
return { ...res, previewPath: `https://${backend}${res?.previewPath}` };
178+
} catch (e) {
179+
throw new OwnTubeError({ message: (e as unknown as { message: string }).message });
180+
}
181+
},
182+
retry,
183+
enabled: !!backend && videoIds.length > 0,
184+
})),
185+
combine: (result) => {
186+
return result.filter(({ data }) => !!data).map(({ data }) => data || ({} as Video));
187+
},
188+
});
189+
};

OwnTube.tv/instanceConfigs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const customizationsSchema = z
2424
hideChannelPlaylistLinks: z.boolean(),
2525
homeFeaturedLives: z.array(z.string()),
2626
refreshQueriesStaleTimeMs: z.number(),
27+
premiumContentAds: z.array(z.string()),
2728
})
2829
.partial();
2930

OwnTube.tv/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"lastWeek": "Last Week",
114114
"lastMonth": "Last Month",
115115
"lastYear": "Last Year",
116+
"last12Months": "Last 12 Months",
116117
"olderThanAYear": "Older than a year",
117118
"showMore": "Show more",
118119
"findAVideoSite": "Find a video site",
@@ -148,5 +149,5 @@
148149
"streamingNow": "Streaming now",
149150
"offline": "Offline",
150151
"privacyPolicy": "Privacy policy",
151-
"premiumVideoUnavailable": "Den här videon är inte tillgänglig för tillfället på grund av begränsningar för premiuminnehåll"
152+
"premiumVideoUnavailable": "This video is unavailable at the moment, due to premium content restrictions"
152153
}

OwnTube.tv/locales/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"lastWeek": "На прошлой неделе",
114114
"lastMonth": "В прошлом месяце",
115115
"lastYear": "В прошлом году",
116+
"last12Months": "За последние 12 месяцев",
116117
"olderThanAYear": "Старше года",
117118
"showMore": "Показать еще",
118119
"findAVideoSite": "Найти видео-сайт",

OwnTube.tv/locales/sv.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"lastWeek": "Senaste veckan",
114114
"lastMonth": "Senaste månaden",
115115
"lastYear": "Senaste året",
116+
"last12Months": "Senaste 12 månaderna",
116117
"olderThanAYear": "Äldre än ett år",
117118
"showMore": "Visa mer",
118119
"findAVideoSite": "Hitta en videosajt",
@@ -148,5 +149,5 @@
148149
"streamingNow": "Direktsändning pågår",
149150
"offline": "Offline",
150151
"privacyPolicy": "Integritetspolicy",
151-
"premiumVideoUnavailable": "Це відео зараз недоступне через обмеження преміум-контенту"
152+
"premiumVideoUnavailable": "Den här videon är inte tillgänglig för tillfället på grund av begränsningar för premiuminnehåll"
152153
}

OwnTube.tv/locales/uk.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"lastWeek": "Минулого тижня",
114114
"lastMonth": "Минулого місяця",
115115
"lastYear": "Минулого року",
116+
"last12Months": "За останні 12 місяців",
116117
"olderThanAYear": "Старші року",
117118
"showMore": "Показати ще",
118119
"findAVideoSite": "Знайти відео-сайт",

OwnTube.tv/public/featured-instances.json5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
homeHidePlaylistsOverview: false,
242242
homeFeaturedLives: ["c25424b3-a077-42a1-9b1e-eb47729f1450"],
243243
showMoreSize: 24,
244+
premiumContentAds: ["80d0b6ee-df38-4119-9234-a79b0909bd34"],
244245
},
245246
},
246247
{

0 commit comments

Comments
 (0)