Browse Source

feat: option for geniurl api token

Sven 1 year ago
parent
commit
9a4937cb55
6 changed files with 54 additions and 19 deletions
  1. 30 16
      assets/translations/README.md
  2. 2 0
      assets/translations/en_US.json
  3. 3 2
      src/config.ts
  4. 9 0
      src/features/index.ts
  5. 8 1
      src/features/lyrics.ts
  6. 2 0
      src/types.ts

+ 30 - 16
assets/translations/README.md

@@ -6,15 +6,15 @@ To submit or edit a translation, please follow [this guide](../../contributing.m
 ### Translation progress:
 | Locale | Translated keys | Based on |
 | ------ | --------------- | :------: |
-| [`en_US`](./en_US.json) | 151 (default locale) |  |
-| [`de_DE`](./de_DE.json) | 🚫 `123/151` (81.5%) | ─ |
-| [`en_UK`](./en_UK.json) | ✅ `151/151` (100.0%) | `en_US` |
-| [`es_ES`](./es_ES.json) | 🚫 `123/151` (81.5%) | ─ |
-| [`fr_FR`](./fr_FR.json) | 🚫 `123/151` (81.5%) | ─ |
-| [`hi_IN`](./hi_IN.json) | 🚫 `123/151` (81.5%) | ─ |
-| [`ja_JA`](./ja_JA.json) | 🚫 `123/151` (81.5%) | ─ |
-| [`pt_BR`](./pt_BR.json) | 🚫 `123/151` (81.5%) | ─ |
-| [`zh_CN`](./zh_CN.json) | 🚫 `123/151` (81.5%) | ─ |
+| [`en_US`](./en_US.json) | 153 (default locale) |  |
+| [`de_DE`](./de_DE.json) | 🚫 `123/153` (80.4%) | ─ |
+| [`en_UK`](./en_UK.json) | ✅ `153/153` (100.0%) | `en_US` |
+| [`es_ES`](./es_ES.json) | 🚫 `123/153` (80.4%) | ─ |
+| [`fr_FR`](./fr_FR.json) | 🚫 `123/153` (80.4%) | ─ |
+| [`hi_IN`](./hi_IN.json) | 🚫 `123/153` (80.4%) | ─ |
+| [`ja_JA`](./ja_JA.json) | 🚫 `123/153` (80.4%) | ─ |
+| [`pt_BR`](./pt_BR.json) | 🚫 `123/153` (80.4%) | ─ |
+| [`zh_CN`](./zh_CN.json) | 🚫 `123/153` (80.4%) | ─ |
 
 <br>
 
@@ -25,7 +25,7 @@ This means you need to manually check against the base translations for missing
 
 ### Missing keys:
 
-<details><summary><code>de_DE</code> - 28 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>de_DE</code> - 30 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -48,6 +48,8 @@ This means you need to manually check against the base translations for missing
 | `unit_days-n` | `days` |
 | `feature_desc_geniUrlBase` | `Base URL of your geniURL instance, see https://github.com/Sv443/geniURL` |
 | `feature_helptext_geniUrlBase` | `If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.` |
+| `feature_desc_geniUrlToken` | `Auth token for your geniURL instance` |
+| `feature_helptext_geniUrlToken` | `To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance` |
 | `feature_desc_lyricsCacheMaxSize` | `Maximum amount of lyrics to keep in the cache` |
 | `feature_helptext_lyricsCacheMaxSize` | `The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.` |
 | `feature_desc_lyricsCacheTTL` | `Max amount of days to keep a lyrics entry in the cache` |
@@ -60,7 +62,7 @@ This means you need to manually check against the base translations for missing
 
 <br></details>
 
-<details><summary><code>es_ES</code> - 28 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>es_ES</code> - 30 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -83,6 +85,8 @@ This means you need to manually check against the base translations for missing
 | `unit_days-n` | `days` |
 | `feature_desc_geniUrlBase` | `Base URL of your geniURL instance, see https://github.com/Sv443/geniURL` |
 | `feature_helptext_geniUrlBase` | `If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.` |
+| `feature_desc_geniUrlToken` | `Auth token for your geniURL instance` |
+| `feature_helptext_geniUrlToken` | `To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance` |
 | `feature_desc_lyricsCacheMaxSize` | `Maximum amount of lyrics to keep in the cache` |
 | `feature_helptext_lyricsCacheMaxSize` | `The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.` |
 | `feature_desc_lyricsCacheTTL` | `Max amount of days to keep a lyrics entry in the cache` |
@@ -95,7 +99,7 @@ This means you need to manually check against the base translations for missing
 
 <br></details>
 
-<details><summary><code>fr_FR</code> - 28 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>fr_FR</code> - 30 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -118,6 +122,8 @@ This means you need to manually check against the base translations for missing
 | `unit_days-n` | `days` |
 | `feature_desc_geniUrlBase` | `Base URL of your geniURL instance, see https://github.com/Sv443/geniURL` |
 | `feature_helptext_geniUrlBase` | `If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.` |
+| `feature_desc_geniUrlToken` | `Auth token for your geniURL instance` |
+| `feature_helptext_geniUrlToken` | `To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance` |
 | `feature_desc_lyricsCacheMaxSize` | `Maximum amount of lyrics to keep in the cache` |
 | `feature_helptext_lyricsCacheMaxSize` | `The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.` |
 | `feature_desc_lyricsCacheTTL` | `Max amount of days to keep a lyrics entry in the cache` |
@@ -130,7 +136,7 @@ This means you need to manually check against the base translations for missing
 
 <br></details>
 
-<details><summary><code>hi_IN</code> - 28 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>hi_IN</code> - 30 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -153,6 +159,8 @@ This means you need to manually check against the base translations for missing
 | `unit_days-n` | `days` |
 | `feature_desc_geniUrlBase` | `Base URL of your geniURL instance, see https://github.com/Sv443/geniURL` |
 | `feature_helptext_geniUrlBase` | `If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.` |
+| `feature_desc_geniUrlToken` | `Auth token for your geniURL instance` |
+| `feature_helptext_geniUrlToken` | `To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance` |
 | `feature_desc_lyricsCacheMaxSize` | `Maximum amount of lyrics to keep in the cache` |
 | `feature_helptext_lyricsCacheMaxSize` | `The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.` |
 | `feature_desc_lyricsCacheTTL` | `Max amount of days to keep a lyrics entry in the cache` |
@@ -165,7 +173,7 @@ This means you need to manually check against the base translations for missing
 
 <br></details>
 
-<details><summary><code>ja_JA</code> - 28 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>ja_JA</code> - 30 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -188,6 +196,8 @@ This means you need to manually check against the base translations for missing
 | `unit_days-n` | `days` |
 | `feature_desc_geniUrlBase` | `Base URL of your geniURL instance, see https://github.com/Sv443/geniURL` |
 | `feature_helptext_geniUrlBase` | `If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.` |
+| `feature_desc_geniUrlToken` | `Auth token for your geniURL instance` |
+| `feature_helptext_geniUrlToken` | `To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance` |
 | `feature_desc_lyricsCacheMaxSize` | `Maximum amount of lyrics to keep in the cache` |
 | `feature_helptext_lyricsCacheMaxSize` | `The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.` |
 | `feature_desc_lyricsCacheTTL` | `Max amount of days to keep a lyrics entry in the cache` |
@@ -200,7 +210,7 @@ This means you need to manually check against the base translations for missing
 
 <br></details>
 
-<details><summary><code>pt_BR</code> - 28 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>pt_BR</code> - 30 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -223,6 +233,8 @@ This means you need to manually check against the base translations for missing
 | `unit_days-n` | `days` |
 | `feature_desc_geniUrlBase` | `Base URL of your geniURL instance, see https://github.com/Sv443/geniURL` |
 | `feature_helptext_geniUrlBase` | `If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.` |
+| `feature_desc_geniUrlToken` | `Auth token for your geniURL instance` |
+| `feature_helptext_geniUrlToken` | `To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance` |
 | `feature_desc_lyricsCacheMaxSize` | `Maximum amount of lyrics to keep in the cache` |
 | `feature_helptext_lyricsCacheMaxSize` | `The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.` |
 | `feature_desc_lyricsCacheTTL` | `Max amount of days to keep a lyrics entry in the cache` |
@@ -235,7 +247,7 @@ This means you need to manually check against the base translations for missing
 
 <br></details>
 
-<details><summary><code>zh_CN</code> - 28 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>zh_CN</code> - 30 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -258,6 +270,8 @@ This means you need to manually check against the base translations for missing
 | `unit_days-n` | `days` |
 | `feature_desc_geniUrlBase` | `Base URL of your geniURL instance, see https://github.com/Sv443/geniURL` |
 | `feature_helptext_geniUrlBase` | `If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.` |
+| `feature_desc_geniUrlToken` | `Auth token for your geniURL instance` |
+| `feature_helptext_geniUrlToken` | `To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance` |
 | `feature_desc_lyricsCacheMaxSize` | `Maximum amount of lyrics to keep in the cache` |
 | `feature_helptext_lyricsCacheMaxSize` | `The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.` |
 | `feature_desc_lyricsCacheTTL` | `Max amount of days to keep a lyrics entry in the cache` |

+ 2 - 0
assets/translations/en_US.json

@@ -151,6 +151,8 @@
     "feature_desc_geniusLyrics": "Add a button to the media controls of the currently playing song to open its lyrics on genius.com",
     "feature_desc_geniUrlBase": "Base URL of your geniURL instance, see https://github.com/Sv443/geniURL",
     "feature_helptext_geniUrlBase": "If you have your own instance of geniURL running (for example to bypass rate limiting), you can enter its base URL here to use it for the genius.com lyrics button.\nIf you don't know what this is, you can leave this option as is.",
+    "feature_desc_geniUrlToken": "Auth token for your geniURL instance",
+    "feature_helptext_geniUrlToken": "To bypass rate limiting, you can provide an auth token that is also defined in the .env file of your geniURL instance",
     "feature_desc_lyricsCacheMaxSize": "Maximum amount of lyrics to keep in the cache",
     "feature_helptext_lyricsCacheMaxSize": "The lyrics of songs you listen to are stored in a cache to reduce the amount of requests to the lyrics provider.\nThis feature allows you to set the maximum amount of lyrics to keep in the cache.\nWhen the limit is reached, the entry that was used last will be removed to make space for any new ones.",
     "feature_desc_lyricsCacheTTL": "Max amount of days to keep a lyrics entry in the cache",

+ 3 - 2
src/config.ts

@@ -49,15 +49,16 @@ export const migrations: ConfigMigrationsDict = {
     };
   },
   // 4 -> 5
-  5: (oldData: Record<string, unknown>) => {
+  5: (oldData: FeatureConfig) => {
     return {
       ...oldData,
       geniUrlBase: getFeatureDefault("geniUrlBase"),
+      geniUrlToken: getFeatureDefault("geniUrlToken"),
       lyricsCacheMaxSize: getFeatureDefault("lyricsCacheMaxSize"),
       lyricsCacheTTL: getFeatureDefault("lyricsCacheTTL"),
       clearLyricsCache: getFeatureDefault("clearLyricsCache"),
       advancedMode: getFeatureDefault("advancedMode"),
-    };
+    } satisfies FeatureConfig;
   },
 };
 

+ 9 - 0
src/features/index.ts

@@ -265,6 +265,15 @@ export const featInfo = {
     // TODO: to be reworked or removed in the big menu rework
     textAdornment: getAdvancedModeAdornment,
   },
+  geniUrlToken: {
+    type: "text",
+    category: "lyrics",
+    default: "",
+    normalize: (val: string) => val.trim(),
+    advanced: true,
+    // TODO: to be reworked or removed in the big menu rework
+    textAdornment: getAdvancedModeAdornment,
+  },
   lyricsCacheMaxSize: {
     type: "slider",
     category: "lyrics",

+ 8 - 1
src/features/lyrics.ts

@@ -347,7 +347,14 @@ export async function fetchLyricsUrls(artist: string, song: string): Promise<Omi
 
     log(`Requesting URLs from geniURL at '${fetchUrl}'`);
 
-    const fetchRes = await fetchAdvanced(fetchUrl);
+    const { geniUrlToken } = getFeatures();
+    const fetchRes = await fetchAdvanced(fetchUrl, {
+      ...(geniUrlToken ? {
+        headers: {
+          Authorization: `Bearer ${geniUrlToken}`,
+        },
+      } : {}),
+    });
     if(fetchRes.status === 429) {
       const waitSeconds = Number(fetchRes.headers.get("retry-after") ?? geniUrlRatelimitTimeframe);
       alert(tp("lyrics_rate_limited", waitSeconds, waitSeconds));

+ 2 - 0
src/types.ts

@@ -260,6 +260,8 @@ export interface FeatureConfig {
   geniusLyrics: boolean;
   /** Base URL to use for GeniURL */
   geniUrlBase: string;
+  /** Token to use for GeniURL */
+  geniUrlToken: string;
   /** Max size of lyrics cache */
   lyricsCacheMaxSize: number;
   /** Max TTL of lyrics cache entries, in ms */