Skip to content

Commit

Permalink
API: use Piped for search autocompletion (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bellisario authored Jan 15, 2023
1 parent ddce34b commit 1e2d0f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Musicale is a free and open source alternative to those players and streams musi

The interesting thing about Musicale is that there is no backend and the API it's from [Piped](https://github.com/TeamPiped/Piped) (a privacy-friendly alternative YouTube frontend), which is well documented [here](https://piped-docs.kavin.rocks/).

There is also an autocomplete API, made by me, to get the search suggestions. You can find more info about it [here](https://musicautocomplete.deno.dev/) and the source code [here](https://github.com/Bellisario/musicautocomplete).

## Legal

We do NOT host or scrape any Youtube Music content, we use a PUBLIC available API to provide user a playable URL of the music through a good-looking interface, WITHOUT violating any laws.
Expand Down
16 changes: 4 additions & 12 deletions src/components/Autocomplete.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
const dispatch = createEventDispatcher();
type ApiResponse =
| {
error: true;
type: 'no-query' | 'invalid' | 'server-error';
results: [];
}
| {
error: false;
results: string[];
};
type ApiResponse = string[]
export let query: string;
export let searchFocus: boolean;
Expand Down Expand Up @@ -43,7 +34,7 @@
controller = new AbortController();
try {
response = await fetch(
`https://musicautocomplete.deno.dev/search?q=${encodeURIComponent(query)}`,
`https://pipedapi.kavin.rocks/suggestions?query=${encodeURIComponent(query.trim())}`,
{
signal: controller.signal,
}
Expand All @@ -53,8 +44,9 @@
return;
}
}
if (response === undefined) return items = []
const data: ApiResponse = await response.json();
items = data.results.slice(0, 5);
items = data.slice(0, 5);
}
// function updateFocus() {
Expand Down

0 comments on commit 1e2d0f0

Please sign in to comment.