Skip to content

Commit

Permalink
add support for search
Browse files Browse the repository at this point in the history
  • Loading branch information
landsman committed Sep 6, 2024
1 parent e814557 commit d235a82
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/csfd/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Parse CSFD Search page from URL
*
* @param currentUrl {string}
* @returns {string|null}
*/
export function parseSearch(currentUrl) {
const check = currentUrl.includes("/hledat/") || currentUrl.includes("/podrobne-vyhledavani/");
if (!check) {
return null;
}

const urlParams = new URL(currentUrl).searchParams;
const searchQuery = urlParams.get('q');

if (searchQuery == null || searchQuery === "") {
return '';
}

return searchQuery;
}
7 changes: 7 additions & 0 deletions src/redirect/csfd-kinobox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {parseTermFromURL} from "../csfd/movie";
import {parseSearch} from "../csfd/search";
import {parseTelevision} from "../csfd/tv";
import {parseCinema} from "../csfd/cinema";
import {parseCharts} from "../csfd/charts";
Expand Down Expand Up @@ -26,6 +27,12 @@ export function redirectFromCsfdToKinobox(currentUrl) {
return searchMovieOnKinobox(csfdMovieTerm);
}

/* search */
const csfdSearch = parseSearch(currentUrl);
if (csfdSearch !== null) {
return searchMovieOnKinobox(csfdSearch);
}

/* charts */
const csfdCharts = parseCharts(currentUrl);
if (csfdCharts) {
Expand Down
10 changes: 10 additions & 0 deletions src/redirect/csfd-kinobox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ test('movie - redirect from csfd to kinobox', () => {
).toBe('https://www.kinobox.cz/vyhledavani?term=klub%20rvacu');
});

test('search', () => {
expect(
redirectFromCsfdToKinobox('https://www.csfd.cz/podrobne-vyhledavani/')
).toBe('https://www.kinobox.cz/vyhledavani?term=');

expect(
redirectFromCsfdToKinobox('https://www.csfd.cz/hledat/?q=matrix')
).toBe('https://www.kinobox.cz/vyhledavani?term=matrix');
});

test('vod', () => {
expect(
redirectFromCsfdToKinobox('https://www.csfd.cz/vod/')
Expand Down

0 comments on commit d235a82

Please sign in to comment.