From 172edaf0fc7ac0a3059ccce8e9bb765e22a079d8 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Wed, 29 Oct 2025 11:31:15 +0000 Subject: [PATCH] fix(source): fine-tune Kokoshka result matching --- src/source/Kokoshka.test.ts | 5 +++++ src/source/Kokoshka.ts | 18 ++++++++++++++++-- ...s:api.themoviedb.org3movie1242404languagesq | 1 + .../https:kokoshka.digitalsStevepercent202025 | 7 +++++++ src/source/__snapshots__/Kokoshka.test.ts.snap | 2 ++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/source/__fixtures__/Kokoshka/https:api.themoviedb.org3movie1242404languagesq create mode 100644 src/source/__fixtures__/Kokoshka/https:kokoshka.digitalsStevepercent202025 diff --git a/src/source/Kokoshka.test.ts b/src/source/Kokoshka.test.ts index 77e3afc..1ef0723 100644 --- a/src/source/Kokoshka.test.ts +++ b/src/source/Kokoshka.test.ts @@ -35,4 +35,9 @@ describe('Kokoshka', () => { const streams = await source.handle(ctx, 'movie', new TmdbId(1213327, undefined, undefined)); expect(streams).toMatchSnapshot(); }); + + test('handle non-existent Steve 2025', async () => { + const streams = await source.handle(ctx, 'movie', new TmdbId(1242404, undefined, undefined)); + expect(streams).toMatchSnapshot(); + }); }); diff --git a/src/source/Kokoshka.ts b/src/source/Kokoshka.ts index 546d227..6ab482e 100644 --- a/src/source/Kokoshka.ts +++ b/src/source/Kokoshka.ts @@ -1,4 +1,5 @@ import * as cheerio from 'cheerio'; +import levenshtein from 'fast-levenshtein'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, getTmdbNameAndYear, Id, TmdbId } from '../utils'; @@ -80,8 +81,21 @@ export class Kokoshka extends Source { const $ = cheerio.load(html); - return $(`.result-item:has(${tmdbId.season ? '.tvshows' : '.movies'}) a`) - .map((_i, el) => new URL($(el).attr('href') as string, this.baseUrl)) + return $(`.result-item:has(${tmdbId.season ? '.tvshows' : '.movies'})`) + .filter((_i, el) => { + const resultItemYear = parseInt($('.year', el).text()); + + return Math.abs(resultItemYear - year) <= 1; + }) + .filter((_i, el) => { + const resultItemTitle = $('.title', el) + .text() + .replace(/\(\d+\).*/, '') // Strip away suffixes like "(2021) me Titra Shqip" + .trim(); + + return levenshtein.get(resultItemTitle, name, { useCollator: true }) < 3; + }) + .map((_i, el) => new URL($('a', el).attr('href') as string, this.baseUrl)) .get(0); }; diff --git a/src/source/__fixtures__/Kokoshka/https:api.themoviedb.org3movie1242404languagesq b/src/source/__fixtures__/Kokoshka/https:api.themoviedb.org3movie1242404languagesq new file mode 100644 index 0000000..30e2001 --- /dev/null +++ b/src/source/__fixtures__/Kokoshka/https:api.themoviedb.org3movie1242404languagesq @@ -0,0 +1 @@ +{"adult":false,"backdrop_path":"/sb8Aq1RohASXyjT0uEOUUZJi5oI.jpg","belongs_to_collection":null,"budget":0,"genres":[{"id":18,"name":"Drama"}],"homepage":"","id":1242404,"imdb_id":"tt32985279","origin_country":["IE"],"original_language":"en","original_title":"Steve","overview":"","popularity":13.0327,"poster_path":"/wmLoMyofbseLfxiGgk1Iz5H97c3.jpg","production_companies":[{"id":196153,"logo_path":"/rdZiokZcHdb51C0uCTDjJyUBfc4.png","name":"Big Things Films","origin_country":"IE"}],"production_countries":[{"iso_3166_1":"IE","name":"Ireland"}],"release_date":"2025-09-19","revenue":0,"runtime":92,"spoken_languages":[{"english_name":"English","iso_639_1":"en","name":"English"}],"status":"Released","tagline":"","title":"Steve","video":false,"vote_average":6.396,"vote_count":134} \ No newline at end of file diff --git a/src/source/__fixtures__/Kokoshka/https:kokoshka.digitalsStevepercent202025 b/src/source/__fixtures__/Kokoshka/https:kokoshka.digitalsStevepercent202025 new file mode 100644 index 0000000..df72571 --- /dev/null +++ b/src/source/__fixtures__/Kokoshka/https:kokoshka.digitalsStevepercent202025 @@ -0,0 +1,7 @@ +Steve 2025 - Kokoshka.Digital | Filma Me Titra Shqip

Rezultate të gjetura: Steve 2025

IMDb 7.52025

Një udhëtim zbulues, i guximshëm dhe ç’armatosës personal në botën e superfandom-it, i treguar përmes lentes së njërit prej artistëve më ikonikë dhe më të qëndrueshëm në botë, Eminem, dhe fansave ...

IMDb 7.8542025

Një polic i guximshëm, por brilant, bëhet kreu i një departamenti të ri policie, ku ai udhëheq një ekip të papritur njerëzish të papërshtatshëm në zgjidhjen e rasteve të pazgjidhura të Edinburgut.

IMDb 6.92025

Biznesmeni i pasur Zsa-zsa Korda emëron vajzën e tij të vetme, një murgeshë, si trashëgimtare të vetme të pasurisë së tij. Ndërsa Korda ndërmerr një sipërmarrje të re, ata shpejt bëhen shënjestër ...

IMDb 62025

Katër të papërshtatshëm e gjejnë veten duke luftuar me probleme të zakonshme kur papritur tërhiqen përmes një portali misterioz në Mbibotën: një vend i çuditshëm, kubik i çudirave që lulëzon me ...

IMDb 8.562025

Fuqia është për t’u rrëmbyer ndërsa Harrigans dhe Stevensons, dy familje ndërluftuese krimi londineze, përleshen në një betejë të vrasësh ose të vritesh që kërcënon të rrëzojë perandoritë ...

IMDb 4.92025

Gjatë ditës, ata janë të padukshëm – shërbëtorë, mikpritëse dhe banakiere në një hotel luksoz. Natën, ata janë Carjackers, një ekuipazh shoferësh të aftë që gjurmojnë dhe grabisin klientët ...

IMDb 72025

Nga demokracia e brishtë e Republikës së Vajmarit te tirania brutale e regjimit nazist, kjo seri e thelluar eksploron se si rënia e Gjermanisë në kaos hapi rrugën për ngritjen në pushtet të Adolf ...


+ + \ No newline at end of file diff --git a/src/source/__snapshots__/Kokoshka.test.ts.snap b/src/source/__snapshots__/Kokoshka.test.ts.snap index 777f23d..b51f0e3 100644 --- a/src/source/__snapshots__/Kokoshka.test.ts.snap +++ b/src/source/__snapshots__/Kokoshka.test.ts.snap @@ -85,6 +85,8 @@ exports[`Kokoshka handle Weapons 2025 1`] = ` ] `; +exports[`Kokoshka handle non-existent Steve 2025 1`] = `[]`; + exports[`Kokoshka handle non-existent content gracefully 1`] = `[]`; exports[`Kokoshka handle non-existent episode gracefully 1`] = `[]`;