-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
youtube: add support for OAuth2 tokens (#558)
- Loading branch information
Showing
6 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
import { Innertube } from 'youtubei.js'; | ||
import { Red } from '../modules/sub/consoleText.js' | ||
|
||
const bail = (...msg) => { | ||
console.error(...msg); | ||
throw new Error(msg); | ||
}; | ||
|
||
const tube = await Innertube.create(); | ||
|
||
tube.session.once( | ||
'auth-pending', | ||
({ verification_url, user_code }) => { | ||
console.log(`${Red('[!]')} The token generated by this script is sensitive and you should not share it with anyone!`); | ||
console.log(` By using this token, you are risking your Google account getting terminated.`); | ||
console.log(` You should ${Red('NOT')} use your personal account!`); | ||
console.log(); | ||
console.log(`Open ${verification_url} in a browser and enter ${user_code} when asked for the code.`); | ||
} | ||
); | ||
|
||
tube.session.once('auth-error', (err) => bail('An error occurred:', err)); | ||
tube.session.once('auth', ({ status, credentials, ...rest }) => { | ||
if (status !== 'SUCCESS') { | ||
bail('something went wrong', rest); | ||
} | ||
|
||
console.log( | ||
'add this cookie to the youtube_oauth array in your cookies file:', | ||
JSON.stringify( | ||
Object.entries(credentials) | ||
.map(([k, v]) => `${k}=${v instanceof Date ? v.toISOString() : v}`) | ||
.join('; ') | ||
) | ||
); | ||
}); | ||
|
||
await tube.session.signIn(); |
This file contains 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
File renamed without changes.
File renamed without changes.