diff --git a/packages/wrappers/src/base.ts b/packages/wrappers/src/base.ts index 077bfb9f..91cd5df8 100644 --- a/packages/wrappers/src/base.ts +++ b/packages/wrappers/src/base.ts @@ -327,22 +327,30 @@ export class BaseWrapper { // if filename behaviorHint is not present, attempt to look for a filename in the stream description or title let description = stream.description || stream.title; - const episodeRegex = - /(? line.match(episodeRegex) || line.match(yearRegex) - ) || lines[0]; - } - let stringToParse: string = filename || description || ''; - if (!(filename.match(episodeRegex) || filename.match(yearRegex))) { - stringToParse = description.replace(/\n/g, ' ').trim(); + // attempt to find a valid filename by looking for season/episode or year in the description line by line, + // and fall back to using the full description. + let parsedInfo: ParsedNameData | undefined = undefined; + const potentialFilenames = [ + filename, + ...(description.split('\n') as string[]).splice(0, 5), + ]; + for (const line of potentialFilenames) { + parsedInfo = parseFilename(line); + if ( + parsedInfo.year || + (parsedInfo.season && parsedInfo.episode) || + parsedInfo.episode + ) { + break; + } else { + parsedInfo = undefined; + } + } + if (!parsedInfo) { + // fall back to using full description as info source + parsedInfo = parseFilename(description); } - let parsedInfo: ParsedNameData = parseFilename(stringToParse); // look for size in one of the many random places it could be let size: number | undefined;