Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow changing YouTube host for trailers #643

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/interfaces/api/settingsInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface PublicSettingsResponse {
locale: string;
emailEnabled: boolean;
newPlexLogin: boolean;
youtubeUrl: string;
}

export interface CacheItem {
Expand Down
4 changes: 4 additions & 0 deletions server/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export interface MainSettings {
mediaServerType: number;
partialRequestsEnabled: boolean;
locale: string;
youtubeUrl: string;
}

interface PublicSettings {
Expand Down Expand Up @@ -142,6 +143,7 @@ interface FullPublicSettings extends PublicSettings {
emailEnabled: boolean;
userEmailRequired: boolean;
newPlexLogin: boolean;
youtubeUrl: string;
}

export interface NotificationAgentConfig {
Expand Down Expand Up @@ -321,6 +323,7 @@ class Settings {
mediaServerType: MediaServerType.NOT_CONFIGURED,
partialRequestsEnabled: true,
locale: 'en',
youtubeUrl: '',
},
plex: {
name: '',
Expand Down Expand Up @@ -558,6 +561,7 @@ class Settings {
userEmailRequired:
this.data.notifications.agents.email.options.userEmailRequired,
newPlexLogin: this.data.main.newPlexLogin,
youtubeUrl: this.data.main.youtubeUrl,
};
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/MovieDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,16 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => {
svg: <PlayIcon />,
});
}
const trailerUrl = data.relatedVideos

const trailerVideo = data.relatedVideos
?.filter((r) => r.type === 'Trailer')
.sort((a, b) => a.size - b.size)
.pop()?.url;
.pop();
const trailerUrl =
trailerVideo?.site === 'YouTube' &&
settings.currentSettings.youtubeUrl != ''
? `${settings.currentSettings.youtubeUrl}${trailerVideo?.key}`
: trailerVideo?.url;

if (trailerUrl) {
mediaLinks.push({
Expand Down
29 changes: 29 additions & 0 deletions src/components/Settings/SettingsMain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ const SettingsMain = () => {
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
(value) => !value || !value.endsWith('/')
),
youtubeUrl: Yup.string()
.url('Must be a valid URL')
.test(
'no-trailing-slash',
'URL must not end in a trailing slash',
(value) => !value || !value.endsWith('/')
),
});

const regenerate = async () => {
Expand Down Expand Up @@ -134,6 +141,7 @@ const SettingsMain = () => {
partialRequestsEnabled: data?.partialRequestsEnabled,
trustProxy: data?.trustProxy,
cacheImages: data?.cacheImages,
youtubeUrl: data?.youtubeUrl,
}}
enableReinitialize
validationSchema={MainSettingsSchema}
Expand All @@ -150,6 +158,7 @@ const SettingsMain = () => {
partialRequestsEnabled: values.partialRequestsEnabled,
trustProxy: values.trustProxy,
cacheImages: values.cacheImages,
youtubeUrl: values.youtubeUrl,
});
mutate('/api/v1/settings/public');
mutate('/api/v1/status');
Expand Down Expand Up @@ -427,6 +436,26 @@ const SettingsMain = () => {
/>
</div>
</div>
<div className="form-row">
<label htmlFor="youtubeUrl" className="text-label">
{'YouTube URL'}
</label>
<div className="form-input-area">
<div className="form-input-field">
<Field
id="youtubeUrl"
name="youtubeUrl"
type="text"
inputMode="url"
/>
</div>
{errors.youtubeUrl &&
touched.youtubeUrl &&
typeof errors.youtubeUrl === 'string' && (
<div className="error">{errors.youtubeUrl}</div>
)}
</div>
</div>
<div className="actions">
<div className="flex justify-end">
<span className="ml-3 inline-flex rounded-md shadow-sm">
Expand Down
9 changes: 7 additions & 2 deletions src/components/TvDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,15 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
});
}

const trailerUrl = data.relatedVideos
const trailerVideo = data.relatedVideos
?.filter((r) => r.type === 'Trailer')
.sort((a, b) => a.size - b.size)
.pop()?.url;
.pop();
const trailerUrl =
trailerVideo?.site === 'YouTube' &&
settings.currentSettings.youtubeUrl != ''
? `${settings.currentSettings.youtubeUrl}${trailerVideo?.key}`
: trailerVideo?.url;

if (trailerUrl) {
mediaLinks.push({
Expand Down
1 change: 1 addition & 0 deletions src/context/SettingsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const defaultSettings = {
locale: 'en',
emailEnabled: false,
newPlexLogin: true,
youtubeUrl: '',
};

export const SettingsContext = React.createContext<SettingsContextProps>({
Expand Down
1 change: 1 addition & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ CoreApp.getInitialProps = async (initialProps) => {
locale: 'en',
emailEnabled: false,
newPlexLogin: true,
youtubeUrl: '',
};

if (ctx.res) {
Expand Down
Loading