forked from sussy-code/providers
-
Notifications
You must be signed in to change notification settings - Fork 56
adding diziyou (turkish) #51
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
Open
lechixy
wants to merge
6
commits into
p-stream:production
Choose a base branch
from
lechixy:diziyou
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fdcb9d2
adding diziyou (turkish) source
lechixy 2aa77e8
fixing code review by qodo
lechixy ba78131
refactoring: review recommended section by qodo
lechixy ac2be6f
Merge branch 'p-stream:production' into diziyou
lechixy 01c18e3
fix: brittle 404 detection now checked with http status
lechixy 699d6b8
fix: adding episode not found, detect dubbed version
lechixy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export function urlifyTitle(title: string): string { | ||
| return title | ||
| .toString() | ||
| .normalize('NFD') | ||
| .replace(/[\u0300-\u036f]/g, '') | ||
| .toLowerCase() | ||
| .trim() | ||
| .replace(/\s+/g, '-') | ||
| .replace(/[^\w-]+/g, '') | ||
| .replace(/--+/g, '-') | ||
| .replace(/^-+/, '') | ||
| .replace(/-+$/, ''); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* eslint-disable no-console */ | ||
| import { flags } from '@/entrypoint/utils/targets'; | ||
| import { SourcererOutput, makeSourcerer } from '@/providers/base'; | ||
| import { Caption } from '@/providers/captions'; | ||
| import { ShowScrapeContext } from '@/utils/context'; | ||
| import { NotFoundError } from '@/utils/errors'; | ||
|
|
||
| import { urlifyTitle } from './helpers'; | ||
|
|
||
| const baseUrl = 'https://www.diziyou.one'; | ||
|
|
||
| const headers = { | ||
| Referer: baseUrl, | ||
| Accept: 'application/json, text/javascript, */*; q=0.01', | ||
| 'User-Agent': | ||
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
| }; | ||
|
|
||
| async function scrapeShow(ctx: ShowScrapeContext): Promise<SourcererOutput> { | ||
| if (!ctx.media.title) { | ||
| throw new NotFoundError('Media title is not provided'); | ||
| } | ||
|
|
||
| const urlTitle = urlifyTitle(ctx.media.title); | ||
| const showPage = await ctx.proxiedFetcher.full<string>(`/${urlTitle}/`, { | ||
| baseUrl, | ||
| headers, | ||
| }); | ||
|
|
||
| if (showPage.statusCode === 404) { | ||
| throw new NotFoundError('Media not found'); | ||
| } | ||
|
|
||
| ctx.progress(30); | ||
|
|
||
| const mediaUrl = `/${urlTitle}-${ctx.media.season.number}-sezon-${ctx.media.episode.number}-bolum/`; | ||
| const mediaPage = await ctx.proxiedFetcher.full<string>(mediaUrl, { | ||
| baseUrl, | ||
| headers, | ||
| }); | ||
| if (mediaPage.statusCode !== 200) { | ||
| throw new NotFoundError('Episode not found'); | ||
| } | ||
|
|
||
| // If there is no turkish dubbed | ||
| if (!mediaPage.body.includes('id="turkceDublaj"')) { | ||
| throw new NotFoundError('Dubbed version not found'); | ||
| } | ||
| if (!mediaPage.body.includes('<iframe id="diziyouPlayer" src="')) { | ||
| throw new NotFoundError('No iframe found'); | ||
| } | ||
|
|
||
| const iframeMatch = mediaPage.body.match(/<iframe id="diziyouPlayer" src="([^"]+)"/); | ||
| if (!iframeMatch) throw new NotFoundError('No source found'); | ||
| let iframeUrl = iframeMatch[1]; | ||
|
|
||
| try { | ||
| iframeUrl = new URL(iframeUrl, baseUrl).toString(); | ||
| } catch (e) { | ||
| throw new NotFoundError('Invalid iframe URL'); | ||
| } | ||
|
|
||
| // The _tr version of the iframe contains the Turkish dubbed stream, while the original one contains the subtitled stream | ||
| // TODO: Add an option for users to choose between dubbed and subtitled versions | ||
| iframeUrl = iframeUrl.replace('.html', '_tr.html'); | ||
|
|
||
| ctx.progress(60); | ||
|
|
||
| const playerResponse = await ctx.proxiedFetcher<string>(iframeUrl, { | ||
| headers: { | ||
| Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | ||
| Referer: baseUrl, | ||
| 'Sec-Fetch-Dest': 'iframe', | ||
| 'Sec-Fetch-Mode': 'navigate', | ||
| 'Sec-Fetch-Site': 'cross-site', | ||
| 'Sec-Fetch-User': '?1', | ||
| 'Sec-GPC': '1', | ||
| 'Upgrade-Insecure-Requests': '1', | ||
| 'User-Agent': | ||
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
| }, | ||
| }); | ||
|
|
||
| if (!playerResponse.includes('<source id="diziyouSource" src="')) throw new NotFoundError('No source found'); | ||
| const playlistUrl = playerResponse.split('<source id="diziyouSource" src="')[1]?.split('"')[0]; | ||
|
|
||
| ctx.progress(80); | ||
|
|
||
| const captions: Caption[] = []; | ||
| const regex = /<track\s+src="([^"]+)"[^>]*srclang="([^"]+)"[^>]*label="([^"]+)"/g; | ||
| const captionMatches = playerResponse.matchAll(regex); | ||
|
|
||
| for (const match of captionMatches) { | ||
| const subtitleFormat = match[1].endsWith('.vtt') ? 'vtt' : 'srt'; | ||
|
|
||
| captions.push({ | ||
| url: match[1], | ||
| language: match[2], | ||
| hasCorsRestrictions: false, | ||
| id: `diziyou-${ctx.media.tmdbId}-caption-${match[2]}`, | ||
| type: subtitleFormat, | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| embeds: [], | ||
| stream: [ | ||
| { | ||
| id: 'primary', | ||
| type: 'hls', | ||
| playlist: playlistUrl, | ||
| headers, | ||
| flags: [flags.CORS_ALLOWED], | ||
| captions, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| export const diziyouScraper = makeSourcerer({ | ||
| id: 'diziyou', | ||
| name: 'Diziyou (Turkish)', | ||
| rank: 217, | ||
| disabled: false, | ||
| flags: [flags.CORS_ALLOWED], | ||
| scrapeShow, | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.