Skip to content

Commit

Permalink
fix deno build
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Sep 6, 2022
1 parent 0fa44b8 commit a265d1f
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 124 deletions.
4 changes: 1 addition & 3 deletions deno/Structures/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface ChannelIconInterface {
height: number;
}

class Channel {
export class Channel {
name?: string;
verified: boolean;
id?: string;
Expand Down Expand Up @@ -93,5 +93,3 @@ class Channel {
};
}
}

export default Channel;
10 changes: 4 additions & 6 deletions deno/Structures/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
* SOFTWARE.
*/

import Thumbnail from "./Thumbnail.ts";
import Video from "./Video.ts";
import Channel from "./Channel.ts";
import { Thumbnail } from "./Thumbnail.ts";
import { Video } from "./Video.ts";
import { Channel } from "./Channel.ts";
import Util from "../Util.ts";
const BASE_API = "https://www.youtube.com/youtubei/v1/browse?key=";

class Playlist {
export class Playlist {
id?: string;
title?: string;
videoCount: number;
Expand Down Expand Up @@ -148,5 +148,3 @@ class Playlist {
};
}
}

export default Playlist;
4 changes: 1 addition & 3 deletions deno/Structures/Thumbnail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

type ThumbnailType = "default" | "hqdefault" | "mqdefault" | "sddefault" | "maxresdefault" | "ultrares";
class Thumbnail {
export class Thumbnail {
id?: string;
width: number;
height: number;
Expand Down Expand Up @@ -88,5 +88,3 @@ class Thumbnail {
};
}
}

export default Thumbnail;
8 changes: 3 additions & 5 deletions deno/Structures/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* SOFTWARE.
*/

import Channel from "./Channel.ts";
import Thumbnail from "./Thumbnail.ts";
import { Channel } from "./Channel.ts";
import { Thumbnail } from "./Thumbnail.ts";

export interface VideoStreamingData {
expiresInSeconds: string;
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface VideoStreamingFormatAdaptive extends VideoStreamingFormat {
loudnessDb?: number;
}

class Video {
export class Video {
id?: string;
title?: string;
description?: string;
Expand Down Expand Up @@ -216,5 +216,3 @@ class Video {
return res;
}
}

export default Video;
20 changes: 4 additions & 16 deletions deno/Structures/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,7 @@
* SOFTWARE.
*/

import Channel, { ChannelIconInterface } from "./Channel.ts";
import Playlist from "./Playlist.ts";
import Video, { VideoStreamingData, VideoStreamingFormat, VideoStreamingFormatAdaptive } from "./Video.ts";
import Thumbnail from "./Thumbnail.ts";

// prettier-ignore
export {
Channel,
ChannelIconInterface,
Video,
Playlist,
Thumbnail,
VideoStreamingData,
VideoStreamingFormat,
VideoStreamingFormatAdaptive
};
export * from "./Channel.ts";
export * from "./Playlist.ts";
export * from "./Video.ts";
export * from "./Thumbnail.ts";
1 change: 0 additions & 1 deletion deno/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ class Util {
description: data.videoRenderer.descriptionSnippet && data.videoRenderer.descriptionSnippet.runs[0] ? data.videoRenderer.descriptionSnippet.runs[0].text : "",
duration: data.videoRenderer.lengthText ? Util.parseDuration(data.videoRenderer.lengthText.simpleText) : 0,
duration_raw: data.videoRenderer.lengthText ? data.videoRenderer.lengthText.simpleText : null,
shorts: data.videoRenderer.thumbnailOverlays?.some((res: any) => res.thumbnailOverlayTimeStatusRenderer?.style === "SHORTS"),
thumbnail: {
id: data.videoRenderer.videoId,
url: data.videoRenderer.thumbnail.thumbnails[data.videoRenderer.thumbnail.thumbnails.length - 1].url,
Expand Down
30 changes: 4 additions & 26 deletions deno/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@
*/

import Util from "./Util.ts";
// prettier-ignore
import {
Channel,
Video,
Playlist,
Thumbnail,
ChannelIconInterface,
VideoStreamingData,
VideoStreamingFormat,
VideoStreamingFormatAdaptive
} from "./Structures/exports";
import { Channel, Video, Playlist } from "./Structures/exports.ts";
import { Formatter } from "./formatter.ts";

const SAFE_SEARCH_COOKIE = "PREF=f2=8000000";
Expand Down Expand Up @@ -307,20 +297,8 @@ class YouTube {
}
}

// prettier-ignore
export {
Util,
Thumbnail,
Channel,
Playlist,
Video,
YouTube,
Formatter,
ChannelIconInterface,
SAFE_SEARCH_COOKIE,
VideoStreamingData,
VideoStreamingFormat,
VideoStreamingFormatAdaptive
};
export { Util, YouTube, Formatter, SAFE_SEARCH_COOKIE };

export * from "./Structures/exports.ts";

export default YouTube;
10 changes: 5 additions & 5 deletions scripts/deno.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// build youtube-sr for deno

const REGEX = /import (.+) from ("|')(.+)("|')/g;
const REGEX = /(import|export) (.+) from ("|')(.+)("|')/g;
const rimraf = require("rimraf");
const readdirp = require("readdirp");
const fs = require("fs-extra");
Expand All @@ -22,7 +22,7 @@ getChalk().then(() => {

function importFormat(txt) {
return txt.split(" ").map(m => {
return ["import", "from", "as", "type", "assert"].includes(m) ? chalk.cyanBright(m) : ["{", "}"].includes(m) ? chalk.yellowBright(m) : m.startsWith('"') && m.endsWith('"') ? chalk.greenBright(m) : chalk.whiteBright(m);
return ["import", "from", "as", "type", "assert", "export"].includes(m) ? chalk.cyanBright(m) : ["{", "}"].includes(m) ? chalk.yellowBright(m) : m.startsWith('"') && m.endsWith('"') ? chalk.greenBright(m) : chalk.whiteBright(m);
}).join(" ");
}

Expand Down Expand Up @@ -55,9 +55,9 @@ function execute() {
// update imports for each match
for (const item of file.data.matchAll(REGEX)) {
// if import path does not end with .ts, append .ts
if (!item[3].endsWith(".ts") && !path.isAbsolute(item[3])) {
file.data = file.data.replace(item[3], `${item[3]}.ts`);
console.log(`${chalk.yellowBright(file.path)}\n${chalk.redBright("-")} ${importFormat(item[0])}\n${chalk.greenBright("+")} ${importFormat(item[0].replace(item[3], `${item[3]}.ts`))}\n`);
if (!item[4].endsWith(".ts") && !path.isAbsolute(item[4])) {
file.data = file.data.replace(item[0], item[0].replace(item[4], `${item[4]}.ts`));
console.log(`${chalk.yellowBright(file.path)}\n${chalk.bgRed(item[0])}\n${chalk.greenBright("+")} ${importFormat(item[0].replace(item[4], `${item[4]}.ts`))}\n`);
}
};
}
Expand Down
4 changes: 1 addition & 3 deletions src/Structures/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface ChannelIconInterface {
height: number;
}

class Channel {
export class Channel {
name?: string;
verified: boolean;
id?: string;
Expand Down Expand Up @@ -92,5 +92,3 @@ class Channel {
};
}
}

export default Channel;
10 changes: 4 additions & 6 deletions src/Structures/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
* SOFTWARE.
*/

import Thumbnail from "./Thumbnail";
import Video from "./Video";
import Channel from "./Channel";
import { Thumbnail } from "./Thumbnail";
import { Video } from "./Video";
import { Channel } from "./Channel";
import Util from "../Util";
const BASE_API = "https://www.youtube.com/youtubei/v1/browse?key=";

class Playlist {
export class Playlist {
id?: string;
title?: string;
videoCount: number;
Expand Down Expand Up @@ -147,5 +147,3 @@ class Playlist {
};
}
}

export default Playlist;
4 changes: 1 addition & 3 deletions src/Structures/Thumbnail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

type ThumbnailType = "default" | "hqdefault" | "mqdefault" | "sddefault" | "maxresdefault" | "ultrares";
class Thumbnail {
export class Thumbnail {
id?: string;
width: number;
height: number;
Expand Down Expand Up @@ -87,5 +87,3 @@ class Thumbnail {
};
}
}

export default Thumbnail;
8 changes: 3 additions & 5 deletions src/Structures/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* SOFTWARE.
*/

import Channel from "./Channel";
import Thumbnail from "./Thumbnail";
import { Channel } from "./Channel";
import { Thumbnail } from "./Thumbnail";

export interface VideoStreamingData {
expiresInSeconds: string;
Expand Down Expand Up @@ -63,7 +63,7 @@ export interface VideoStreamingFormatAdaptive extends VideoStreamingFormat {
loudnessDb?: number;
}

class Video {
export class Video {
id?: string;
title?: string;
description?: string;
Expand Down Expand Up @@ -215,5 +215,3 @@ class Video {
return res;
}
}

export default Video;
20 changes: 4 additions & 16 deletions src/Structures/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,7 @@
* SOFTWARE.
*/

import Channel, { ChannelIconInterface } from "./Channel";
import Playlist from "./Playlist";
import Video, { VideoStreamingData, VideoStreamingFormat, VideoStreamingFormatAdaptive } from "./Video";
import Thumbnail from "./Thumbnail";

// prettier-ignore
export {
Channel,
ChannelIconInterface,
Video,
Playlist,
Thumbnail,
VideoStreamingData,
VideoStreamingFormat,
VideoStreamingFormatAdaptive
};
export * from "./Channel";
export * from "./Playlist";
export * from "./Video";
export * from "./Thumbnail";
30 changes: 4 additions & 26 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@
*/

import Util from "./Util";
// prettier-ignore
import {
Channel,
Video,
Playlist,
Thumbnail,
ChannelIconInterface,
VideoStreamingData,
VideoStreamingFormat,
VideoStreamingFormatAdaptive
} from "./Structures/exports";
import { Channel, Video, Playlist } from "./Structures/exports";
import { Formatter } from "./formatter";

const SAFE_SEARCH_COOKIE = "PREF=f2=8000000";
Expand Down Expand Up @@ -306,20 +296,8 @@ class YouTube {
}
}

// prettier-ignore
export {
Util,
Thumbnail,
Channel,
Playlist,
Video,
YouTube,
Formatter,
ChannelIconInterface,
SAFE_SEARCH_COOKIE,
VideoStreamingData,
VideoStreamingFormat,
VideoStreamingFormatAdaptive
};
export { Util, YouTube, Formatter, SAFE_SEARCH_COOKIE };

export * from "./Structures/exports";

export default YouTube;

0 comments on commit a265d1f

Please sign in to comment.