qaraluch / yt-hacks

Node.js scripts for YT automation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yt-hacks

Quick and dirty Node.js scripts to interact with YT API.

Settings

Set up global settings like port number for servers and so on in .env file. Use .env.example as a template.

Dependencies installation

Clone the repo and install dependencies with npm package manager:

npm install

List of app dependencies:

  • googleapis
  • dotenv
  • express
  • prompt-confirm

Other dependencies:

  • docker
    • puppeteer

Authorization  

Get token

You need to acquire Google's Oauth2 tokens to run further scripts.

Before getting tokens you need get and save your credentials as clinet_secret.json file in the ./.secrets/ dir. You can find these pieces of information by going to the [Developer Console][https://console.cloud.google.com/apis/credentials], clicking your project --> APIs & auth --> credentials and download it.

Run script:

node src/getTokens.js

to create OAuth2 credentials object and save it as JSON ./.secrets/tokens.json file.

It will create a web server, so you can go to the address: http://localhost:3000 in the browser. Follow instructions on the web page.

References: [1], [2], [3].

Test YT API

If you setup correctly credentials and got your tokens, you can test YT API response using following script.

Run script:

node src/testYTAPI.js

References: [4], [5].

List all playlists

Get list of all your playslist and its id, name and items in it.

Run command:

node src/lsPlaylists.js

Take screenshot of main YT page

There is used a dockerized puppeteer.js for this task.

  1. Install docker and build an image by:
./build.sh

or

docker build -t puppeteer-img .
  1. run container:
./run.sh

or

sudo docker run \
  -it \
  --init \
  --rm \
  --cap-add=SYS_ADMIN \
  -v $(pwd):/home/node/app \
  --workdir /home/node/app \
  puppeteer-img \
  bash

It will switch to the container shell:

  1. run commands:
npm run screenshot

or

node src/screenshot.js

The screenshot of the web page will be saved to the Downloads dir in the host's CWD.

References: [6].

Sign in to the YT service

And take screenshot of the YT page behind login. For this task it is used puppeteer script: signInYT.js

Run following command to see results of this scrip:

npm run login

or

node src/loginYT.js

References: [7], [8].

Lazy load all videos' content on the page

In order to make operations on the Watch Later list you need to lazy load all content on the page. For this task it is used puppeteer script: lazyLoadPageContent.js

Run following command to see results of this scrip:

npm run scroll-down

or

node src/scrollDownWL.js

Copy videos form WL playlist to another (backup)

After load all videos for WL playlist you can backup videos to another playlist now. For this task it is used puppeteer script: copyVideosBetweenPlaylists.js

Run following command to see results of this scrip:

npm run backup-wl
npm run backup-wl 150

or

node src/backupWL.js

You can pass argument witch video number the script resume from.

References: [10].

Remove videos form playlist

For this task it is used puppeteer script: removeVideosFromPlaylist.js

Run following command to see results of this scrip:

npm run cleanup-wl

or

node src/cleanUpWL.js

References: [10].

TODOs:

  • get all your subscriptsions and save it to the lists repo

Resources:

About

Node.js scripts for YT automation


Languages

Language:JavaScript 96.0%Language:Dockerfile 2.3%Language:Shell 1.7%