Code Monkey home page Code Monkey logo

node-csfd-api's Introduction

npm version Package License Build & Publish codecov

CSFD API 🎥 2024

JavaScript NPM library for scraping Czech Movie Database (csfd.cz)

  • JavaScript / TypeScript
  • Browser + Node.js (SSR)
  • Tested (~100% Code coverage)
  • ✅ Ready for new ČSFD 2024!
  • You can use in:
    • Firebase function
    • AWS λ (lambda function)
    • CloudFlare Worker
    • Chrome extension
    • React native app
    • Browsers (Pay attention to CORS)

🗜️ Install

npm install node-csfd-api
# yarn add node-csfd-api

🛠️ Usage and examples

Movie

Get info about this movie (id: 535121)

import { csfd } from 'node-csfd-api';

csfd.movie(535121).then((movie) => console.log(movie));
Click here to see full result example
{
  id: 535121,
  title: 'Na špatné straně',
  year: '2018',
  descriptions: [
    'Otupělý policejní veterán Ridgeman (Mel Gibson)...',
    'Brett je policajt tesne ...'
  ],
  genres: [ 'Krimi', 'Drama', 'Thriller' ],
  type: 'film',
  url: 'https://www.csfd.cz/film/535121',
  origins: [ 'USA', 'Kanada' ],
  colorRating: 'good',
  rating: 73,
  ratingCount: 6654,
  photo: '//image.pmgstatic.com/cache/resized/w1326/files/images/film/photos/162/980/162980090_bbffbb.jpg',
  trivia: ['Když Henry (Tory Kittles) se svým mladším bratrem...', 'Ve filmu se střídají...'],
  titlesOther: [
    { country: 'USA', title: 'Dragged Across Concrete' },
    { country: 'Kanada', title: 'Dragged Across Concrete' },
    { country: 'Slovensko', title: 'Na zlej strane' },
    { country: 'Austrálie', title: 'Dragged Across Concrete' },
    { country: 'Velká Británie', title: 'Dragged Across Concrete' }
  ],
  poster: 'https://image.pmgstatic.com/cache/resized/w1080/files/images/film/posters/163/579/163579352_bf8737.jpg',
  creators: {
    directors: [
    {
      id: 87470,
      name: 'S. Craig Zahler',
      url: 'https://www.csfd.cz/tvurce/87470-s-craig-zahler/'
      }
    ],
    actors: [
      {
        id: 1,
        name: 'Mel Gibson',
        url: 'https://www.csfd.cz/tvurce/1-mel-gibson/'
      }
    ],
    basedOn: [],
    writers: [
      {
        id: 87470,
        name: 'S. Craig Zahler',
        url: 'https://www.csfd.cz/tvurce/87470-s-craig-zahler/'
      }
    ],
    music: [
      {
        id: 203209,
        name: 'Jeff Herriott',
        url: 'https://www.csfd.cz/tvurce/203209-jeff-herriott/'
      }
    ],
    producers: [
      {
        id: 320006,
        name: 'Sefton Fincham',
        url: 'https://www.csfd.cz/tvurce/320006-sefton-fincham/'
      }
    ]
  },
  vod: [
    {
      title: 'Voyo',
      url: 'https://voyo.nova.cz/filmy/4604-na-spatne-strane'
    },
    {
      title: 'DVD',
      url: 'https://filmy.heureka.cz/na-spatne-strane-dvd/#utm_source=csfd.cz&utm_medium=cooperation&utm_campaign=csfd_movies_feed'
    }
  ],
  tags: ['policie', 'zbraně', 'zloděj', 'město', 'sledování'],
  premieres: [
   {
      country: 'Česko',
      format: 'Na Blu-ray',
      date: '07.08.2019',
      company: 'Magic Box'
    },
    {
      country: 'USA',
      format: 'V kinech',
      date: '22.03.2019',
      company: 'Lionsgate US'
    }
  ]
}

Search

Search movies, users and TV series

import { csfd } from 'node-csfd-api';

csfd.search('bart').then((search) => console.log(search));
Click here to see full result example
[
  {
    id: 19653,
    title: 'Black Bart',
    year: '1975',
    url: 'https://www.csfd.cz/film/19653-black-bart/',
    type: 'TV film',
    colorRating: 'bad',
    poster: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
    origins: ['USA'],
    creators: {
      directors: [{
        id: 87470,
        name: 'S. Craig Zahler',
        url: 'https://www.csfd.cz/tvurce/87470-s-craig-zahler/'
      }],
      actors: [{
        id: 1,
        name: 'Mel Gibson',
        url: 'https://www.csfd.cz/tvurce/1-mel-gibson/'
      }]
    }
  }
],
tvSeries: [
  {
    id: 71924,
    title: 'Království',
    year: 1994,
    url: 'https://www.csfd.cz/film/71924-kralovstvi/',
    type: 'seriál',
    colorRating: 'good',
    poster: 'https://image.pmgstatic.com/cache/resized/w60h85/files/images/film/posters/166/708/166708064_2da697.jpg',
    origins: ['Dánsko'],
    creators: []
  }
],
users: [
  {
    id: 912,
    user: 'BART!',
    userRealName: 'Lukáš Barták',
    avatar: 'https://image.pmgstatic.com/cache/resized/w45h60/files/images/user/avatars/000/281/281554_1c0fef.jpg',
    url: 'https://www.csfd.cz/uzivatel/912-bart/'
  }
]

Creators

Get creator info + filmography

import { csfd } from 'node-csfd-api';

csfd.creator(2120).then((creator) => console.log(creator));
Click here to see full result example
{
  id: 2120,
  name: 'Quentin Tarantino',
  birthday: '27.03.1963',
  birthplace: 'Knoxville, Tennessee, USA',
  photo: 'https://image.pmgstatic.com/cache/resized/w100h132crop/files/images/creator/photos/164/515/164515525_b98f8a.jpg',
  age: 58,
  bio: 'Quentin Tarantino se narodil 27. března roku 1963 v americkém Knoxville teprve šestnáctileté Connie Tarantinové. Své jméno Quentin dostal podle matčiny oblíbené televizní postavy Quinta ze seriálu "Gunsmoke". Quentinův otec byl jistý Tony Tarantino, který rodinu opustil když byl Quentin ještě malinký. Jeho dětství a dospívání ovlivnily nejen filmy, ale pop kultura obecně. Televizní seriály, komiksy, populární hudba, to vše jako mladý hltal ve velkém a stále neměl…',
  films: [
    {
      id: 527699,
      title: 'Tenkrát v Hollywoodu',
      year: 2019,
      colorRating: 'good'
    },
    {
      id: 362228,
      title: 'Osm hrozných',
      year: 2015,
      colorRating: 'good'
    },
    {
      id: 294824,
      title: 'Nespoutaný Django',
      year: 2012,
      colorRating: 'good'
    },
    {
      id: 117077,
      title: 'Hanebný pancharti',
      year: 2009,
      colorRating: 'good'
    },
    {
      id: 229384,
      title: 'Grindhouse: Auto zabiják',
      year: 2007,
      colorRating: 'average'
    },
    {
      id: 178904,
      title: 'Sin City - město hříchu',
      year: 2005,
      colorRating: 'good'
    },
    {
      id: 136304,
      title: 'Kill Bill 2',
      year: 2004,
      colorRating: 'good'
    },
    { id: 43483, title: 'Kill Bill', year: 2003, colorRating: 'good' },
    {
      id: 8850,
      title: 'Jackie Brown',
      year: 1997,
      colorRating: 'good'
    },
    {
      id: 7743,
      title: 'Čtyři pokoje',
      year: 1995,
      colorRating: 'good'
    },
    {
      id: 8852,
      title: 'Pulp Fiction: Historky z podsvětí',
      year: 1994,
      colorRating: 'good'
    }
  ]
}

User Ratings

Last ratings (last page)

Get my last 50 ratings

import { csfd } from 'node-csfd-api';

csfd.userRatings('912-bart').then((ratings) => console.log(ratings));

All ratings (all pages)

Warning: Use it wisely. Can be detected and banned. Consider using it together with allPagesDelay attribute.

Get all of my ratings

import { csfd } from 'node-csfd-api';

csfd
  .userRatings('912-bart', {
    allPages: true, // Download all pages (one by one)
    allPageDelay: 2000 // Make delay 2000ms on each page request
  })
  .then((ratings) => console.log(ratings));
Click here to see full result example
[
  {
    title: 'David Attenborough: Život na naší planetě',
    year: 2020,
    type: 'film',
    url: 'https://www.csfd.cz/film/812944-david-attenborough-zivot-na-nasi-planete/',
    colorRating: 'good',
    userDate: '01.11.2020',
    userRating: 5
  },
  {
    title: 'Coronation',
    year: 2020,
    type: 'film',
    url: 'https://www.csfd.cz/film/912552-coronation/',
    colorRating: 'good',
    userDate: '28.10.2020',
    userRating: 4
  }
];

Options for user ratings

Option Type Default Description
includesOnly CSFDFilmTypes[] null Including only film types. eg. ['seriál', 'koncert']
exclude CSFDFilmTypes[] null Excluding film types eg. ['epizoda', 'série']
allPages boolean false Get all pages
allPagesDelay number 0 Delay on each page request. In milliseconds

Note: You can not use both parameters includesOnly and excludes. Parameter includesOnly has a priority.

🧑‍💻 Used by

Web extensions

Web applications

  • bartweb.czLast seen section (Firebase function)

Mobile applications

  • KinoKlub – Mobile application for AeroFilms (React Native: Android + iOS application)

🔮 Roadmap

Scraping more pages

  • Movies
    • Titles
    • Years
    • Type
    • User rating
    • Color rating
    • Poster
    • Duration
    • Origins
    • Descriptions
    • Genres
    • VOD
    • Tags
    • Premieres
    • Creators
      • Directors
      • Writers
      • Cinematography
      • Music
      • Actors
      • BasedOn
      • Producers
      • Film editors
      • Costume designers
      • Production designers
    • Premieres
    • Related movies
    • Similar movies
    • Trivia
    • Photo from movie (random)
    • Reviews
    • OST
  • Search
    • Movies
    • Users
    • TV Series
    • Creators
  • Creators
    • Bio
    • Movies (TODO categories)
  • User Ratings
    • Last ratings
    • All pages

🛠️ Development

Developing and debugging library

yarn start

Run demo locally

You can find and modify it in ./demo.ts file

yarn demo

🤝 Contribution

I welcome you to customize this according to your needs ;)

Pull requests for any improvements would be great!

⭐️ Show your support

Give a ⭐️ if this project helped you!

Or if you are brave enough consider making a donation for some 🍺 or 🍵 ;)

🕵️‍♀️ Privacy Policy

I DO NOT STORE ANY DATA. PERIOD.

I physically can't. I have nowhere to store it. I don't even have a server database to store it. So even if Justin Bieber asked nicely to see your data, I wouldn't have anything to show him.

That's why, with node-csfd-api, what happens on your device stays on your device till disappear.

📝 License

Copyright © 2020 – 2024 Lukas Bartak

Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)

All contents are licensed under the MIT license.

node-csfd-api's People

Contributors

bartholomej avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-csfd-api's Issues

Duration is NaN on some movies

Eg. Lord of the rings movies have special Length, they have three types of length, normal, directors cut, and special edition. In this case, the duration is NaN.

λ node .\index.js csfd-get 4711 -r
{
  id: 4711,
  title: 'Pán prstenů: Společenstvo Prstenu',
  year: 2001,
  duration: NaN,
  descriptions: [

Feature request: Add number of ratings

Thanks for a wonderful library. I've just used it to successfully deploy a super simple API endpoint on Heroku to use with my personal movie database.

I was wondering if would consider also adding information about the number of ratings?

The API already returns the calculated percentage, but the number of ratings helps you better determine the relevance/significance of the rating.

I looked through your code and considered making a pull request. Unfortunately, I can't write tests and I don't think my code would be up to your standards. Hopefully, it should be quite simple to scrape the information.

Here is the element in question:

<span class="counter">**{NUMBER OF RATINGS}**</span>

CleanShot 2021-11-16 at 19 27 44@2x

Synology Video Station

Dobrý den,
šlo by to nějak použít pro metadata na Synology VideoStation?
Děkuji

Hello, is there any way to use this for metadata on Synology VideoStation?
Thanks

csfd.movie(1079) throws TypeError: Cannot read properties of undefined (reading 'split')

Calling csfd.movie(1079) throws

TypeError: Cannot read properties of undefined (reading 'split')
    at getPremieres (...\node_modules\node-csfd-api\helpers\movie.helper.js:230:91)
    at MovieScraper.buildMovie (...\node_modules\node-csfd-api\services\movie.service.js:52:56)
    at MovieScraper.movie (...\node_modules\node-csfd-api\services\movie.service.js:17:14)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {stack: 'TypeError: Cannot read properties of undefine…ions (node:internal/process/task_queues:96:5)', message: 'Cannot read properties of undefined (reading 'split')'}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.