Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions barrels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"directory": "./dist/",
"name": "index.dto.d",
"noHeader": true
}
30 changes: 24 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
"name": "node-csfd-api",
"version": "2.14.1",
"description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
"main": "index.js",
"author": "BART! <bart@bartweb.cz>",
"scripts": {
"start": "tsc -w",
"prebuild": "rimraf dist",
"build": "tsc",
"postbuild": "npm-prepare-dist -s postinstall -s prepare",
"build": "tsc && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && yarn barrels",
"barrels": "barrelsby --delete -c barrels.json",
"postbuild": "npm-prepare-dist -s postinstall -s prepare && yarn fix-paths",
"tsc": "tsc",
"demo": "tsx demo",
"lint": "eslint ./src/**/**/* --fix",
"test": "vitest",
"test:coverage": "yarn test run --coverage",
"fix-paths": "yarn json -I -f ./dist/package.json -e \"this.module='./esm/index.js';this.main='./cjs/index.js';this.types='./index.dto.d.ts'\"",
"publish:next": "yarn && yarn build && yarn test:coverage && cd dist && npm publish --tag next",
"postversion": "git push && git push --follow-tags",
"release:beta": "npm version preminor --preid=beta -m \"chore(update): prelease %s β\"",
Expand All @@ -36,11 +37,12 @@
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.35.0",
"@types/express": "^5.0.3",
"@types/node": "^24.3.1",
"@typescript-eslint/eslint-plugin": "^8.43.0",
"@typescript-eslint/parser": "^8.43.0",
"@types/node": "^24.5.1",
"@typescript-eslint/eslint-plugin": "^8.44.0",
"@typescript-eslint/parser": "^8.44.0",
"@vitest/coverage-istanbul": "^3.2.4",
"@vitest/ui": "3.2.4",
"barrelsby": "^2.8.1",
"dotenv": "^17.2.2",
"eslint": "^9.35.0",
"eslint-config-google": "^0.14.0",
Expand All @@ -49,6 +51,7 @@
"express": "^5.1.0",
"globals": "^16.4.0",
"husky": "^9.1.7",
"json": "^11.0.0",
"lint-staged": "^16.1.6",
"npm-prepare-dist": "^0.5.0",
"prettier": "^3.6.2",
Expand Down Expand Up @@ -84,5 +87,20 @@
"license": "MIT",
"lint-staged": {
"*.ts": "eslint --cache --fix"
},
"main": "./cjs/index.js",
"module": "./esm/index.js",
"types": "./index.dto.d.ts",
"exports": {
".": {
"import": {
"types": "./index.dto.d.ts",
"default": "./esm/index.js"
},
"require": {
"types": "./index.dto.d.ts",
"default": "./cjs/index.js"
}
}
}
}
2 changes: 1 addition & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dotenv/config';
import express, { NextFunction, Request, Response } from 'express';
import packageJson from './package.json';
import { csfd } from './src';
import { CSFDFilmTypes } from './src/interfaces/global';
import { CSFDFilmTypes } from './src/dto/global';

type Severity = 'info' | 'warn' | 'error' | 'success';

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/cinema.interface.ts → src/dto/cinema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CSFDMovieListItem } from './movie.interface';
import { CSFDMovieListItem } from './movie';

export interface CSFDCinema {
id: number;
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions src/interfaces/movie.interface.ts → src/dto/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ export interface CSFDVod {
}

export interface CSFDCreators {
directors: CSFDCreator[];
writers: CSFDCreator[];
cinematography: CSFDCreator[];
music: CSFDCreator[];
actors: CSFDCreator[];
basedOn: CSFDCreator[];
producers: CSFDCreator[];
filmEditing: CSFDCreator[];
costumeDesign: CSFDCreator[];
productionDesign: CSFDCreator[];
directors: CSFDMovieCreator[];
writers: CSFDMovieCreator[];
cinematography: CSFDMovieCreator[];
music: CSFDMovieCreator[];
actors: CSFDMovieCreator[];
basedOn: CSFDMovieCreator[];
producers: CSFDMovieCreator[];
filmEditing: CSFDMovieCreator[];
costumeDesign: CSFDMovieCreator[];
productionDesign: CSFDMovieCreator[];
}

export interface CSFDTitlesOther {
country: string;
title: string;
}

export interface CSFDCreator {
export interface CSFDMovieCreator {
/**
* CSFD person ID.
*
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/search.interface.ts → src/dto/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CSFDScreening } from './global';
import { CSFDCreator } from './movie.interface';
import { CSFDMovieCreator } from './movie';

export interface CSFDSearch {
movies: CSFDSearchMovie[];
Expand All @@ -22,11 +22,11 @@ export interface CSFDSearchUser {
url: string;
}

export interface CSFDSearchCreator extends CSFDCreator {
export interface CSFDSearchCreator extends CSFDMovieCreator {
image: string;
}

export interface CSFDSearchCreators {
directors: CSFDCreator[];
actors: CSFDCreator[];
directors: CSFDMovieCreator[];
actors: CSFDMovieCreator[];
}
File renamed without changes.
20 changes: 10 additions & 10 deletions src/helpers/cinema.helper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HTMLElement } from 'node-html-parser';
import { CSFDColorRating } from '../interfaces/global';
import { Colors } from '../interfaces/user-ratings.interface';
import {
CSFDCinemaGroupedFilmsByDate,
CSFDCinemaMeta,
CSFDCinemaMovie
} from './../interfaces/cinema.interface';
} from '../dto/cinema';
import { CSFDColorRating } from '../dto/global';
import { Colors } from '../dto/user-ratings';
import { parseColor, parseIdFromUrl } from './global.helper';

export const getColorRating = (el: HTMLElement): CSFDColorRating => {
export const getCinemaColorRating = (el: HTMLElement): CSFDColorRating => {
return parseColor(el?.classNames.split(' ').pop() as Colors);
};

Expand All @@ -17,14 +17,14 @@ export const getCinemaId = (el: HTMLElement | null): number => {
return +id;
};

export const getId = (url: string): number | null => {
export const getCinemaUrlId = (url: string): number | null => {
if (url) {
return parseIdFromUrl(url);
}
return null;
};

export const getCoords = (el: HTMLElement | null): { lat: number; lng: number } | null => {
export const getCinemaCoords = (el: HTMLElement | null): { lat: number; lng: number } | null => {

if (!el) return null;
const linkMapsEl = el.querySelector('a[href*="q="]');
Expand Down Expand Up @@ -63,20 +63,20 @@ export const getGroupedFilmsByDate = (el: HTMLElement | null): CSFDCinemaGrouped
.map((index) => {
const [date, films] = divs.slice(index, index + 2);
const dateText = date?.firstChild?.textContent?.trim() ?? null;
return { date: dateText, films: getFilms('', films) };
return { date: dateText, films: getCinemaFilms('', films) };
});

return getDatesAndFilms;
};

export const getFilms = (date: string, el: HTMLElement | null): CSFDCinemaMovie[] => {
export const getCinemaFilms = (date: string, el: HTMLElement | null): CSFDCinemaMovie[] => {
const filmNodes = el.querySelectorAll('.cinema-table tr');

const films = filmNodes.map((filmNode) => {
const url = filmNode.querySelector('td.name h3 a')?.attributes.href;
const id = getId(url);
const id = getCinemaUrlId(url);
const title = filmNode.querySelector('.name h3')?.text.trim();
const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
const colorRating = getCinemaColorRating(filmNode.querySelector('.name .icon'));
const showTimes = filmNode.querySelectorAll('.td-time')?.map((x) => x.textContent.trim());
const meta = filmNode.querySelectorAll('.td-title span')?.map((x) => x.text.trim());

Expand Down
30 changes: 15 additions & 15 deletions src/helpers/creator.helper.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { HTMLElement } from 'node-html-parser';
import { CSFDCreatorScreening } from '../interfaces/creator.interface';
import { CSFDColorRating } from '../interfaces/global';
import { Colors } from '../interfaces/user-ratings.interface';
import { CSFDCreatorScreening } from '../dto/creator';
import { CSFDColorRating } from '../dto/global';
import { Colors } from '../dto/user-ratings';
import { addProtocol, parseColor, parseIdFromUrl } from './global.helper';

export const getColorRating = (el: HTMLElement): CSFDColorRating => {
const getCreatorColorRating = (el: HTMLElement): CSFDColorRating => {
return parseColor(el?.classNames.split(' ').pop() as Colors);
};

export const getId = (url: string): number => {
export const getCreatorId = (url: string): number => {
if (url) {
return parseIdFromUrl(url);
}
return null;
};

export const getName = (el: HTMLElement | null): string => {
export const getCreatorName = (el: HTMLElement | null): string => {
return el.querySelector('h1').innerText.trim();
};

export const getBirthdayInfo = (
export const getCreatorBirthdayInfo = (
el: HTMLElement | null
): { birthday: string; age: number; birthPlace: string } => {
const infoBlock = el.querySelector('h1 + p');
Expand All @@ -42,35 +42,35 @@ export const getBirthdayInfo = (
return { birthday, age, birthPlace };
};

export const getBio = (el: HTMLElement | null): string => {
export const getCreatorBio = (el: HTMLElement | null): string => {
return el.querySelector('.article-content p')?.text.trim().split('\n')[0].trim() || null;
};

export const getPhoto = (el: HTMLElement | null): string => {
export const getCreatorPhoto = (el: HTMLElement | null): string => {
const image = el.querySelector('img').attributes.src;
return addProtocol(image);
};

export const parseBirthday = (text: string): any => {
const parseBirthday = (text: string): any => {
return text.replace(/nar./g, '').trim();
};

export const parseAge = (text: string): any => {
const parseAge = (text: string): any => {
return text.trim().replace(/\(/g, '').replace(/let\)/g, '').trim();
};

export const parseBirthPlace = (text: string): any => {
const parseBirthPlace = (text: string): any => {
return text.trim().replace(/<br>/g, '').trim();
};

export const getFilms = (el: HTMLElement | null): CSFDCreatorScreening[] => {
export const getCreatorFilms = (el: HTMLElement | null): CSFDCreatorScreening[] => {
const filmNodes = el.querySelectorAll('.box')[0]?.querySelectorAll('table tr');
let yearCache: number;
const films = filmNodes.map((filmNode) => {
const id = getId(filmNode.querySelector('td.name .film-title-name')?.attributes.href);
const id = getCreatorId(filmNode.querySelector('td.name .film-title-name')?.attributes.href);
const title = filmNode.querySelector('.name')?.text.trim();
const year = +filmNode.querySelector('.year')?.text.trim();
const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
const colorRating = getCreatorColorRating(filmNode.querySelector('.name .icon'));

// Cache year from previous film because there is a gap between movies with same year
if (year) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/global.helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CSFDColorRating } from '../interfaces/global';
import { Colors } from '../interfaces/user-ratings.interface';
import { CSFDColorRating } from '../dto/global';
import { Colors } from '../dto/user-ratings';

export const parseIdFromUrl = (url: string): number => {
if (url) {
Expand Down
Loading