aboutsummaryrefslogtreecommitdiff
path: root/index.js
blob: dbfbc7fce5b70b10e8e863c6011562a1c206a11c (plain) (blame)
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
const { app, BrowserWindow, session } = require('electron')
function createWindow() {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
        fullscreen: true,
        autoHideMenuBar: true
    })

    win.loadURL('https://youtube.com/tv');
}

function fetchCookie(){
    session.defaultSession.cookies.get({
        url: 'https://youtube.com/tv'
    });
}

function cookieDump(cookies) {
    var buffer = '['
    for (let cookie of cookies) {
        console.log(cookie)
        buffer += JSON.stringify(cookie)
        buffer += ","
    }
    buffer = buffer.slice(0, -1) + "]"
    fs.writeFile('cookies.json', buffer, function (err) {
        if (err) return console.log(err);
        console.log('Wrote cookies to file');
    });
}

app.whenReady().then(() => {
    console.log("Started YouTube TV Client 2.0");
    createWindow();

    fetchCookie();

    session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
        details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (Linux; Tizen 2.3) AppleWebKit/538.1 (KHTML, like Gecko)Version/2.3 TV Safari/538.1';
        callback({ cancel: false, requestHeaders: details.requestHeaders });
      });  

    app.on('activate', function () {
        if (BrowserWindow.getAllWindows().length === 0) createWindow();
    });

  });


app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') app.quit();
    fetchCookie()
        .then((cookies) => {
            cookieDump(cookies);
            console.log("Wrote Cookies");
        }).catch((error) => {
            console.log(error);
    });
    
});