Skip to content

Commit

Permalink
🩹 Fix uploading lower quality for some old clips
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryScaletta committed Dec 19, 2023
1 parent f726d50 commit 61be508
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/twitch-clips-downloader/twitch-clips-downloader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export class TwitchClipsDownloaderService implements OnModuleDestroy {
);
}

// For some clips lower quality links require 'AT-cm%7C' prefix after last '/'
private getMp4LinkV2(mp4: string) {
const i = mp4.lastIndexOf('/');
return mp4.slice(0, i) + '/AT-cm%7C' + mp4.slice(i + 1);
}

getSlug(url: string) {
const m = TWITCH_CLIP_REGEX.exec(url);
if (!m) return null;
Expand Down Expand Up @@ -159,16 +165,19 @@ export class TwitchClipsDownloaderService implements OnModuleDestroy {
};
if (size > SIZE_20_MB) {
for (const quality of ['720', '480'] as const) {
const mp4LinkLowRes = this.getMp4Link(clip.thumbnail_url, quality);
let mp4LinkLowRes = this.getMp4Link(clip.thumbnail_url, quality);
size = await this.getUrlContentLength(mp4LinkLowRes);
if (size !== null && size < SIZE_20_MB) {
const warningLine = `⚠️ _This video is ${quality}p\\. [Download original quality](${mp4Link})\\._`;
return {
type: 'video',
url: mp4LinkLowRes,
caption: `${title}\n\n${infoLine}\n\n${warningLine}`,
};
if (size === null) {
mp4LinkLowRes = this.getMp4LinkV2(mp4LinkLowRes);
size = await this.getUrlContentLength(mp4LinkLowRes);
}
if (size === null || size > SIZE_20_MB) continue;
const warningLine = `⚠️ _This video is ${quality}p\\. [Download original quality](${mp4Link})\\._`;
return {
type: 'video',
url: mp4LinkLowRes,
caption: `${title}\n\n${infoLine}\n\n${warningLine}`,
};
}
const warningLine = `⚠️ _Can't upload more than 20MB, please use [this link](${mp4Link}) to download\\._`;
return {
Expand Down

0 comments on commit 61be508

Please sign in to comment.