aboutsummaryrefslogtreecommitdiff
path: root/assets/php/getNetflixJson.php
blob: 3a2fbe42a76fdf30f3dbde15a46464368da7aeab (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
<?php
/**
 * Serverside Script of the Netflix Stats Generator to get the personal Netflix JSON
 * @author Marvin Borner
 * @copyright Marvin Borner 2018
 */

$NetflixCookie = $_POST["Cookie"];

$LastPage = false;
$CurPage = 0;
$NetflixJson = "[";

while ($LastPage === false) {
    $ch = curl_init("https://www.netflix.com/api/shakti/7742b8c7/viewingactivity?pg=" . (string) $CurPage . "&pgSize=100");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_COOKIE, $NetflixCookie);
    $Result = curl_exec($ch);
    //print_r((json_decode($Result, TRUE)["viewedItems"]));
    //echo count(json_decode(curl_exec($ch),true)["viewedItems"]);
    if ($LastPage = count(json_decode($Result, true)["viewedItems"]) > 0) {
        $LastPage = false;
        $NetflixJson .= json_encode(json_decode($Result, true)["viewedItems"]) . ",";
    } else {
        $LastPage = true;
        $NetflixJson = substr($NetflixJson, 0, -1);
    }

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

print_r($NetflixJson . "]");