Skip to content

Commit

Permalink
chore(docs): update examples to reflect recent changes [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Feb 26, 2023
1 parent f4e0f30 commit 0b1840a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 32 deletions.
42 changes: 26 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Thank you for taking the time to contribute!
The following is a set of guidelines for contributing to YouTube.js.
___
* [Issues](#issues)
* [Create a new issue](#issue-1)
* [Solve an issue](#issue-2)

* [Make changes](#changes)
* [Commit your updates](#changes-1)
* [Create a PR](#changes-2)
* [Run tests](#test)
* [Lint your code](#lint)
* [Build](#build)
- [Contributing to YouTube.js](#contributing-to-youtubejs)
- [Issues](#issues)
- [Create a new issue](#create-a-new-issue)
- [Solve an issue](#solve-an-issue)
- [Make changes](#make-changes)
- [Commit your updates](#commit-your-updates)
- [Pull Request](#pull-request)
- [Test](#test)
- [Lint](#lint)
- [Build](#build)

## Issues

Expand Down Expand Up @@ -66,16 +66,26 @@ npm run lint:fix
#### Build

```bash
# Node
npm run build:node

# Browser
npm run build:browser
npm run build:browser:prod
# Build all
npm run build

# Protobuf
npm run build:proto

# Parser map
npm run build:parser-map

# Deno
npm run build:deno

# ES Module
npm run build:esm

# Node
npm run bundle:node

# Browser
npm run bundle:browser
npm run bundle:browser:prod

```
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ YouTube.js supports streaming of videos in the browser by converting YouTube's s
The example below uses [`dash.js`](https://github.com/Dash-Industry-Forum/dash.js) to play the video.

```ts
import { Innertube } from 'youtubei.js';
import { Innertube } from 'youtubei.js/web';
import dashjs from 'dashjs';

const youtube = await Innertube.create({ /* setup - see above */ });
Expand Down Expand Up @@ -210,7 +210,7 @@ Our cache uses the `node:fs` module in Node-like environments, `Deno.writeFile`
import { Innertube, UniversalCache } from 'youtubei.js';
// By default, cache stores files in the OS temp directory (or indexedDB in browsers).
const yt = await Innertube.create({
cache: new UniversalCache()
cache: new UniversalCache(false)
});

// You may wish to make the cache persistent (on Node and Deno)
Expand Down
2 changes: 1 addition & 1 deletion examples/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Innertube, UniversalCache } = require('youtubei.js');
(async () => {
const yt = await Innertube.create({
// required if you wish to use OAuth#cacheCredentials
cache: new UniversalCache()
cache: new UniversalCache(false)
});

// 'auth-pending' is fired with the info needed to sign in via OAuth.
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To use YouTube.js in the browser you must proxy requests through your own server
We'll use our own fetch implementation to proxy requests through our server. This is a simple example, but you can use any fetch implementation you want.

```ts
import { Innertube } from "youtubei.js/build/browser";
import { Innertube } from "youtubei.js/web.bundle.min";

const yt = await Innertube.create({
fetch: async (input, init) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/channel/basic-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Innertube, UniversalCache, YTNodes } from 'youtubei.js';

(async () => {
const yt = await Innertube.create({ cache: new UniversalCache(), generate_session_locally: true });
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });

const channel = await yt.getChannel('UCX6OQ3DkcsbYNE6H8uQQuVA');

Expand Down
2 changes: 1 addition & 1 deletion examples/comments/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Innertube, UniversalCache } from 'youtubei.js';

(async () => {
const yt = await Innertube.create({ cache: new UniversalCache(), generate_session_locally: true });
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });

const comment_section = await yt.getComments('a-rqu-hjobc');

Expand Down
2 changes: 1 addition & 1 deletion examples/deno/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Innertube } from '../../bundle/browser.js';
import { Innertube } from 'https://deno.land/x/youtubei/deno.ts';

const yt = await Innertube.create();

Expand Down
9 changes: 4 additions & 5 deletions examples/download/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Innertube, UniversalCache } from 'youtubei.js';
import { readFileSync, existsSync, mkdirSync, createWriteStream } from 'fs';
import { streamToIterable } from 'youtubei.js/dist/src/utils/Utils';
import { Innertube, UniversalCache, Utils } from 'youtubei.js';
import { existsSync, mkdirSync, createWriteStream } from 'fs';

(async () => {
const yt = await Innertube.create({ cache: new UniversalCache(), generate_session_locally: true });
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });

const search = await yt.music.search('No Copyright Background Music', { type: 'album' });

Expand Down Expand Up @@ -34,7 +33,7 @@ import { streamToIterable } from 'youtubei.js/dist/src/utils/Utils';

const file = createWriteStream(`${dir}/${song.title?.replace(/\//g, '')}.m4a`);

for await (const chunk of streamToIterable(stream)) {
for await (const chunk of Utils.streamToIterable(stream)) {
file.write(chunk);
}

Expand Down
5 changes: 2 additions & 3 deletions examples/livechat/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Innertube, UniversalCache, YTNodes } from 'youtubei.js';
import { LiveChatContinuation } from 'youtubei.js/dist/src/parser';
import { Innertube, UniversalCache, YTNodes, LiveChatContinuation } from 'youtubei.js';
import { ChatAction, LiveMetadata } from 'youtubei.js/dist/src/parser/youtube/LiveChat';

(async () => {
const yt = await Innertube.create({ cache: new UniversalCache(), generate_session_locally: true });
const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true });

const search = await yt.search('lofi hip hop radio - beats to relax/study to');
const info = await yt.getInfo(search.videos[0].as(YTNodes.Video).id);
Expand Down
2 changes: 1 addition & 1 deletion examples/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const creds_path = './my_yt_creds.json';
const creds = existsSync(creds_path) ? JSON.parse(readFileSync(creds_path).toString()) : undefined;

(async () => {
const yt = await Innertube.create({ cache: new UniversalCache() });
const yt = await Innertube.create({ cache: new UniversalCache(false) });

yt.session.on('auth-pending', (data: any) => {
console.info(`Hello!\nOn your phone or computer, go to ${data.verification_url} and enter the code ${data.user_code}`);
Expand Down

0 comments on commit 0b1840a

Please sign in to comment.