Skip to content

Commit 686e26b

Browse files
committed
Prevent rate limitting from ponytube, other smol adjustments
1 parent 553b506 commit 686e26b

File tree

7 files changed

+1585
-35
lines changed

7 files changed

+1585
-35
lines changed

.env.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ CHECK_BLACKLISTED=false
2727
# If the playlist is missing a url from the pony archive, this setting
2828
# will tell the program what to do
2929
# This setting can be set to:
30-
# true : The missing url will be automatically added
31-
# ask : You will be asked whether or not the video should be added
32-
# each time a missing video is found
33-
# any other input : No videos will be added to the playlist
30+
# true :
31+
# The missing url will be automatically added
32+
# ask (RECOMMENDED) : You will be asked whether or not the video should be added
33+
# each time a missing video is found. Recomended since some videos manually added
34+
# to the playlist aren't in the archive *
35+
# any other input :
36+
# No videos will be added to the playlist
3437
ADD_IF_MISSING=ask
38+
# * Case [10/13/24] : Don't Mine at Night (re-upload) by Jan Animation Studios has a
39+
# link in the playlist, but not in the archive. Replacement of the alt link was likely forgotten
40+
# so this would be a case where you'd want the program not to enter the alt link
3541

3642
# If this is set to true, then any video found in the cytube playlist that
3743
# has a bad status label in the archive will be reported at the end of the

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
package-lock.json
21
.env
3-
node_modules
2+
node_modules
3+
.vscode

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ Written in js because:
55
2. This project uses [Puppeteer](https://github.com/puppeteer/puppeteer) and a still functional [plugin](https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-stealth) that enables automation without being stopped by Cloudflare
66
3. The python [alternative](https://github.com/MeiK2333/pyppeteer_stealth) is pretty outdated and was transplanted by the Puppeteer plugin anyway
77

8-
Using this requires [Node.js](https://nodejs.org/en) and a list of dependencies is listed in [package.json](https://github.com/Brambles-cat/ArchiveToCytube/blob/main/package.json)
8+
Using this requires [Node.js](https://nodejs.org/en) and a list of dependencies is listed in [package.json](https://github.com/Brambles-cat/ArchiveToCytube/blob/main/package.json) which can be installed by running
9+
```bash
10+
npm i
11+
```
912

1013
## Usage
1114
Firstly, the `CHANNEL` variable in .env must be set to the name of the Cytube channel the program should run using. Several settings in this file can also be modified to change how the program behaves. Then in the command prompt, navigate to the same directory as index.js and run

cytube_auto.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const puppeteer = require('puppeteer-extra')
22
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
33

4-
const { csv_map: index, blacklisted_creator, get_row_video_ids, get_archive_csv, log, logErr, delay, getInput } = require('./utils.js')
4+
const { csv_map: index, blacklisted_creator, get_row_links, get_archive_csv, log, logErr, delay, getInput, vid_identifier } = require('./utils.js')
55

66
puppeteer.use(StealthPlugin())
77

@@ -24,7 +24,7 @@ function update_playlist(use_cookie, headless, queue_delay, playlist_url, check_
2424

2525
if (has_edit_permissions) {
2626
try {
27-
await delay(1000)
27+
await delay(2000)
2828
// This is the + button which is needed to reveal the playlist adding video options
2929
await page.waitForSelector('#showmediaurl').then(button => button.click())
3030
await delay(1000)
@@ -69,7 +69,7 @@ function update_playlist(use_cookie, headless, queue_delay, playlist_url, check_
6969
row_is_blacklisted,
7070
csv_row = 1,
7171
add_vid_attempts = 0,
72-
row_video_ids,
72+
row_links,
7373
included,
7474
should_queue = true,
7575
is_contradictory = false
@@ -85,8 +85,8 @@ function update_playlist(use_cookie, headless, queue_delay, playlist_url, check_
8585
for (const archive_row of archive_data) {
8686
++csv_row
8787
row_is_blacklisted = check_blacklisted && blacklisted_creator(archive_row)
88-
row_video_ids = await get_row_video_ids(archive_row)
89-
included = check_includes(playlistSnapshot, row_video_ids)
88+
row_links = get_row_links(archive_row)
89+
included = await check_includes(playlistSnapshot, row_links)
9090

9191
if (row_is_blacklisted) {
9292
if (included.video_id) {
@@ -138,31 +138,31 @@ function update_playlist(use_cookie, headless, queue_delay, playlist_url, check_
138138
if (archive_row[index.NOTES].includes("age restriction")) {
139139
log(`${csv_row}: not present - ${archive_row[index.TITLE]}`)
140140

141-
if (should_queue = can_add(ask_before_adding)) {
141+
if (should_queue = can_update(ask_before_adding)) {
142142
log("adding using age-restriction bypassing link...\n")
143143
await page.type('#mediaurl', archive_row[index.NOTES].split(" ").at(-1))
144144
}
145145
}
146146
else if (!archive_row[index.STATE]) {
147147
log(`${csv_row}: not present - ${archive_row[index.TITLE]}`)
148148

149-
if (should_queue = can_add(ask_before_adding)) {
149+
if (should_queue = can_update(ask_before_adding)) {
150150
log("adding...\n")
151151
await page.type('#mediaurl', archive_row[index.LINK])
152152
}
153153
}
154154
else if (archive_row[index.FOUND] === "found") {
155155
log(`${csv_row}: not present - ${archive_row[index.TITLE]}`)
156156

157-
if (should_queue = can_add(ask_before_adding)) {
157+
if (should_queue = can_update(ask_before_adding)) {
158158
log("adding using alt link...\n")
159159
await page.type('#mediaurl', archive_row[index.ALT_LINK])
160160
}
161161
}
162-
else if (row_video_ids.length === 3) {
162+
else if (row_links.length === 3) {
163163
log(`${csv_row}: not present - ${archive_row[index.TITLE]}`)
164164

165-
if (should_queue = can_add(ask_before_adding)) {
165+
if (should_queue = can_update(ask_before_adding)) {
166166
log("adding using link in notes...\n")
167167
await page.type('#mediaurl', archive_row[index.NOTES].split(" ").at(-1))
168168
}
@@ -282,14 +282,20 @@ function update_playlist(use_cookie, headless, queue_delay, playlist_url, check_
282282
else if (archive_row[index.FOUND] === "found")
283283
url_to_add = archive_row[index.ALT_LINK]
284284
else if (archive_row[index.NOTES].includes("://"))
285-
// precondition: all urls in notes are at the end
285+
// precondition: all urls in notes are at the end of the cell
286286
url_to_add = archive_row[index.NOTES].split(" ").at(-1)
287287
else {
288288
logErr("No useable links found", false)
289+
if (can_update(true, "Remove bad url only?")) {
290+
if (await page.$('.server-msg-disconnect')) {
291+
logErr('Disconnected from server because of duplicate login')
292+
return
293+
}
294+
}
289295
continue
290296
}
291297

292-
if (can_add(true, "Remove bad url and replace with an alternative?")) {
298+
if (can_update(true, "Remove bad url and replace with an alternative?")) {
293299
if (await page.$('.server-msg-disconnect')) {
294300
logErr('Disconnected from server because of duplicate login')
295301
return
@@ -372,12 +378,12 @@ async function normal_login(page, url, headless) {
372378

373379
id_indices = [index.LINK, index.ALT_LINK, index.NOTES]
374380

375-
function check_includes(playlist_snapshot, video_ids) {
381+
async function check_includes(playlist_snapshot, video_links) {
376382
const ret = {archive_index: null, video_id: null}
377383
let id, i = 0
378384

379-
for (;i < video_ids.length; ++i) {
380-
id = video_ids[i]
385+
for (;i < video_links.length; ++i) {
386+
id = await vid_identifier(video_links[i])
381387

382388
if (typeof id === "string") {
383389
if (id in playlist_snapshot) {
@@ -402,7 +408,7 @@ function check_includes(playlist_snapshot, video_ids) {
402408
return ret
403409
}
404410

405-
function can_add(ask=true, msg="Add this video to the playlist?") {
411+
function can_update(ask=true, msg="Add this video to the playlist?") {
406412
return (
407413
has_edit_permissions &&
408414
(

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ const { logErr, log, setErrDelay, blacklist_check } = require('./utils.js')
33
require('dotenv').config()
44

55

6-
function get(v) {
7-
if (v === undefined || v.toLowerCase() === "false")
6+
function get(variable) {
7+
if (variable === undefined || variable.toLowerCase() === "false")
88
return false
99

10-
if (v.toLowerCase() === "true")
10+
if (variable.toLowerCase() === "true")
1111
return true
1212

13-
throw new Error(`\"${v}\" used for boolean variable. Expected \"true\" or \"false\"`)
13+
throw new Error(`\"${variable}\" used for boolean variable. Expected \"true\" or \"false\"`)
1414
}
1515

1616
function int(v) {

0 commit comments

Comments
 (0)