Skip to content

Commit

Permalink
added the ability to remove videos from watch history
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldDominik893 committed Sep 22, 2024
1 parent 572ba79 commit 47303e2
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 27 deletions.
8 changes: 4 additions & 4 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
// $dbname = "users";

// Invidious
$InvCServer = "https://invidious.protokolla.fi"; // The Invidious instance that will be used to fetch comments
$InvVIServer = "https://invidious.protokolla.fi"; // The Invidious instance that will be used to fetch video information
$InvTServer = "https://invidious.protokolla.fi"; // The Invidious instance that will be used to fetch trending videos for the home page
$InvSServer = "https://invidious.protokolla.fi"; // The Invidious instance that will be used to search for content
$InvCServer = "https://invidious.perennialte.ch"; // The Invidious instance that will be used to fetch comments
$InvVIServer = "https://invidious.nerdvpn.de"; // The Invidious instance that will be used to fetch video information
$InvTServer = "https://invidious.perennialte.ch"; // The Invidious instance that will be used to fetch trending videos for the home page
$InvSServer = "https://invidious.perennialte.ch"; // The Invidious instance that will be used to search for content

// Admin and Defaults
$defaultRegion = "GB"; // If the user is logged out or doesn't have a region set this will be the default, (put any 2 digit country code)
Expand Down
95 changes: 74 additions & 21 deletions history.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,46 @@
die("Connection failed: " . $conn->connect_error);
}


if ($_POST['remove-vid'] && $_POST['timestamp']) {
$videoIdToRemove = $_POST['remove-vid'];
$timestampToRemove = $_POST['timestamp'];

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$stmt = $conn->prepare("SELECT * FROM login WHERE username = ?");
$stmt->bind_param("s", $_SESSION['logged_in_user']);
$stmt->execute();
$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
$watchHistory = json_decode($row['watch_history'], true);

// Filter out the video with matching video_id and timestamp
$watchHistory = array_filter($watchHistory, function($item) use ($videoIdToRemove, $timestampToRemove) {
return $item['video_id'] !== $videoIdToRemove || $item['timestamp'] !== $timestampToRemove;
});

// Reindex array
$watchHistory = array_values($watchHistory);

$updatedWatchHistory = json_encode($watchHistory);

$updateStmt = $conn->prepare("UPDATE login SET watch_history = ? WHERE username = ?");
$updateStmt->bind_param("ss", $updatedWatchHistory, $_SESSION['logged_in_user']);
$updateStmt->execute();

$updateStmt->close();
}


}



$stmt = $conn->prepare("SELECT watch_history FROM login WHERE username = ?");
$stmt->bind_param("s", $_SESSION['logged_in_user']);
$stmt->execute();
Expand Down Expand Up @@ -157,27 +197,40 @@


if (count($groupedWatchHistory) > 0) {
foreach ($groupedWatchHistory as $date => $videos) { ?>
<h3><?php echo htmlspecialchars($date); ?></h3>
<?php foreach ($videos as $item) {
$title = htmlspecialchars($item['title']);
$author = htmlspecialchars($item['author']);
$videoId = htmlspecialchars($item['video_id']);
$time = htmlspecialchars($item['time']);
echo <<<HTML
<a class="awhite" href="/watch/?v={$videoId}">
<div class="video-tile w3-animate-left">
<div class="videoDiv">
<img src="http://i.ytimg.com/vi/{$videoId}/mqdefault.jpg" height="144px">
</div>
<div class="videoInfo">
<div class="videoTitle"><b>{$title}</b><br>{$author} <div style="float: right;">{$time}</div></div>
</div>
</div>
</a>
HTML;
} ?>
<?php } } ?>
foreach ($groupedWatchHistory as $date => $videos) { ?>
<h3><?php echo htmlspecialchars($date); ?></h3>
<?php foreach ($videos as $item) {
$title = htmlspecialchars($item['title']);
$author = htmlspecialchars($item['author']);
$videoId = htmlspecialchars($item['video_id']);
$time = htmlspecialchars($item['time']);
$timestamp = htmlspecialchars($item['timestamp']); // Assume 'timestamp' exists in the watch history
echo <<<HTML
<a class="awhite" href="/watch/?v={$videoId}">
<div class="video-tile w3-animate-left">
<div class="videoDiv">
<img src="http://i.ytimg.com/vi/{$videoId}/mqdefault.jpg" height="144px">
<div class="button-on-vid">
<form method="POST" action="" style="display:inline;">
<input type="hidden" name="remove-vid" value="{$videoId}">
<input type="hidden" name="timestamp" value="{$timestamp}">
<button type="submit" class="remove-button"><span class="material-symbols-outlined">delete</span></button>
</form></div>
</div>
<div class="videoInfo">
<div class="videoTitle">
<b>{$title}</b><br>{$author} <div style="float: right;">{$time}</div>
</div>
</div>
</div>
</a>
HTML;
} ?>
<?php }
} ?>



<?php } else { ?>
<h4 style="text-align: center;">You are not logged in.</h4>
Expand Down
26 changes: 26 additions & 0 deletions styles/homeblue.css
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,32 @@ transition: 0.3s
padding-right: 4px;
border-radius: 3px;
}

.button-on-vid {
position: absolute;
top: 4px;
right: 4px;
}

.remove-button {
color: white;
padding: 2px;
padding-bottom: 0;
height: 28px;
background-color: rgb(252, 55, 55);
transition: transform 0.2s;
transition: 0.3s;
margin-left: 3px;
border: none;
border-radius: 5px;
}

.remove-button:hover {
background-color: rgb(247, 129, 129);
transition: transform 0.2s;
transition: 0.3s;
}

img {
border-radius: 4px
}
Expand Down
55 changes: 53 additions & 2 deletions styles/homeultra-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,13 @@ font-variation-settings:
.footer {
width: 100%;
padding: 10px;
background: linear-gradient(135deg, #FFA50033, #80008033);
background: linear-gradient(135deg, #ffa5000a, #8000800a);
border-radius: 8px;
border: 2px dashed transparent;
border-image: linear-gradient(135deg, #FFA50033, #80008033) 1;
}


.timestamp {
position: absolute;
margin-top: -23px;
Expand All @@ -285,6 +289,32 @@ font-variation-settings:
padding-right: 4px;
border-radius: 3px;
}

.button-on-vid {
position: absolute;
top: 4px;
right: 4px;
}

.remove-button {
color: white;
padding: 2px;
padding-bottom: 0;
height: 28px;
background-color: rgb(252, 55, 55);
transition: transform 0.2s;
transition: 0.3s;
margin-left: 3px;
border: none;
border-radius: 5px;
}

.remove-button:hover {
background-color: rgb(247, 129, 129);
transition: transform 0.2s;
transition: 0.3s;
}

img {
border-radius: 5px
}
Expand All @@ -298,7 +328,20 @@ img {
text-align: left;
display: flex;
margin: auto;
}
}

.epicdiv-noflex {
width: 100%;
background: #141414;
border: 1px solid rgb(31, 31, 31);
max-width: 416px;
border-radius: 4px;
padding: 10px;
}

.epicdiv-noflex h3 {
margin-top: 0px;
}

.epicdiv h4, .epicdiv h3 {
margin-top: 0px;
Expand All @@ -315,4 +358,12 @@ img {
.trending-cat-btn-selected, .trending-cat-btn-selected:hover {
background-color: rgb(226, 226, 226);
color: #000000;
}

input[type=search].input-field {
margin-bottom: -32px;
background-color: rgb(27, 27, 27);
border: none;
border-radius: 6px;
height: 34px;
}

0 comments on commit 47303e2

Please sign in to comment.