fix(source): fine-tune Kokoshika result matching
This commit is contained in:
parent
4bc5e42e50
commit
bbdd968820
5 changed files with 31 additions and 2 deletions
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
|||
1
src/source/__fixtures__/Kokoshka/https:api.themoviedb.org3movie1242404languagesq
generated
Normal file
1
src/source/__fixtures__/Kokoshka/https:api.themoviedb.org3movie1242404languagesq
generated
Normal file
|
|
@ -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}
|
||||
7
src/source/__fixtures__/Kokoshka/https:kokoshka.digitalsStevepercent202025
generated
Normal file
7
src/source/__fixtures__/Kokoshka/https:kokoshka.digitalsStevepercent202025
generated
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -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`] = `[]`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue