-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_test.js
75 lines (71 loc) · 3.26 KB
/
node_test.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
const process = require( "process" );
const path = require( "path" );
const global_package_path = process.argv[ 0 ].split( "/bin/node" )[ 0 ] + "/lib/node_modules";
const puppeteer = require( path.join( global_package_path , "puppeteer" ) );
//const chrome_cookies = require( path.join( global_package_path , "chrome-cookies-secure" ) );
const JFODB = require( path.join( global_package_path , "jsonfile-obj-db" ) );
const SPOTIFY_USERNAME = false;
const SPOTIFY_PASSWORD = false;
// // First Run
// ( async ()=> {
// const spotify_login_save = new JFODB( "spotify_login_save" );
// spotify_login_save.self[ "spotify_username" ] = SPOTIFY_USERNAME;
// spotify_login_save.self[ "spotify_password" ] = SPOTIFY_PASSWORD;
// const browser = await puppeteer.launch( { headless: true } );
// const page = await browser.newPage();
// await page.setViewport( { width: 1200 , height: 720 } )
// await page.goto( "https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2F" , { waitUntil: "networkidle0" } );
// await page.type( "#login-username" , spotify_login_save.self[ "spotify_username" ] || SPOTIFY_USERNAME );
// await page.type( '#login-password', spotify_login_save.self[ "spotify_password" ] || SPOTIFY_PASSWORD );
// await page.click( "#login-button" );
// await page.waitForNavigation( { waitUntil: "networkidle0" } );
// // for ( let cookie of spotify_login_save.self[ "cookies" ] ) {
// // await page.setCookie( cookie );
// // }
// const local_storage_clone = await page.evaluate( () => {
// return localStorage;
// });
// // const cookies_clone = await page.evaluate( () => {
// // return document.cookie;
// // });
// const cookies_clone = await page.cookies();
// const token_info = await page.evaluate( () => {
// const token_script = document.getElementById( "config" );
// const token_json = token_script.text.trim();
// const token_info = JSON.parse( token_json );
// return token_info;
// });
// await browser.close();
// spotify_login_save.self[ "local_storage" ] = local_storage_clone;
// spotify_login_save.self[ "cookies" ] = cookies_clone;
// spotify_login_save.self[ "token_info" ] = token_info;
// spotify_login_save.save();
// console.log( spotify_login_save.self );
// })();
// Reuse Login Cookies
( async ()=> {
const spotify_login_save = new JFODB( "spotify_login_save" );
const browser = await puppeteer.launch( { headless: true } );
const page = await browser.newPage();
await page.setViewport( { width: 1200 , height: 720 } )
for ( let cookie of spotify_login_save.self[ "cookies" ] ) {
await page.setCookie( cookie );
}
await page.goto( "https://open.spotify.com" , { waitUntil: "networkidle0" } );
const local_storage_clone = await page.evaluate( () => {
return localStorage;
});
const cookies_clone = await page.cookies();
const token_info = await page.evaluate( () => {
const token_script = document.getElementById( "config" );
const token_json = token_script.text.trim();
const token_info = JSON.parse( token_json );
return token_info;
});
await browser.close();
spotify_login_save.self[ "local_storage" ] = local_storage_clone;
spotify_login_save.self[ "cookies" ] = cookies_clone;
spotify_login_save.self[ "token_info" ] = token_info;
spotify_login_save.save();
console.log( spotify_login_save.self );
})();