diff options
-rwxr-xr-x[-rw-r--r--] | .gitignore | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | .idea/NetflixPersonalStats.iml | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | .idea/jsLibraryMappings.xml | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | .idea/misc.xml | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | .idea/modules.xml | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | .idea/vcs.xml | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | .idea/workspace.xml | 61 | ||||
-rwxr-xr-x[-rw-r--r--] | README.md | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | assets/css/main.css | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | assets/js/chart.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | assets/js/jQuery.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | assets/js/main.js | 155 | ||||
-rwxr-xr-x[-rw-r--r--] | assets/php/getJson.php | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | index.html | 2 |
14 files changed, 155 insertions, 70 deletions
diff --git a/.gitignore b/.gitignore index 485dee6..485dee6 100644..100755 --- a/.gitignore +++ b/.gitignore diff --git a/.idea/NetflixPersonalStats.iml b/.idea/NetflixPersonalStats.iml index cce6a37..cce6a37 100644..100755 --- a/.idea/NetflixPersonalStats.iml +++ b/.idea/NetflixPersonalStats.iml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml index 93a1ca9..93a1ca9 100644..100755 --- a/.idea/jsLibraryMappings.xml +++ b/.idea/jsLibraryMappings.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 28a804d..28a804d 100644..100755 --- a/.idea/misc.xml +++ b/.idea/misc.xml diff --git a/.idea/modules.xml b/.idea/modules.xml index 0b5fe66..0b5fe66 100644..100755 --- a/.idea/modules.xml +++ b/.idea/modules.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..35eb1dd 100644..100755 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 37d42c7..020dea4 100644..100755 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,7 @@ <project version="4"> <component name="ChangeListManager"> <list default="true" id="97b3211b-cf0c-4d16-95ab-95e8421b8759" name="Default" comment=""> - <change beforePath="$PROJECT_DIR$/assets/js/main.js" beforeDir="false" afterPath="$PROJECT_DIR$/assets/js/main.js" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/assets/php/getJson.php" beforeDir="false" afterPath="$PROJECT_DIR$/assets/php/getJson.php" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> </list> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="TRACKING_ENABLED" value="true" /> @@ -18,7 +17,7 @@ <entry file="file://$PROJECT_DIR$/index.html"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="253"> - <caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" /> + <caret line="11" selection-start-line="11" selection-end-line="11" /> </state> </provider> </entry> @@ -26,8 +25,8 @@ <file leaf-file-name="main.js" pinned="false" current-in-tab="true"> <entry file="file://$PROJECT_DIR$/assets/js/main.js"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="506"> - <caret line="22" column="37" lean-forward="true" selection-start-line="22" selection-start-column="37" selection-end-line="22" selection-end-column="37" /> + <state relative-caret-position="874"> + <caret line="38" column="21" selection-start-line="38" selection-start-column="21" selection-end-line="38" selection-end-column="21" /> </state> </provider> </entry> @@ -35,7 +34,7 @@ <file leaf-file-name="getJson.php" pinned="false" current-in-tab="false"> <entry file="file://$PROJECT_DIR$/assets/php/getJson.php"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="440"> + <state relative-caret-position="506"> <caret line="22" column="20" selection-start-line="22" selection-start-column="20" selection-end-line="22" selection-end-column="20" /> </state> </provider> @@ -57,8 +56,8 @@ <option value="$PROJECT_DIR$/assets/js/chart.js" /> <option value="$PROJECT_DIR$/assets/js/jQuery.js" /> <option value="$PROJECT_DIR$/index.html" /> - <option value="$PROJECT_DIR$/assets/js/main.js" /> <option value="$PROJECT_DIR$/assets/php/getJson.php" /> + <option value="$PROJECT_DIR$/assets/js/main.js" /> </list> </option> </component> @@ -84,6 +83,7 @@ <foldersAlwaysOnTop value="true" /> </navigator> <panes> + <pane id="Scope" /> <pane id="ProjectPane"> <subPane> <expand> @@ -118,9 +118,8 @@ <select /> </subPane> </pane> - <pane id="PackagesPane" /> <pane id="AndroidView" /> - <pane id="Scope" /> + <pane id="PackagesPane" /> </panes> </component> <component name="PropertiesComponent"> @@ -198,16 +197,16 @@ <option name="presentableId" value="Default" /> <updated>1529337036914</updated> <workItem from="1529337040585" duration="712000" /> - <workItem from="1529337817654" duration="10788000" /> + <workItem from="1529337817654" duration="10867000" /> + <workItem from="1529427246619" duration="3000" /> </task> <servers /> </component> <component name="TimeTrackingManager"> - <option name="totallyTimeSpent" value="11500000" /> + <option name="totallyTimeSpent" value="11582000" /> </component> <component name="ToolWindowManager"> <frame x="1366" y="0" width="2560" height="1440" extended-state="6" /> - <editor active="true" /> <layout> <window_info anchor="right" id="Palette" order="3" /> <window_info anchor="bottom" id="TODO" order="6" /> @@ -250,6 +249,30 @@ <component name="editorHistoryManager"> <entry file="file://$PROJECT_DIR$/index.html"> <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="253"> + <caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" /> + </state> + </provider> + </entry> + <entry file="file://$PROJECT_DIR$/assets/php/getJson.php"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="506"> + <caret line="22" column="20" selection-start-line="22" selection-start-column="20" selection-end-line="22" selection-end-column="20" /> + </state> + </provider> + </entry> + <entry file="file://$PROJECT_DIR$/assets/css/main.css"> + <provider selected="true" editor-type-id="text-editor" /> + </entry> + <entry file="file://$PROJECT_DIR$/assets/js/main.js"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="874"> + <caret line="38" column="21" lean-forward="true" selection-start-line="38" selection-start-column="21" selection-end-line="38" selection-end-column="21" /> + </state> + </provider> + </entry> + <entry file="file://$PROJECT_DIR$/index.html"> + <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="276"> <caret line="12" selection-start-line="12" selection-end-line="12" /> </state> @@ -269,9 +292,6 @@ <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="1228"> <caret line="6197" column="41" lean-forward="true" selection-start-line="6197" selection-start-column="41" selection-end-line="6197" selection-end-column="41" /> - <folding> - <element signature="n#!!doc" expanded="true" /> - </folding> </state> </provider> </entry> @@ -282,30 +302,27 @@ <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="30"> <caret line="2554" column="10" lean-forward="true" selection-start-line="2554" selection-start-column="10" selection-end-line="2554" selection-end-column="10" /> - <folding> - <element signature="n#!!doc" expanded="true" /> - </folding> </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/index.html"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="253"> - <caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" /> + <caret line="11" selection-start-line="11" selection-end-line="11" /> </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/assets/php/getJson.php"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="440"> + <state relative-caret-position="506"> <caret line="22" column="20" selection-start-line="22" selection-start-column="20" selection-end-line="22" selection-end-column="20" /> </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/assets/js/main.js"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="506"> - <caret line="22" column="37" lean-forward="true" selection-start-line="22" selection-start-column="37" selection-end-line="22" selection-end-column="37" /> + <state relative-caret-position="874"> + <caret line="38" column="21" selection-start-line="38" selection-start-column="21" selection-end-line="38" selection-end-column="21" /> </state> </provider> </entry> diff --git a/README.md b/README.md index 927f067..927f067 100644..100755 --- a/README.md +++ b/README.md diff --git a/assets/css/main.css b/assets/css/main.css index e69de29..e69de29 100644..100755 --- a/assets/css/main.css +++ b/assets/css/main.css diff --git a/assets/js/chart.js b/assets/js/chart.js index ba06c40..ba06c40 100644..100755 --- a/assets/js/chart.js +++ b/assets/js/chart.js diff --git a/assets/js/jQuery.js b/assets/js/jQuery.js index bb40eca..bb40eca 100644..100755 --- a/assets/js/jQuery.js +++ b/assets/js/jQuery.js diff --git a/assets/js/main.js b/assets/js/main.js index e7f5dcf..431403b 100644..100755 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,47 +1,112 @@ -$(function () { - const CookieInput = $(".CookieInput"); - let NetflixJson; - - CookieInput.keyup(function (e) { - if (e.keyCode === 13) { - $.ajax({ - url: "assets/php/getJson.php", - data: {"Cookie": CookieInput.val()}, - type: "POST", - }).done(function (answer) { - /** - * Example response: - * bookmark: 0 - * country: "DE" - * date: 1529338765489 - * dateStr: "18.06.18" - * deviceType: 1481 - * duration: 3302 - * episodeTitle: "Folge 13" - * estRating: "50" - * index: 0 - * movieID: 80205354 - * seasonDescriptor: "Teil 1" - * series: 80192098 // => id - * seriesTitle: "Haus des Geldes" - * title: "Teil 1: \"Folge 13\"" - * topNodeId: "80192098" // === id - * videoTitle: "Folge 13" - */ - document.write(answer); - /*NetflixJson = JSON.parse(answer); - console.log(NetflixJson); - let IndividualTitles = []; - NetflixJson.forEach(function(item, key) { - const CurrentTitle = NetflixJson[key].seriesTitle; - if (IndividualTitles.indexOf(CurrentTitle) === -1 && CurrentTitle !== undefined) { - IndividualTitles.push(CurrentTitle); - } - }); - console.log(IndividualTitles);*/ - - }); +const CookieInput = $(".CookieInput"); +let NetflixJson; + +CookieInput.keyup(function (e) { + if (e.keyCode === 13) { + $.ajax({ + url: "assets/php/getJson.php", + data: { + "Cookie": CookieInput.val() + }, + type: "POST", + }).done(function (response) { + AnalyzeData(response); CookieInput.val(""); - } + }); + } +}); + +function AnalyzeData(JsonResponse) { + /** + * @example response of a series: + * bookmark: 0 + * country: "DE" + * date: 1529338765489 + * dateStr: "18.06.18" + * deviceType: 1481 + * duration: 3302 + * episodeTitle: "Folge 13" + * estRating: "50" + * index: 0 + * movieID: 80205354 + * seasonDescriptor: "Teil 1" + * series: 80192098 + * seriesTitle: "Haus des Geldes" + * title: "Teil 1: \"Folge 13\"" + * topNodeId: "80192098" + * videoTitle: "Folge 13" + * + * @example response of a movie: + * bookmark: 7771 + * country: "DE" + * date: 1476477258019 + * dateStr: "14.10.16" + * deviceType: 1193 + * duration: 8160 + * estRating: "30" + * index: 916 + * movieID: 20557937 + * title: "Matrix" + * topNodeId: "20557937" + * videoTitle: "Matrix" + */ + NetflixJson = JSON.parse(JsonResponse); + console.log(NetflixJson); + let IndividualSeries = []; + let IndividualMovies = []; + let AverageWatchTimes = []; + + NetflixJson.forEach(function (item, pageKey) { + item.forEach(function (eachItem, ItemNumber) { + if ("seriesTitle" in eachItem) { // is series + const CurrentTitle = NetflixJson[pageKey][ItemNumber].seriesTitle; + if (IndividualSeries.indexOf(CurrentTitle) === -1 && CurrentTitle !== undefined) { // only if not alreadyy crawled -> individualism + IndividualSeries.push(CurrentTitle); + } + } else { // is movie + const CurrentTitle = NetflixJson[pageKey][ItemNumber].videoTitle; + if (IndividualMovies.indexOf(CurrentTitle) === -1 && CurrentTitle !== undefined) { // only if not alreadyy crawled -> individualism + IndividualMovies.push(CurrentTitle); + } + } + + const DayTimeInSeconds = new Date(NetflixJson[pageKey][ItemNumber].date * 1000); + const DayTimeInHours = DayTimeInSeconds.getHours(); + AverageWatchTimes.push(DayTimeInHours); + }); + }); + + const TotalSeriesWatched = IndividualSeries.length; + + // Calculate watch time occurrence (average times in which the user watches sth.) + let AverageWatchTimeOccurrence = {}; + for (let i = 0; i < AverageWatchTimes.length; i++) { + const Time = AverageWatchTimes[i]; + AverageWatchTimeOccurrence[Time] = AverageWatchTimeOccurrence[Time] ? AverageWatchTimeOccurrence[Time] + 1 : 1; + } + + console.table(IndividualSeries); + console.table(IndividualMovies); + console.table(AverageWatchTimes); + console.table(AverageWatchTimeOccurrence); + + RenderData(AverageWatchTimeOccurrence); +} + +function RenderData(AverageWatchTimeOccurrenceObject) { + const WatchTimeChartElement = document.getElementById("WatchTimeChart").getContext("2d"); + const WatchTimeChart = new Chart(WatchTimeChartElement, { + type: 'line', + data: { + labels: ["12am", "1am", "2am", "3am", "4am", "5am", "6am", "7am", "8am", "9am", "10am", "11am", "12pm", "1pm", "2pm", "3pm", "4pm", "5pm", "6pm", "7pm", "8pm", "9pm", "10pm", "11pm"], + datasets: [{ + label: "Average daytime", + backgroundColor: 'rgb(255, 99, 132)', + borderColor: 'rgb(255, 99, 132)', + data: AverageWatchTimeOccurrenceObject, + }] + }, + + options: {} }); -});
\ No newline at end of file +}
\ No newline at end of file diff --git a/assets/php/getJson.php b/assets/php/getJson.php index b72070a..fbbecac 100644..100755 --- a/assets/php/getJson.php +++ b/assets/php/getJson.php @@ -11,13 +11,14 @@ while ($LastPage === FALSE) { curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_COOKIE, $NetflixCookie); $Result = curl_exec($ch); - //echo $Result; + //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]) > 0) { + if ($LastPage = count(json_decode($Result, TRUE)["viewedItems"]) > 0) { $LastPage = FALSE; - $NetflixJson .= json_encode(json_decode($Result, TRUE)["viewedItems"][0]) . ","; + $NetflixJson .= json_encode(json_decode($Result, TRUE)["viewedItems"]) . ","; } else { $LastPage = TRUE; + $NetflixJson = substr($NetflixJson, 0, -1); } curl_close($ch); diff --git a/index.html b/index.html index c4fcee8..23219c0 100644..100755 --- a/index.html +++ b/index.html @@ -12,6 +12,8 @@ <input class="CookieInput" type="text" placeholder="Type your cookie..."> +<canvas id="WatchTimeChart"></canvas> + <script src="assets/js/jQuery.js"></script> <script src="assets/js/chart.js"></script> <script src="assets/js/main.js"></script> |