diff --git a/README.md b/README.md index b81562b..f13eda3 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ Additionally, by selecting "Include album data", the following fields will be ad - Label - Copyrights +The last column is always the Playlist URI, the same on every line, after any of the additional fields above. + Note that the more data being exported, the longer the export will take. #### Saved Albums diff --git a/src/components/PlaylistExporter.test.ts b/src/components/PlaylistExporter.test.ts index 7255a88..dc99ab9 100644 --- a/src/components/PlaylistExporter.test.ts +++ b/src/components/PlaylistExporter.test.ts @@ -9,7 +9,7 @@ import { Track } from "../spotify" const baseHeaders = [ "Track URI", "Track Name", "Artist URI(s)", "Artist Name(s)", "Album URI", "Album Name", "Album Artist URI(s)", "Album Artist Name(s)", "Album Release Date", "Album Image URL", "Disc Number", "Track Number", "Track Duration (ms)", - "Track Preview URL", "Explicit", "Popularity", "ISRC", "Added By", "Added At", + "Track Preview URL", "Explicit", "Popularity", "ISRC", "Added By", "Added At", "Playlist URI", ] const playlist = buildPlaylist({ id: 'p1', name: 'Mixtape', tracks: { total: 1 } }) @@ -43,14 +43,23 @@ describe("PlaylistExporter", () => { const csv = await new PlaylistExporter(playlist, config).csvData() - expect(csvHeaders(csv).slice(baseHeaders.length)).toEqual([ + expect(csvHeaders(csv).slice(baseHeaders.length - 1)).toEqual([ "Artist Genres", "Danceability", "Energy", "Key", "Loudness", "Mode", "Speechiness", "Acousticness", "Instrumentalness", "Liveness", "Valence", "Tempo", "Time Signature", "Album Genres", "Label", "Copyrights", + "Playlist URI", ]) }) + test("fills the playlist URI on every line", async () => { + serveTracks(buildTrack({ id: 't1' }), buildTrack({ id: 't2' })) + + const csv = await new PlaylistExporter(playlist, noExtraData).csvData() + + expect(csvRecords(csv).map(record => record["Playlist URI"])).toEqual([playlist.uri, playlist.uri]) + }) + test("quotes every field so commas, quotes and newlines survive", async () => { serveTracks(buildTrack({ id: 't1', name: 'Say "Hi",\nthen leave', artists: [buildArtist({ name: 'A, B' })] })) diff --git a/src/components/PlaylistExporter.tsx b/src/components/PlaylistExporter.tsx index 27e4687..93673af 100644 --- a/src/components/PlaylistExporter.tsx +++ b/src/components/PlaylistExporter.tsx @@ -54,6 +54,12 @@ class TracksCsvFile { }) } + // Adds a column with the same value on every line + addColumn(columnName: string, value: CsvValue) { + this.columnNames.push(columnName) + this.lineTrackData.forEach((lineTrackData) => lineTrackData.push(value)) + } + content(): string { let csvContent = '' @@ -109,6 +115,9 @@ class PlaylistExporter { await tracksCsvFile.addData(new TracksAlbumData(tracks)) } + // Playlist URI goes last so earlier columns keep their positions in existing exports + tracksCsvFile.addColumn(i18n.t("track.playlist_uri"), this.playlist.uri) + return tracksCsvFile.content() } diff --git a/src/components/PlaylistTable.test.tsx b/src/components/PlaylistTable.test.tsx index 561d7e8..2af96aa 100644 --- a/src/components/PlaylistTable.test.tsx +++ b/src/components/PlaylistTable.test.tsx @@ -22,6 +22,7 @@ import liveSavedAlbums from "../test/fixtures/spotify/live/me-albums-limit-50.js vi.mock('@bugsnag/js') const ghostpoetPlaylist = "Ghostpoet – Peanut Butter Blues and Melancholy Jam" +const ghostpoetPlaylistUri = "spotify:playlist:4XOGDpHMrVoH33uJEwHWU5" const ghostpoetFileName = "ghostpoet_–_peanut_butter_blues_and_melancholy_jam.csv" const likedRequests = [ @@ -52,6 +53,7 @@ const crying = { "ISRC": "UK4UP1300002", "Added By": "", "Added At": "2020-07-19T09:24:39Z", + "Playlist URI": "spotify:user:watsonbox:saved", } const ghostpoetTrack = { @@ -67,6 +69,7 @@ const ghostpoetTrack = { "Explicit": "false", "Added By": "spotify:user:watsonbox", "Added At": "2020-11-03T15:19:04Z", + "Playlist URI": ghostpoetPlaylistUri, } const oneTwos = { @@ -111,6 +114,7 @@ const localTrack = (name: string, artist: string, durationMs: number) => ({ "ISRC": "", "Added By": "spotify:user:u8ins5esg43wtxk4h66o5d1nb", "Added At": "2021-02-24T06:12:40Z", + "Playlist URI": ghostpoetPlaylistUri, }) const requestedUrls = () => handlerCalled.mock.calls.map(([url]) => url) diff --git a/src/i18n/locales/ar/translation.json b/src/i18n/locales/ar/translation.json index 11c0e71..3dd5064 100644 --- a/src/i18n/locales/ar/translation.json +++ b/src/i18n/locales/ar/translation.json @@ -83,6 +83,7 @@ "is_playable": "قابل للتشغيل", "added_by": "أضيف بواسطة", "added_at": "أضيف في", + "playlist_uri": "رابط قائمة التشغيل (URI)", "album": { "album_genres": "أنواع الألبوم", "label": "العلامة التجارية", diff --git a/src/i18n/locales/de/translation.json b/src/i18n/locales/de/translation.json index cb28c3a..69cb451 100644 --- a/src/i18n/locales/de/translation.json +++ b/src/i18n/locales/de/translation.json @@ -79,6 +79,7 @@ "is_playable": "Ist abspielbar", "added_by": "Hinzugefügt von", "added_at": "Hinzugefügt am", + "playlist_uri": "Playlist-URI", "album": { "album_genres": "Album-Genres", "label": "Label", diff --git a/src/i18n/locales/el/translation.json b/src/i18n/locales/el/translation.json index 0f0617c..413f1f2 100644 --- a/src/i18n/locales/el/translation.json +++ b/src/i18n/locales/el/translation.json @@ -79,6 +79,7 @@ "is_playable": "Αναπαράγεται", "added_by": "Προστέθηκε από", "added_at": "Προστέθηκε στις", + "playlist_uri": "URI λίστας αναπαραγωγής", "album": { "album_genres": "Είδη άλμπουμ", "label": "Εταιρεία", diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index f6d6a14..f5889d3 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -87,6 +87,7 @@ "is_playable": "Is Playable", "added_by": "Added By", "added_at": "Added At", + "playlist_uri": "Playlist URI", "album": { "album_genres": "Album Genres", "label": "Label", diff --git a/src/i18n/locales/es/translation.json b/src/i18n/locales/es/translation.json index 6d582d9..200b1a7 100644 --- a/src/i18n/locales/es/translation.json +++ b/src/i18n/locales/es/translation.json @@ -79,6 +79,7 @@ "is_playable": "Es reproducible", "added_by": "Añadido por", "added_at": "Añadido en", + "playlist_uri": "URI de la playlist", "album": { "album_genres": "Géneros del álbum", "label": "Sello", diff --git a/src/i18n/locales/fr/translation.json b/src/i18n/locales/fr/translation.json index 398cc0f..c8ab7d5 100644 --- a/src/i18n/locales/fr/translation.json +++ b/src/i18n/locales/fr/translation.json @@ -79,6 +79,7 @@ "is_playable": "Est jouable", "added_by": "Ajouté par", "added_at": "Ajouté le", + "playlist_uri": "URI de la playlist", "album": { "album_genres": "Genres de l'album", "label": "Label", diff --git a/src/i18n/locales/it/translation.json b/src/i18n/locales/it/translation.json index 4fa3a48..13dff8f 100644 --- a/src/i18n/locales/it/translation.json +++ b/src/i18n/locales/it/translation.json @@ -79,6 +79,7 @@ "is_playable": "È riproducibile", "added_by": "Aggiunto da", "added_at": "Aggiunto il", + "playlist_uri": "URI della playlist", "album": { "album_genres": "Generi dell'album", "label": "Etichetta", diff --git a/src/i18n/locales/ja/translation.json b/src/i18n/locales/ja/translation.json index 0a86bea..05823cd 100644 --- a/src/i18n/locales/ja/translation.json +++ b/src/i18n/locales/ja/translation.json @@ -78,6 +78,7 @@ "is_playable": "再生可能", "added_by": "追加者", "added_at": "追加日時", + "playlist_uri": "プレイリストURI", "album": { "album_genres": "アルバムジャンル", "label": "レーベル", diff --git a/src/i18n/locales/nl/translation.json b/src/i18n/locales/nl/translation.json index b30ba77..e600f8e 100644 --- a/src/i18n/locales/nl/translation.json +++ b/src/i18n/locales/nl/translation.json @@ -79,6 +79,7 @@ "is_playable": "Speelbaar", "added_by": "Toegevoegd door", "added_at": "Toegevoegd op", + "playlist_uri": "Afspeellijst-URI", "album": { "album_genres": "Genres van het album", "label": "Label", diff --git a/src/i18n/locales/pt/translation.json b/src/i18n/locales/pt/translation.json index 2cf4b76..c97e4c4 100644 --- a/src/i18n/locales/pt/translation.json +++ b/src/i18n/locales/pt/translation.json @@ -79,6 +79,7 @@ "is_playable": "É reproduzível", "added_by": "Adicionado por", "added_at": "Adicionado em", + "playlist_uri": "URI da playlist", "album": { "album_genres": "Gêneros do álbum", "label": "Gravadora", diff --git a/src/i18n/locales/sv/translation.json b/src/i18n/locales/sv/translation.json index f3d232a..79bcb2a 100644 --- a/src/i18n/locales/sv/translation.json +++ b/src/i18n/locales/sv/translation.json @@ -79,6 +79,7 @@ "is_playable": "Är spelbar", "added_by": "Tillagd av", "added_at": "Tillagd vid", + "playlist_uri": "Spellistans URI", "album": { "album_genres": "Albumets genrer", "label": "Skivbolag", diff --git a/src/i18n/locales/tr/translation.json b/src/i18n/locales/tr/translation.json index 7eb93ba..2313ea5 100644 --- a/src/i18n/locales/tr/translation.json +++ b/src/i18n/locales/tr/translation.json @@ -79,6 +79,7 @@ "is_playable": "Çalınabilir mi?", "added_by": "Ekleyen", "added_at": "Eklenme Tarihi", + "playlist_uri": "Çalma Listesi URI", "album": { "album_genres": "Albüm Türleri", "label": "Plak Şirketi", diff --git a/src/i18n/locales/yue-Hant-HK/translation.json b/src/i18n/locales/yue-Hant-HK/translation.json index 93819cd..86cce1a 100644 --- a/src/i18n/locales/yue-Hant-HK/translation.json +++ b/src/i18n/locales/yue-Hant-HK/translation.json @@ -78,6 +78,7 @@ "is_playable": "播得到", "added_by": "加入者", "added_at": "加入時間", + "playlist_uri": "播放清單 Link", "album": { "album_genres": "專輯曲風", "label": "唱片公司", diff --git a/src/i18n/locales/zh-Hans/translation.json b/src/i18n/locales/zh-Hans/translation.json index d0d4e83..d6a93fe 100644 --- a/src/i18n/locales/zh-Hans/translation.json +++ b/src/i18n/locales/zh-Hans/translation.json @@ -78,6 +78,7 @@ "is_playable": "可播放", "added_by": "添加者", "added_at": "添加时间", + "playlist_uri": "播放列表 URI", "album": { "album_genres": "专辑流派", "label": "唱片公司", diff --git a/src/i18n/locales/zh-Hant/translation.json b/src/i18n/locales/zh-Hant/translation.json index 0c04d04..b183b84 100644 --- a/src/i18n/locales/zh-Hant/translation.json +++ b/src/i18n/locales/zh-Hant/translation.json @@ -78,6 +78,7 @@ "is_playable": "可播放", "added_by": "新增者", "added_at": "新增時間", + "playlist_uri": "播放清單 URI", "album": { "album_genres": "專輯曲風", "label": "唱片公司",