Skip to content

Commit

Permalink
Merge pull request #1723 from u7630748/feature/downloadFavourite
Browse files Browse the repository at this point in the history
Feature Request (#1091) - Auto-Download Favorite Tracks
  • Loading branch information
nukeop authored Oct 16, 2024
2 parents 0697afc + c7ed70c commit 9c137f6
Show file tree
Hide file tree
Showing 48 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/app/app/actions/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const addToDownloads = createStandardAction(DownloadActionTypes.ADD_TO_DO
};

downloads = [...downloads, newDownload];
store.set('downloads', downloads);

return {
payload: { downloads, track: clonedTrack.uuid }
Expand Down
11 changes: 11 additions & 0 deletions packages/app/app/actions/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { areTracksEqualByName, getTrackItem } from '@nuclear/ui';

import { safeAddUuid } from './helpers';
import { createStandardAction } from 'typesafe-actions';
import { addToDownloads } from './downloads';
import StreamProviderPlugin from '@nuclear/core/src/plugins/streamProvider';

export const READ_FAVORITES = 'READ_FAVORITES';
export const ADD_FAVORITE_TRACK = 'ADD_FAVORITE_TRACK';
Expand Down Expand Up @@ -32,6 +34,15 @@ export function addFavoriteTrack(track) {
favorites.tracks = [...filteredTracks, omit(clonedTrack, 'streams')];

store.set('favorites', favorites);

const settings = store.get('settings');
const autoDownloadFavourites = settings.autoDownloadFavourites;

if (autoDownloadFavourites) {
const streamProviders: StreamProviderPlugin[] = store.get('StreamProvider') || [];

addToDownloads(streamProviders, track);
}

return {
type: ADD_FAVORITE_TRACK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { buildStoreState } from '../../../test/storeBuilders';
import { AnyProps, configureMockStore, setupI18Next, TestRouterProvider, TestStoreProvider, uuidRegex } from '../../../test/testUtils';
import MainContentContainer from '../MainContentContainer';
import PlayerBarContainer from '../PlayerBarContainer';
import { addFavoriteTrack } from '../../actions/favorites';
import { DownloadStatus } from '@nuclear/ui/lib/types';
import { store as electronStore } from '@nuclear/core';

const updateStore = (key: string, value: object) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -211,6 +214,55 @@ describe('Favorite tracks view container', () => {
}));
});

it('should automatically add a track to downloads when favorited and auto-download is enabled', () => {
electronStore.set('settings', { autoDownloadFavourites: true });

const testTrack = {
artist: 'Test Artist',
name: 'Test Track',
source: 'TestSource',
duration: 300
};

addFavoriteTrack(testTrack);

const downloads = electronStore.get('downloads');
expect(downloads).toContainEqual(
expect.objectContaining({
track: expect.objectContaining({
artist: 'Test Artist',
name: 'Test Track'
}),
status: DownloadStatus.WAITING
})
);
});

it('should not add a track to downloads when favorited if auto-download is disabled', async () => {
electronStore.clear();
electronStore.set('settings', { autoDownloadFavourites: false });

const testTrack = {
artist: 'Test Artist',
name: 'Test Track',
source: 'TestSource',
duration: 300
};

addFavoriteTrack(testTrack);

const downloads = electronStore.get('downloads');
expect(downloads).not.toContainEqual(
expect.objectContaining({
track: expect.objectContaining({
artist: 'Test Artist',
name: 'Test Track'
})
})
);
});


it.each([
{ query: 'test track 1', by: 'track title' },
{ query: 'test artist 1', by: 'artist' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,34 @@ exports[`Settings view container should render settings 1`] = `
/>
</div>
</div>
<div
class="settings_item boolean"
>
<span
class="settings_item_text"
>
<label
class="settings_item_name"
>
Auto download favorite track
</label>
</span>
<div
class="spacer"
/>
<div
class="ui fitted toggle checkbox"
>
<input
class="hidden"
readonly=""
tabindex="0"
type="radio"
value=""
/>
<label />
</div>
</div>
</div>
</div>
<div
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ export const settingsConfig: Array<Setting> = [
default: 1,
min: 1
},
{
name: 'autoDownloadFavourites',
category: 'downloads',
type: SettingType.BOOLEAN,
prettyName: 'auto-download-favourites',
default: false
},
{
name: 'devtools',
category: 'developer',
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ar_SA.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "جنون المذياع التلقائي",
"autoradio-craziness-description": "سيختار المذياع التلقائي الأغاني التي لا تشبه الأغاني الموجودة فعلًا في قائمة الانتظار كلما كانت أكثر جنونًا",
"autoradio-description": "إضافة اغنية مشابهة تلقائياً عند انتهاء قائمة الانتظار",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "تاريخ الاستماع",
"listening-history-description": "سجل المسارات التي تستمع إليها، لا Last.fm. يتم تخزين السجل دون اتصال.",
"compact-menu-bar": "استخدام النمط المدمج لشريط القائمة",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/be_BY.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Вар'яцкае Аўтарадыё",
"autoradio-craziness-description": "Аўтарадыё абярэ песні, якія менш падобныя на тыя, што ўжо ёсць у чарзе, тым больш шалёна гэта будзе",
"autoradio-description": "Дадаваць падобныя трэкі аўтаматычна, калі чарга заканчваецца",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Гісторыя праслухоўвання",
"listening-history-description": "Рэгіструйце трэкі, якія вы слухаеце, напрыклад Last.fm. Гісторыя захоўваецца ў аўтаномным рэжыме.",
"compact-menu-bar": "Выкарыстоўваць кампактны стыль для радкоў меню",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/bn_BD.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "অটোরেডিওর পাগলামি",
"autoradio-craziness-description": "অটোরেডিও সেসব গান সিলেক্ট করবে যেগুলো ইতমধ্যে সারিতে থাকা গানের সাথে পার্থক্যপূর্ণ।",
"autoradio-description": "সারি শেষ হয়ে গেলে স্বয়ংক্রিয়ভাবে সামঞ্জস্যপূর্ণ ট্র্যাক যুক্ত কর",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Listening history",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "কম্প্যাক্ট স্টাইল ব্যবহার করুন মেনু বারের জন্য",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Bláznivost autorádia",
"autoradio-craziness-description": "Čím bláznivější, tím spíše autorádio vybere skladby, které se méně podobají těm, které jsou již ve frontě",
"autoradio-description": "Přidat automaticky podobné skladby po dokončení přehrávání fronty",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Historie přehrávání",
"listening-history-description": "Zaznamenávejte skladby, které posloucháte, a la Last.fm. Historie je ukládána offline.",
"compact-menu-bar": "Použít kompaktní styl pro lištu menu",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Autoradio-Verrücktheit",
"autoradio-craziness-description": "Autoradio wählt Lieder, aus die anders sind, als die Lieder, die bereits in der Warteschlange sind",
"autoradio-description": "Fügt ähnliche Lieder automatisch hinzu, falls die Warteschlange beendet wird",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Hörgeschichte",
"listening-history-description": "Protokollieren Sie die Titel, die Sie bei Last.fm hören. Der Verlauf wird offline gespeichert.",
"compact-menu-bar": "Kompakten Stil für Menüleiste verwenden",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/dk.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Autoradio vanvittighed",
"autoradio-craziness-description": "Autoradio vælger sange som er mindre som de sange der allerede er i køen jo mere skør den er.",
"autoradio-description": "Tilføj automatisk lignende sange når køen slutter.",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Listening history",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "Benyt kompakt stil til menu",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
"autoradio-craziness": "Autoradio craziness",
"autoradio-craziness-description": "Autoradio will select songs that are less similar to the ones already in the queue the crazier it is",
"autoradio-description": "Add similar tracks automatically when the queue is ending",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Listening history",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "Use compact style for menu bar",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Nivel de locura de Autoradio",
"autoradio-craziness-description": "Autoradio seleccionará canciones diferentes a aquellas en la cola mientras más loco esté",
"autoradio-description": "Añadir pistas similares automáticamente cuando la cola esté terminando",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Historial de reproducción",
"listening-history-description": "Registre las canciones que escucha, a la Last.fm. El historial se almacena sin conexión.",
"compact-menu-bar": "Usar el estilo compacto para la barra de menú",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/fa_IR.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Autoradio craziness",
"autoradio-craziness-description": "Autoradio will select songs that are less similar to the ones already in the queue the crazier it is",
"autoradio-description": "Add similar tracks automatically when the queue is ending",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Listening history",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "Use compact style for menu bar",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Autoradio hulluus",
"autoradio-craziness-description": "Autoradio valitsee kappaleet jotka ovat vähemmän samanlaisia kuin ne jotka on jo jonossa",
"autoradio-description": "Lisää samankaltaisia kappaleita automaattisesti kun jono on loppumassa",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Kuunteluhistoria",
"listening-history-description": "Ylöskirjaa raidat joita kuuntelet, tyyliin Last.fm. Historiasi taltioidaan yhteydettömässä tilassa.",
"compact-menu-bar": "Käytä kompaktia valikon palkkia",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Niveau de folie de l'autoradio",
"autoradio-craziness-description": "Plus le niveau de folie de l'autoradio est élevé, moins les morceaux choisis seront cohérent avec ceux déjà présent dans la file d'attente",
"autoradio-description": "Ajouter automatiquement des morceaux similaires lorsque la file d'attente se termine",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Historique d'écoute",
"listening-history-description": "Enregistrez les pistes que vous écoutez, un Last.fm. L'historique est stocké hors ligne.",
"compact-menu-bar": "Utiliser le style compacte pour la barre de menu",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/gr.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Τρέλα του ράδιο αυτοκινήτου",
"autoradio-craziness-description": "Αυξάνοντας το επίπεδο διαφοροποίησης, μειώνετε την ομοιότητα των τραγουδιών με αυτά της ουράς αναπαραγωγής",
"autoradio-description": "Προσθέστε παρόμοια τραγούδια μόλις η τρέχουσα λίστα αναπαραγωγής φτάσει στο τέλος της",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Listening history",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "Χρησιμοποιήστε το συμπαγές μενού",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/he_IL.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "טרוף רדיו אוטומטי",
"autoradio-craziness-description": "הרדיו האוטומטי יבחר שירים שפחות דומים לאלו שכבר נמצאים בתור ככל שזה מטורף יותר",
"autoradio-description": "הוסף רצועות דומות באופן אוטומטי כאשר התור מסתיים",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "היסטוריית האזנה",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "שימוש בסגנון חסכוני לסרגל התפריט",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "ऑटोरेडियो पागलपन",
"autoradio-craziness-description": "ऑटोरेडियो उन गानों का चयन करेगा जो पहले से कतार में लगे गानों से कम मिलते-जुलते हैं",
"autoradio-description": "कतार समाप्त होने पर स्वचालित रूप से समान ट्रैक जोड़ें",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Listening history",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "मेनू बार के लिए कॉम्पैक्ट शैली का प्रयोग करें",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Autoradio ludilo",
"autoradio-craziness-description": "Autoradio će odabrati pjesme koje su manje slične onima koje su već u redu čekanja što je luđe",
"autoradio-description": "Automatski dodaj slične pjesme kad se red čekanja završava",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Povijest slušanja",
"listening-history-description": "Zabilježite pjesme koje slušate na Last.fm-u. Povijest se pohranjuje na vašem uređaju.",
"compact-menu-bar": "Koristi kompaktni stil za traku izbornika",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/hu_HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Autómata rádió őrültsége",
"autoradio-craziness-description": "Az autómata rádió olyan zenéket fog kiválasztani, amlyek annál kevésbé hasonlítanak az várólistán levőkre, ammenyivel őrültebb",
"autoradio-description": "Hasonló számok autómatikus hozzáadása, amikor a várólista a végéhez ér",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Hallgatási előzmények",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "Use compact style for menu bar",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Autoradio craziness",
"autoradio-craziness-description": "Autoradio akan memilih lagu yang kurang mirip dengan yang sudah masuk ke daftar antrian",
"autoradio-description": "Tambahkan lagu yang mirip secara otomatis di akhir daftar antrian",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Riwayat mendengarkan",
"listening-history-description": "Log trek yang anda dengarkan ke, Last.fm. Riwayat akan disimpan secara luring.",
"compact-menu-bar": "Gunakan gaya ringkas untuk papan menu",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/is.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Brjálæði sjálfvirkt útvarps",
"autoradio-craziness-description": "Sjálfvirka útvarpið velur lög sem eru minna lík en þau sem eru núþegar í biðröð því brjálaðar verður það",
"autoradio-description": "Sjálfkrafa bætir við svipuðum lögum þegar biðröð er að ljúka",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Listening history",
"listening-history-description": "Log the tracks you listen to, a la Last.fm. The history is stored offline.",
"compact-menu-bar": "Nota þéttan stíl fyrir aðalrimil",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Livello di follia della radio automatica",
"autoradio-craziness-description": "La radio automatica, più folle è, più selezionerà canzoni meno simili a quelle già nella coda",
"autoradio-description": "Aggiungere automaticamente tracce simili quando la coda termina",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Cronologia di ascolto",
"listening-history-description": "Tieni traccia dei brani ascoltati, come avviene su Last.fm. La cronologia viene memorizzata offline.",
"compact-menu-bar": "Usa lo stile compatto per la barra dei menù",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "ラジオのヤバさ",
"autoradio-craziness-description": "ラジオがヤバいほど既に再生キューにある曲と似ていない曲を選びます",
"autoradio-description": "キューにある曲と似たような曲を自動的にキューに追加します",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "再生履歴",
"listening-history-description": "Last.fm 風に、聴いた曲を記録。この履歴はオフラインで保存されます。",
"compact-menu-bar": "メニューバーを小型に表示",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "무작위 자동 재생",
"autoradio-craziness-description": "얼마나 재생 목록과 비슷하지 않은 음악을 재생할지 조절할 수 있습니다.",
"autoradio-description": "재생 목록이 끝나면 자동으로 비슷한 음악 연속 재생",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "재생 기록",
"listening-history-description": "예를 들어 Last.fm 처럼 당신이 재생한 트랙을 기록합니다. 기록은 오프라인으로 저장됩니다.",
"compact-menu-bar": "축소된 메뉴 바 사용",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ku_KMR.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"autoradio-craziness": "Dînbûna Autoradio",
"autoradio-craziness-description": "Autoradio wê stranên ku kêmtir mîna yên ku di rêza de ne hilbijêre",
"autoradio-description": "Dema ku rêz diqede, stranên bi vî rengî bixweber tevlî bike",
"auto-download-favourites": "Auto download favorite track",
"listening-history": "Dîroka Guhdarkirinê",
"listening-history-description": "Stranên ku tu guhdar dikî tomar bike bo Last.fm. dîrok derhêl tê tomarkirin.",
"compact-menu-bar": "Ji bo darika kulînê şêwaza pêkhatî bi kar bîne",
Expand Down
Loading

0 comments on commit 9c137f6

Please sign in to comment.