mirror of
https://github.com/p-stream/providers.git
synced 2026-05-15 05:51:36 +00:00
get fed region
This commit is contained in:
parent
ca99fd6f6a
commit
f05e8fb19e
1 changed files with 32 additions and 5 deletions
|
|
@ -1,13 +1,40 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
// Thanks Nemo for this API!
|
||||||
import { flags } from '@/entrypoint/utils/targets';
|
import { flags } from '@/entrypoint/utils/targets';
|
||||||
import { EmbedOutput, makeEmbed } from '@/providers/base';
|
import { EmbedOutput, makeEmbed } from '@/providers/base';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
|
|
||||||
import { Caption } from '../captions';
|
import { Caption } from '../captions';
|
||||||
|
|
||||||
// Thanks Nemo for this API!
|
const getRegion = (): string | null => {
|
||||||
const BASE_URL = 'https://fed-api.pstream.org';
|
try {
|
||||||
const CACHE_URL = 'https://fed-api.pstream.org/cache';
|
return typeof window !== 'undefined' ? window.localStorage.getItem('__MW::region') : null;
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Unable to access localStorage:', e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getBaseUrl = (): string => {
|
||||||
|
const region = getRegion();
|
||||||
|
switch (region) {
|
||||||
|
case 'us-east':
|
||||||
|
return 'https://fed-api-east.pstream.org';
|
||||||
|
case 'us-west':
|
||||||
|
return 'https://fed-api-west.pstream.org';
|
||||||
|
case 'south-america':
|
||||||
|
return 'https://fed-api-south.pstream.org';
|
||||||
|
case 'asia':
|
||||||
|
return 'https://fed-api-asia.pstream.org';
|
||||||
|
case 'europe':
|
||||||
|
return 'https://fed-api-europe.pstream.org';
|
||||||
|
default:
|
||||||
|
return 'https://fed-api-east.pstream.org';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const BASE_URL = getBaseUrl();
|
||||||
|
|
||||||
// Language mapping for subtitles
|
// Language mapping for subtitles
|
||||||
const languageMap: Record<string, string> = {
|
const languageMap: Record<string, string> = {
|
||||||
|
|
@ -81,8 +108,8 @@ function embed(provider: {
|
||||||
// Cache URL format
|
// Cache URL format
|
||||||
apiUrl =
|
apiUrl =
|
||||||
query.type === 'movie'
|
query.type === 'movie'
|
||||||
? `${CACHE_URL}/${query.imdbId}`
|
? `${BASE_URL}/cache/${query.imdbId}`
|
||||||
: `${CACHE_URL}/${query.imdbId}/${query.season}/${query.episode}`;
|
: `${BASE_URL}/cache/${query.imdbId}/${query.season}/${query.episode}`;
|
||||||
} else {
|
} else {
|
||||||
// Standard API URL format
|
// Standard API URL format
|
||||||
apiUrl =
|
apiUrl =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue