diff --git a/src/csfd/search.js b/src/csfd/search.js new file mode 100644 index 0000000..63e3ef2 --- /dev/null +++ b/src/csfd/search.js @@ -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; +} diff --git a/src/redirect/csfd-kinobox.js b/src/redirect/csfd-kinobox.js index a1bd7b9..d69e7f3 100644 --- a/src/redirect/csfd-kinobox.js +++ b/src/redirect/csfd-kinobox.js @@ -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"; @@ -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) { diff --git a/src/redirect/csfd-kinobox.test.js b/src/redirect/csfd-kinobox.test.js index 5ed8e5a..b12e417 100644 --- a/src/redirect/csfd-kinobox.test.js +++ b/src/redirect/csfd-kinobox.test.js @@ -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/')