aboutsummaryrefslogtreecommitdiff
path: root/assets/php/getData.php
blob: 22f0f26a5abf3f6a9152ed28a05a7e4c527e6a60 (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
<?php
/**
 * Server-side script of the Netflix Stats Generator to get the personal Netflix JSON
 * @author Marvin Borner
 * @copyright Marvin Borner 2018
 */

$cookie = $_POST['cookie'];

if (isset($cookie)) {
    $isLastPage = false;
    $currentPage = 0;
    $result = '[';

    while ($isLastPage === false) {
        $ch = curl_init('https://www.netflix.com/api/shakti/ve8ded8cd/viewingactivity?pg=' . $currentPage . '&pgSize=100');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        $answer = curl_exec($ch);

        if ($isLastPage = (count(json_decode($answer, true)['viewedItems']) > 0)) {
            $isLastPage = false;
            $result .= json_encode(json_decode($answer, true)['viewedItems']) . ',';
        } else {
            $isLastPage = true;
            $result = substr($result, 0, -1);
        }

        curl_close($ch);
        $currentPage++;
    }

    if ($result !== '') {
        print_r($result . ']');
    } else {
        http_response_code(404);
        die();
    }
} else {
    http_response_code(404);
    die();
}