-
Notifications
You must be signed in to change notification settings - Fork 36
/
netflix.js
170 lines (124 loc) · 4.52 KB
/
netflix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//npm install puppeteer fs @antiadmin/anticaptchaofficial
// update your login credentials
// run with command: "node netflix.js"
//IMPORTANT:
//1. Netflix utilizes Enterprise Recaptcha V3
//2. We use their obfuscated script located at https://codex.nflxext.com/*** CDN.
// We modify it a little to add a function "getMyToken" at the place where they use token from Google.
// In case of script modifcations, you may add this function yourself.
// This function simply returns V3 Enterprise token which we substitute after solving it in Anti Captcha.
//3. Netflix login and password are required to test this script.
//4. Several attempts (about 10 times) should be made to sign in successfully.
const anticaptcha = require("@antiadmin/anticaptchaofficial");
const pup = require("puppeteer");
const fs = require('fs');
//API key for anti-captcha.com
const anticaptchaAPIKey = 'API_KEY_HERE';
//access data
const url = 'https://www.netflix.com/login';
const login = 'your@email.com';
const password = 'password';
let browser = null;
let page = null;
let token = null;
(async () => {
anticaptcha.setAPIKey(anticaptchaAPIKey);
const balance = await anticaptcha.getBalance();
if (balance <= 0) {
console.log('Buy your anticaptcha balance!');
return;
} else {
console.log('API key balance is '+balance+', continuing');
// anticaptcha.shutUp(); //uncomment for silent captcha recognition
}
try {
console.log('opening browser ..');
let options = {
headless: false,
ignoreHTTPSErrors: true,
devtools: true
};
console.log(options);
browser = await pup.launch(options);
console.log('creating new page ..');
page = await browser.newPage();
} catch (e) {
failCallback("could not open browser: "+e);
return false;
}
await page.setRequestInterception(true);
page.on('request', (request) => {
if (request.url().indexOf('none') !== -1 && request.url().indexOf('js') !== -1 && request.url().indexOf('components') !== -1) {
console.log('aborting '+request.url());
request.abort();
} else {
request.continue();
}
});
page.on('response', (response) => {
if (response.url().indexOf('login') !== -1 && response.request().method() === 'POST') {
console.log("\n\n==== captcha check response ====\n\n");
console.log('status: '+response.status());
if (response.status() !== 302) {
failCallback("captcha result not accepted");
} else {
successCallback("successfully passed test");
}
}
});
console.log('solving captcha');
try {
token = await anticaptcha.solveRecaptchaV3Enterprise(url,'6Lf8hrcUAAAAAIpQAFW2VFjtiYnThOjZOA5xvLyR',0.9,'');
} catch (e) {
failCallback("could not solve captcha");
return;
}
console.log('token is ready: '+token);
try {
await page.goto(url, {
waitUntil: "domcontentloaded"
});
} catch (e) {
console.log('err while loading the page: '+e);
}
// await delay(5000);
console.log('adding modifed script');
try {
const path = require('path');
let file = fs.readFileSync(path.resolve('.', '_netflix.js'), 'utf8');
file = file.replace('RECAPTCHA_TOKEN', token);
await page.addScriptTag({ content: file });
} catch (e) {
console.log('failed to insert script: '+e);
}
await delay(3000);
console.log('filling form ..');
const loginInput= await page.$(`#id_userLoginId`)
await loginInput.focus();
await page.type(`#id_userLoginId`,login)
await delay(1000);
const passwordInput= await page.$(`#id_password`)
await passwordInput.focus();
await page.type(`#id_password`,password)
await delay(1000);
console.log('clicking the button');
await Promise.all([
page.click("#appMountPoint > div > div.login-body > div > div > div.hybrid-login-form-main > form > button"),
page.waitForNavigation({ waitUntil: 'networkidle0' }),
]);
})();
function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time)
});
}
function successCallback() {
console.log('Successfully passed: ');
// console.log('closing browser .. ');
// browser.close();
}
function failCallback(code) {
console.log('Failed to pass: '+code);
// console.log('closing browser .. ');
// browser.close();
}