Skip to content

Commit

Permalink
fix(top_genres): filter track search request link
Browse files Browse the repository at this point in the history
  • Loading branch information
harbassan committed Dec 26, 2023
1 parent ee0fe75 commit cbbf22e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const fetchTopArtists = async (artists: Record<string, number>) => {
return [top_artists, top_genres, total_genre_tracks];
};

function filterLink(str: string): string {
export function filterLink(str: string): string {
const normalizedStr = str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
return normalizedStr.replace(/[^a-zA-Z0-9\-._~:/?#[\]@!$&()*+,;= ]/g, "").replace(/ /g, "+");
}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/top_genres.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import useDropdownMenu from "../components/hooks/useDropdownMenu";
import StatCard from "../components/cards/stat_card";
import GenresCard from "../components/cards/genres_card";
import { apiRequest, fetchAudioFeatures, updatePageCache } from "../funcs";
import { fetchAudioFeatures, filterLink, updatePageCache } from "../funcs";
import InlineGrid from "../components/inline_grid";
import Status from "../components/status";
import PageHeader from "../components/page_header";
Expand Down Expand Up @@ -93,8 +93,9 @@ const GenresPage = ({ config }: { config: ConfigWrapper }) => {
async function testDupe(track: Track) {
// perform a search to get rid of duplicate tracks
const spotifyItem = await Spicetify.CosmosAsync.get(
`https://api.spotify.com/v1/search?q=track:${track.name}+artist:${track.artists[0].name}&type=track`
`https://api.spotify.com/v1/search?q=track:${filterLink(track.name)}+artist:${filterLink(track.artists[0].name)}&type=track`
).then((res: any) => res.tracks?.items);
if (!spotifyItem) return false;
return spotifyItem.some((item: any) => {
return item.name === track.name && item.popularity > track.popularity;
});
Expand Down

0 comments on commit cbbf22e

Please sign in to comment.