node-csfd-api
Advanced tools
Comparing version 1.1.0-alpha.3 to 1.1.0-beta.0
@@ -1,2 +0,2 @@ | ||
export declare const fetchUserRatings: (user: string | number, page?: number) => Promise<string>; | ||
export declare const fetchUserRatings: (user: string | number) => Promise<string>; | ||
export declare const fetchMovie: (movieId: number) => Promise<string>; |
@@ -18,6 +18,15 @@ "use strict"; | ||
}; | ||
const fetchUserRatings = async (user, page) => { | ||
const url = vars_1.userRatingsUrl(user, page); | ||
const response = await cross_fetch_1.default(url, { headers }); | ||
return await response.text(); | ||
const fetchUserRatings = async (user) => { | ||
const url = vars_1.userRatingsUrl(user); | ||
try { | ||
const response = await cross_fetch_1.default(url, { headers }); | ||
if (response.status >= 400 && response.status < 600) { | ||
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`); | ||
} | ||
return await response.text(); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
return 'Error'; | ||
} | ||
}; | ||
@@ -27,5 +36,14 @@ exports.fetchUserRatings = fetchUserRatings; | ||
const url = vars_1.movieUrl(+movieId); | ||
const response = await cross_fetch_1.default(url, { headers }); | ||
return await response.text(); | ||
try { | ||
const response = await cross_fetch_1.default(url, { headers }); | ||
if (response.status >= 400 && response.status < 600) { | ||
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`); | ||
} | ||
return await response.text(); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
return 'Error'; | ||
} | ||
}; | ||
exports.fetchMovie = fetchMovie; |
@@ -0,3 +1,4 @@ | ||
import { CSFDFilmTypes } from './interfaces/global'; | ||
import { CSFDMovie } from './interfaces/movie.interface'; | ||
import { CSFDUserRatingConfig, CSFDUserRatings } from './interfaces/user-ratings.interface'; | ||
import { CSFDUserRatings } from './interfaces/user-ratings.interface'; | ||
import { MovieScraper } from './services/movie.service'; | ||
@@ -9,5 +10,8 @@ import { UserRatingsScraper } from './services/user-ratings.service'; | ||
constructor(userRatingsService: UserRatingsScraper, movieService: MovieScraper); | ||
userRatings(user: string | number, config?: CSFDUserRatingConfig): Promise<CSFDUserRatings[]>; | ||
userRatings(user: string | number, config?: { | ||
includesOnly?: CSFDFilmTypes[]; | ||
excludes?: CSFDFilmTypes[]; | ||
}): Promise<CSFDUserRatings[]>; | ||
movie(movie: number): Promise<CSFDMovie>; | ||
} | ||
export declare const csfd: Csfd; |
@@ -1,2 +0,2 @@ | ||
import { CSFDFilmTypes, CSFDScreening, CSFDStars } from './global'; | ||
import { CSFDScreening, CSFDStars } from './global'; | ||
export interface CSFDUserRatings extends CSFDScreening { | ||
@@ -6,7 +6,2 @@ userRating: CSFDStars; | ||
} | ||
export interface CSFDUserRatingConfig { | ||
includesOnly?: CSFDFilmTypes[]; | ||
excludes?: CSFDFilmTypes[]; | ||
allPages?: boolean; | ||
} | ||
export declare type Colors = 'lightgrey' | 'blue' | 'red' | 'grey'; |
{ | ||
"name": "node-csfd-api", | ||
"version": "1.1.0-alpha.3", | ||
"version": "1.1.0-beta.0", | ||
"description": "Simple NPM library for scraping CSFD", | ||
@@ -16,2 +16,3 @@ "main": "./index.js", | ||
"test": "jest", | ||
"publish:next": "yarn && yarn build && yarn test --coverage true && npm publish --folder dist --tag beta", | ||
"postversion": "git push && git push --follow-tags", | ||
@@ -25,3 +26,3 @@ "release:beta": "npm version prerelease -m \"chore(update): prelease %s 💥 \"", | ||
"cross-fetch": "^3.0.6", | ||
"node-html-parser": "^2.0.0" | ||
"node-html-parser": "^2.0.2" | ||
}, | ||
@@ -28,0 +29,0 @@ "repository": { |
@@ -6,3 +6,3 @@ [![npm version](https://badge.fury.io/js/node-csfd-api.svg)](https://badge.fury.io/js/node-csfd-api) | ||
# CSFD API | ||
# CSFD API 2021 | ||
@@ -12,4 +12,4 @@ > Tiny NPM library for scraping CSFD | ||
> - Browser + Node.js (SSR) | ||
> - TypeScript | ||
> - ✅ Ready for CSFD 2021! [See instructions](#CSFD-2021-beta) | ||
> - TypeScript 100% | ||
> - ✅ Ready for CSFD 2021! | ||
@@ -39,3 +39,3 @@ ## Install | ||
csfd.movie('535121').then((movie) => console.log(movie)); | ||
csfd.movie(535121).then((movie) => console.log(movie)); | ||
``` | ||
@@ -144,6 +144,11 @@ | ||
### More | ||
#### Options | ||
Work in progress... | ||
| Option | Type | Default | Description | | ||
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------------------------------- | | ||
| **includesOnly** | [CSFDFilmTypes[]](https://github.com/bartholomej/node-csfd-api/blob/8fa5f9cbc7e7f2b62b0bd2c2b5a24c9a63444f6a/src/interfaces/global.ts#L25) | null | Including only film types. eg. `['TV Seriál', 'koncert']` | | ||
| **exclude** | [CSFDFilmTypes[]](https://github.com/bartholomej/node-csfd-api/blob/8fa5f9cbc7e7f2b62b0bd2c2b5a24c9a63444f6a/src/interfaces/global.ts#L25) | null | Excluding film types eg. `['epizoda', 'série']` | | ||
_Note: You can not use both parameters 'includesOnly' and 'excludes'. Parameter 'includesOnly' has a priority._ | ||
## CSFD 2021 (beta) | ||
@@ -153,6 +158,9 @@ | ||
- Branch ([new-csfd](https://github.com/bartholomej/node-csfd-api/tree/new-csfd)) | ||
- `yarn add node-csfd-api@beta` | ||
## Roadmap | ||
- [ ] Search: movies, tv series, users, creators... | ||
- [ ] Profiles of creators... | ||
## Development | ||
@@ -168,3 +176,3 @@ | ||
You can find and modify it in `./demo.ts` file | ||
You can find and modify it in [`./demo.ts`](https://raw.githubusercontent.com/bartholomej/node-csfd-api/search/demo.ts) file | ||
@@ -175,2 +183,17 @@ ```bash | ||
## Development (notes for me) | ||
### Publish Stable | ||
```shell | ||
yarn release:patch | ||
# yarn release:minor | ||
# yarn release:major | ||
``` | ||
### Publish next channel | ||
1. Bump version `-beta.0` in `package.json` | ||
2. `yarn publish:next` | ||
## Contribution | ||
@@ -177,0 +200,0 @@ |
@@ -1,7 +0,10 @@ | ||
import { CSFDUserRatingConfig, CSFDUserRatings } from '../interfaces/user-ratings.interface'; | ||
import { CSFDFilmTypes } from '../interfaces/global'; | ||
import { CSFDUserRatings } from '../interfaces/user-ratings.interface'; | ||
export declare class UserRatingsScraper { | ||
private films; | ||
userRatings(user: string | number, config?: CSFDUserRatingConfig): Promise<CSFDUserRatings[]>; | ||
private getPage; | ||
userRatings(user: string | number, config?: { | ||
includesOnly?: CSFDFilmTypes[]; | ||
excludes?: CSFDFilmTypes[]; | ||
}): Promise<CSFDUserRatings[]>; | ||
private buildUserRatings; | ||
} |
@@ -12,25 +12,6 @@ "use strict"; | ||
async userRatings(user, config) { | ||
let allMovies = []; | ||
var _a, _b, _c, _d; | ||
const response = await fetchers_1.fetchUserRatings(user); | ||
const items = node_html_parser_1.parse(response); | ||
const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr'); | ||
// Get number of pages | ||
const pagesNode = items.querySelector('.pagination'); | ||
const pages = +(pagesNode === null || pagesNode === void 0 ? void 0 : pagesNode.childNodes[pagesNode.childNodes.length - 4].rawText) || 1; | ||
allMovies = this.getPage(config, movies); | ||
if (config === null || config === void 0 ? void 0 : config.allPages) { | ||
console.log('Fetching all pages', pages); | ||
for (let i = 1; i <= pages; i++) { | ||
console.log('Fetching page', i, 'out of', pages, '...'); | ||
const response = await fetchers_1.fetchUserRatings(user, i); | ||
const items = node_html_parser_1.parse(response); | ||
const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr'); | ||
allMovies = [...allMovies, ...this.getPage(config, movies)]; | ||
} | ||
return allMovies; | ||
} | ||
return allMovies; | ||
} | ||
getPage(config, movies) { | ||
var _a, _b, _c, _d; | ||
if (config) { | ||
@@ -37,0 +18,0 @@ if (((_a = config.includesOnly) === null || _a === void 0 ? void 0 : _a.length) && ((_b = config.excludes) === null || _b === void 0 ? void 0 : _b.length)) { |
@@ -1,2 +0,2 @@ | ||
export declare const userRatingsUrl: (user: string | number, page?: number) => string; | ||
export declare const userRatingsUrl: (user: string | number) => string; | ||
export declare const movieUrl: (movie: number) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.movieUrl = exports.userRatingsUrl = void 0; | ||
const userRatingsUrl = (user, page) => `https://new.csfd.cz/uzivatel/${encodeURIComponent(user)}/hodnoceni/${page ? '?page=' + page : ''}`; | ||
const userRatingsUrl = (user) => `https://new.csfd.cz/uzivatel/${encodeURIComponent(user)}/hodnoceni/`; | ||
exports.userRatingsUrl = userRatingsUrl; | ||
const movieUrl = (movie) => `https://new.csfd.cz/film/${encodeURIComponent(movie)}`; | ||
exports.movieUrl = movieUrl; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31135
571
219
Updatednode-html-parser@^2.0.2