Skip to content

Commit

Permalink
Fixed non-embeddable videos being considered deleted (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Jul 29, 2023
1 parent 126de62 commit 60b90b7
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 331 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Changelog

## v2.2.0
## v2.2.1

<!--Releasenotes start-->
- Fixed a bug where the extension would handle a non-embeddable video as deleted.
- The extension now handles the case where shorts are ignored, but a channel has only uploaded shorts.
- Fixed some minor bugs regarding version compatibility.
<!--Releasenotes end-->

## v2.2.0

- Fixed the scrollbar on Chromium browsers not being styled correctly.
- Added links to browser add-on stores to the popup.
- The shuffle page opened by the popup will now inform you if a shuffle takes a bit longer than expected.
Expand All @@ -11,7 +18,6 @@
- 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.
- Fixed a bug where the shuffling page opened by the popup would sometimes incorrectly show an error message for a brief moment.
- Internal pages such as the changelog page will now use more available space on smaller resolutions.
<!--Releasenotes end-->

## v2.1.0

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ Firefox:
<br>
<a href="https://addons.mozilla.org/en-GB/firefox/addon/random-youtube-video/">
<img src="https://img.shields.io/amo/v/random-youtube-video?label=version"
alt="Firefox version" ></a>
alt="Firefox version"></a>
<a href="https://addons.mozilla.org/en-GB/firefox/addon/random-youtube-video/">
<img src="https://img.shields.io/amo/rating/random-youtube-video?label=rating"
alt="Firefox rating" ></a>
alt="Firefox rating"></a>
<a href="https://addons.mozilla.org/en-GB/firefox/addon/random-youtube-video/">
<img alt="Mozilla Add-on" src="https://img.shields.io/amo/users/random-youtube-video?label=users"
alt="Firefox users" ></a>
alt="Firefox users"></a>
<br>
<br>
<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">
<a href='https://github.com/NikkelM/Random-YouTube-Video/actions?query=branch%3Amain'>
<img src="https://img.shields.io/github/actions/workflow/status/NikkelM/Random-YouTube-Video/test.yml?branch=main&label=tests"
alt="GitHub Workflow Status - Tests"></a>
<a href='https://coveralls.io/github/NikkelM/Random-YouTube-Video?branch=main'>
<img src='https://coveralls.io/repos/github/NikkelM/Random-YouTube-Video/badge.svg?branch=main'
alt='Coverage Status' /></a>
alt='Coverage Status'></a>
<br>
<a href="https://github.com/NikkelM/Random-YouTube-Video/tree/main/CHANGELOG.md">
<img src="https://img.shields.io/badge/view-changelog-blue"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "random-youtube-video",
"version": "2.1.0",
"version": "2.2.1",
"description": "Play a random video uploaded on the current YouTube channel.",
"scripts": {
"dev": "concurrently \"npm run dev:chromium\" \"npm run dev:firefox\"",
Expand Down
15 changes: 13 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// Updates (overwriting videos) a playlist in Firebase
case "overwritePlaylistInfoInDB":
updatePlaylistInfoInDB('uploadsPlaylists/' + request.data.key, request.data.val, true).then(sendResponse);
break;
// Before v1.0.0 the videos were stored in an array without upload times, so they need to all be refetched
case 'updateDBPlaylistToV1.0.0':
updateDBPlaylistToV1_0_0('uploadsPlaylists/' + request.data.key).then(sendResponse);
break;
// Gets an API key depending on user settings
case "getAPIKey":
Expand Down Expand Up @@ -169,7 +173,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {

// ---------- Firebase ----------
import { initializeApp } from 'firebase/app';
import { getDatabase, ref, child, update, get } from 'firebase/database';
import { getDatabase, ref, child, update, get, remove } from 'firebase/database';

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

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

async function updateDBPlaylistToV1_0_0(playlistId) {
// Remove all videos from the database
remove(ref(db, playlistId + '/videos'));

return "Videos were removed from the database playlist.";
}

// Prefers to get cached data instead of sending a request to the database
async function readDataOnce(key) {
console.log(`Reading data for key ${key} from database...`);
Expand Down
2 changes: 1 addition & 1 deletion src/html/popup/popupUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function updateFYIDiv(domElements) {
// ----- FYI: Number of shuffled videos text -----
// Use toLocaleString() to add commas/periods to large numbers
const numShuffledVideosTotal = configSync.numShuffledVideosTotal.toLocaleString();
domElements.numberOfShuffledVideosText.innerText = `You have shuffled ${numShuffledVideosTotal} video${(configSync.numShuffledVideosTotal !== 1) ? "s" : ""} until now.`;
domElements.numberOfShuffledVideosText.innerText = `You have shuffled ${numShuffledVideosTotal} time${(configSync.numShuffledVideosTotal !== 1) ? "s" : ""} until now.`;

// ----- Daily quota notice -----
await getUserQuotaRemainingToday();
Expand Down
Loading

0 comments on commit 60b90b7

Please sign in to comment.