Skip to content

Commit 60b90b7

Browse files
authored
Fixed non-embeddable videos being considered deleted (#200)
1 parent 126de62 commit 60b90b7

File tree

11 files changed

+438
-331
lines changed

11 files changed

+438
-331
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Changelog
22

3-
## v2.2.0
3+
## v2.2.1
44

55
<!--Releasenotes start-->
6+
- Fixed a bug where the extension would handle a non-embeddable video as deleted.
7+
- The extension now handles the case where shorts are ignored, but a channel has only uploaded shorts.
8+
- Fixed some minor bugs regarding version compatibility.
9+
<!--Releasenotes end-->
10+
11+
## v2.2.0
12+
613
- Fixed the scrollbar on Chromium browsers not being styled correctly.
714
- Added links to browser add-on stores to the popup.
815
- The shuffle page opened by the popup will now inform you if a shuffle takes a bit longer than expected.
@@ -11,7 +18,6 @@
1118
- Fixed a bug where the extension's service worker would get shut down while video data was being fetched from the YouTube API, leading to a 'Receiving end does not exist' error.
1219
- Fixed a bug where the shuffling page opened by the popup would sometimes incorrectly show an error message for a brief moment.
1320
- Internal pages such as the changelog page will now use more available space on smaller resolutions.
14-
<!--Releasenotes end-->
1521

1622
## v2.1.0
1723

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ Firefox:
1717
<br>
1818
<a href="https://addons.mozilla.org/en-GB/firefox/addon/random-youtube-video/">
1919
<img src="https://img.shields.io/amo/v/random-youtube-video?label=version"
20-
alt="Firefox version" ></a>
20+
alt="Firefox version"></a>
2121
<a href="https://addons.mozilla.org/en-GB/firefox/addon/random-youtube-video/">
2222
<img src="https://img.shields.io/amo/rating/random-youtube-video?label=rating"
23-
alt="Firefox rating" ></a>
23+
alt="Firefox rating"></a>
2424
<a href="https://addons.mozilla.org/en-GB/firefox/addon/random-youtube-video/">
2525
<img alt="Mozilla Add-on" src="https://img.shields.io/amo/users/random-youtube-video?label=users"
26-
alt="Firefox users" ></a>
26+
alt="Firefox users"></a>
2727
<br>
2828
<br>
29-
<img alt="GitHub Workflow Status - Tests" src="https://img.shields.io/github/actions/workflow/status/NikkelM/Random-YouTube-Video/test.yml?branch=main&label=tests">
29+
<a href='https://github.com/NikkelM/Random-YouTube-Video/actions?query=branch%3Amain'>
30+
<img src="https://img.shields.io/github/actions/workflow/status/NikkelM/Random-YouTube-Video/test.yml?branch=main&label=tests"
31+
alt="GitHub Workflow Status - Tests"></a>
3032
<a href='https://coveralls.io/github/NikkelM/Random-YouTube-Video?branch=main'>
3133
<img src='https://coveralls.io/repos/github/NikkelM/Random-YouTube-Video/badge.svg?branch=main'
32-
alt='Coverage Status' /></a>
34+
alt='Coverage Status'></a>
3335
<br>
3436
<a href="https://github.com/NikkelM/Random-YouTube-Video/tree/main/CHANGELOG.md">
3537
<img src="https://img.shields.io/badge/view-changelog-blue"

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "random-youtube-video",
3-
"version": "2.1.0",
3+
"version": "2.2.1",
44
"description": "Play a random video uploaded on the current YouTube channel.",
55
"scripts": {
66
"dev": "concurrently \"npm run dev:chromium\" \"npm run dev:firefox\"",

src/background.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
138138
// Updates (overwriting videos) a playlist in Firebase
139139
case "overwritePlaylistInfoInDB":
140140
updatePlaylistInfoInDB('uploadsPlaylists/' + request.data.key, request.data.val, true).then(sendResponse);
141+
break;
142+
// Before v1.0.0 the videos were stored in an array without upload times, so they need to all be refetched
143+
case 'updateDBPlaylistToV1.0.0':
144+
updateDBPlaylistToV1_0_0('uploadsPlaylists/' + request.data.key).then(sendResponse);
141145
break;
142146
// Gets an API key depending on user settings
143147
case "getAPIKey":
@@ -169,7 +173,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
169173

170174
// ---------- Firebase ----------
171175
import { initializeApp } from 'firebase/app';
172-
import { getDatabase, ref, child, update, get } from 'firebase/database';
176+
import { getDatabase, ref, child, update, get, remove } from 'firebase/database';
173177

174178
const firebaseConfig = {
175179
apiKey: "AIzaSyA6d7Ahi7fMB4Ey8xXM8f9C9Iya97IGs-c",
@@ -192,7 +196,7 @@ async function updatePlaylistInfoInDB(playlistId, playlistInfo, overwriteVideos)
192196
} else {
193197
console.log("Updating playlistInfo in the database...");
194198
// Contains all properties except the videos
195-
const playlistInfoWithoutVideos = Object.fromEntries(Object.entries(playlistInfo).filter(([key, value]) => key !== "videos"));
199+
const playlistInfoWithoutVideos = Object.fromEntries(Object.entries(playlistInfo).filter(([key, value]) => (key !== "videos")));
196200

197201
// Upload the 'metadata'
198202
update(ref(db, playlistId), playlistInfoWithoutVideos);
@@ -204,6 +208,13 @@ async function updatePlaylistInfoInDB(playlistId, playlistInfo, overwriteVideos)
204208
return "PlaylistInfo was sent to database.";
205209
}
206210

211+
async function updateDBPlaylistToV1_0_0(playlistId) {
212+
// Remove all videos from the database
213+
remove(ref(db, playlistId + '/videos'));
214+
215+
return "Videos were removed from the database playlist.";
216+
}
217+
207218
// Prefers to get cached data instead of sending a request to the database
208219
async function readDataOnce(key) {
209220
console.log(`Reading data for key ${key} from database...`);

src/html/popup/popupUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export async function updateFYIDiv(domElements) {
115115
// ----- FYI: Number of shuffled videos text -----
116116
// Use toLocaleString() to add commas/periods to large numbers
117117
const numShuffledVideosTotal = configSync.numShuffledVideosTotal.toLocaleString();
118-
domElements.numberOfShuffledVideosText.innerText = `You have shuffled ${numShuffledVideosTotal} video${(configSync.numShuffledVideosTotal !== 1) ? "s" : ""} until now.`;
118+
domElements.numberOfShuffledVideosText.innerText = `You have shuffled ${numShuffledVideosTotal} time${(configSync.numShuffledVideosTotal !== 1) ? "s" : ""} until now.`;
119119

120120
// ----- Daily quota notice -----
121121
await getUserQuotaRemainingToday();

0 commit comments

Comments
 (0)