UNPKG

node-csfd-api

Version:

ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)

1 lines 2.66 kB
{"version":3,"file":"user-ratings.helper.mjs","names":[],"sources":["../../src/helpers/user-ratings.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global';\nimport { CSFDColors } from '../dto/user-ratings';\nimport { parseColor, parseIdFromUrl } from './global.helper';\n\nexport const getUserRatingId = (el: HTMLElement): number => {\n const url = el.querySelector('td.name .film-title-name').attributes.href;\n return parseIdFromUrl(url);\n};\n\nexport const getUserRating = (el: HTMLElement): CSFDStars => {\n const ratingText = el.querySelector('td.star-rating-only .stars').classNames.split(' ').pop();\n\n const rating = ratingText.includes('stars-') ? +ratingText.split('-').pop() : 0;\n return rating as CSFDStars;\n};\n\nexport const getUserRatingType = (el: HTMLElement): CSFDFilmTypes => {\n const typeText = el.querySelectorAll('td.name .film-title-info .info');\n\n return (typeText.length > 1 ? typeText[1].text.slice(1, -1) : 'film') as CSFDFilmTypes;\n};\n\nexport const getUserRatingTitle = (el: HTMLElement): string => {\n return el.querySelector('td.name .film-title-name').text;\n};\n\nexport const getUserRatingYear = (el: HTMLElement): number => {\n return +el.querySelectorAll('td.name .film-title-info .info')[0]?.text.slice(1, -1) || null;\n};\n\nexport const getUserRatingColorRating = (el: HTMLElement): CSFDColorRating => {\n const color = parseColor(el.querySelector('td.name .icon').classNames.split(' ').pop() as CSFDColors);\n return color;\n};\n\nexport const getUserRatingDate = (el: HTMLElement): string => {\n return el.querySelector('td.date-only').text.trim();\n};\n\nexport const getUserRatingUrl = (el: HTMLElement): string => {\n const url = el.querySelector('td.name .film-title-name').attributes.href;\n return `https://www.csfd.cz${url}`;\n};\n"],"mappings":";;;AAKA,MAAa,mBAAmB,OAA4B;CAC1D,MAAM,MAAM,GAAG,cAAc,2BAA2B,CAAC,WAAW;AACpE,QAAO,eAAe,IAAI;;AAG5B,MAAa,iBAAiB,OAA+B;CAC3D,MAAM,aAAa,GAAG,cAAc,6BAA6B,CAAC,WAAW,MAAM,IAAI,CAAC,KAAK;AAG7F,QADe,WAAW,SAAS,SAAS,GAAG,CAAC,WAAW,MAAM,IAAI,CAAC,KAAK,GAAG;;AAIhF,MAAa,qBAAqB,OAAmC;CACnE,MAAM,WAAW,GAAG,iBAAiB,iCAAiC;AAEtE,QAAQ,SAAS,SAAS,IAAI,SAAS,GAAG,KAAK,MAAM,GAAG,GAAG,GAAG;;AAGhE,MAAa,sBAAsB,OAA4B;AAC7D,QAAO,GAAG,cAAc,2BAA2B,CAAC;;AAGtD,MAAa,qBAAqB,OAA4B;AAC5D,QAAO,CAAC,GAAG,iBAAiB,iCAAiC,CAAC,IAAI,KAAK,MAAM,GAAG,GAAG,IAAI;;AAGzF,MAAa,4BAA4B,OAAqC;AAE5E,QADc,WAAW,GAAG,cAAc,gBAAgB,CAAC,WAAW,MAAM,IAAI,CAAC,KAAK,CAAe;;AAIvG,MAAa,qBAAqB,OAA4B;AAC5D,QAAO,GAAG,cAAc,eAAe,CAAC,KAAK,MAAM;;AAGrD,MAAa,oBAAoB,OAA4B;AAE3D,QAAO,sBADK,GAAG,cAAc,2BAA2B,CAAC,WAAW"}