Skip to content
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
33 changes: 33 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

################################################################################
# #
# Editorconfig #
# #
# This file defines basic file properties that #
# editors / IDEs use when you modify documents. #
# #
# Check https://EditorConfig.org for details. #
# #
################################################################################


root = true


[*]

end_of_line = lf

[LICENSE]
[*.{editorconfig,gitignore,json,ts,md}]

trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
charset = utf-8


[*.md]

trim_trailing_whitespace = false
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this instead? I think the comment at top is unnecessary and the ident size should be 2.

root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true

8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.vscode
video.mp4
music.mp3
audio.mp3
.vscode
video.mp4
music.mp3
audio.mp3
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Copyright 2021 DjDeveloperr
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Copyright 2021 DjDeveloperr

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# ytdl_core
Deno port of [ytdl-core](https://www.npmjs.com/package/ytdl-core) using Web Streams API.
## Usage
```ts
import ytdl from "https://deno.land/x/ytdl_core/mod.ts";
const stream = await ytdl("vRXZj0DzXIA");
const chunks: Uint8Array[] = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
const blob = new Blob(chunks);
await Deno.writeFile("video.mp4", new Uint8Array(await blob.arrayBuffer()));
```
## License
Check [License](./LICENSE) for more info.
Copyright 2021 DjDeveloper, Copyright (C) 2012-present by fent
# ytdl_core

Deno port of [ytdl-core](https://www.npmjs.com/package/ytdl-core) using Web Streams API.

## Usage

```ts
import ytdl from "https://deno.land/x/ytdl_core/mod.ts";

const stream = await ytdl("vRXZj0DzXIA");

const chunks: Uint8Array[] = [];

for await (const chunk of stream) {
chunks.push(chunk);
}

const blob = new Blob(chunks);
await Deno.writeFile("video.mp4", new Uint8Array(await blob.arrayBuffer()));
```

## License

Check [License](./LICENSE) for more info.

Copyright 2021 DjDeveloper, Copyright (C) 2012-present by fent
7 changes: 3 additions & 4 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export {default as querystring} from "https://esm.sh/querystring@0.2.1";
export { humanStr as parseTimestamp } from "https://raw.githubusercontent.com/fent/node-m3u8stream/master/src/parse-time.ts";
export * as sax from "https://deno.land/x/sax_ts@v1.2.10/src/sax.ts";
export { default as m3u8stream } from "https://esm.sh/m3u8stream@0.8.6";
export { humanStr as parseTimestamp } from "https://raw.githubusercontent.com/fent/node-m3u8stream/master/src/parse-time.ts";
export * as sax from "https://deno.land/x/sax_ts@v1.2.10/src/sax.ts";
export { default as m3u8stream } from "https://esm.sh/m3u8stream@0.8.6";
30 changes: 15 additions & 15 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export * from "./src/cache.ts";
export * from "./src/format_util.ts";
export * from "./src/formats.ts";
export * from "./src/info.ts";
export * from "./src/info_extras.ts";
export * from "./src/url_utils.ts";
export {
decipherFormats,
setDownloadURL,
cache as sigCache,
} from "./src/sig.ts";
export * from "./src/utils.ts";
export * from "./src/stream.ts";
export * from "./src/video.ts";
export { ytdl as default } from "./src/video.ts";
export * from "./src/cache.ts";
export * from "./src/format_util.ts";
export * from "./src/formats.ts";
export * from "./src/info.ts";
export * from "./src/info_extras.ts";
export * from "./src/url_utils.ts";
export {
decipherFormats,
setDownloadURL,
cache as sigCache,
} from "./src/sig.ts";
export * from "./src/utils.ts";
export * from "./src/stream.ts";
export * from "./src/video.ts";
export { ytdl as default } from "./src/video.ts";
116 changes: 58 additions & 58 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
export class Cache extends Map {
constructor(public timeout = 1000) {
super();
}
set(key: string, value: any) {
if (this.has(key)) {
clearTimeout(super.get(key).tid);
}
super.set(key, {
tid: setTimeout(this.delete.bind(this, key), this.timeout),
value,
});
return this;
}
get(key: string) {
let entry = super.get(key);
if (entry) {
return entry.value;
}
return null;
}
getOrSet(key: string, fn: CallableFunction) {
if (this.has(key)) {
return this.get(key);
} else {
let value = fn();
this.set(key, value);
(async () => {
try {
await value;
} catch (err) {
this.delete(key);
}
})();
return value;
}
}
delete(key: string) {
let entry = super.get(key);
if (entry) {
clearTimeout(entry.tid);
return super.delete(key);
} else return false;
}
clear() {
for (let entry of this.values()) {
clearTimeout(entry.tid);
}
super.clear();
}
}
export class Cache extends Map {
constructor(public timeout = 1000) {
super();
}

set(key: string, value: any) {
if (this.has(key)) {
clearTimeout(super.get(key).tid);
}

super.set(key, {
tid: setTimeout(this.delete.bind(this, key), this.timeout),
value,
});

return this;
}

get(key: string) {
let entry = super.get(key);
if (entry) {
return entry.value;
}
return null;
}

getOrSet(key: string, fn: CallableFunction) {
if (this.has(key)) {
return this.get(key);
} else {
let value = fn();
this.set(key, value);
(async () => {
try {
await value;
} catch (err) {
this.delete(key);
}
})();
return value;
}
}

delete(key: string) {
let entry = super.get(key);
if (entry) {
clearTimeout(entry.tid);
return super.delete(key);
} else return false;
}

clear() {
for (let entry of this.values()) {
clearTimeout(entry.tid);
}
super.clear();
}
}
Loading