Skip to content

Commit

Permalink
Add Moviemento scraper
Browse files Browse the repository at this point in the history
This re-uses the earlier work for Il Kino, using the Kinoheld website.
  • Loading branch information
diurnalist committed Dec 27, 2016
1 parent bd60ef8 commit bb6d363
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion server/src/scraper/moviemento.js
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
module.exports = (callback) => callback(null, []);
const log = require('debug')('scraper:moviemento');
const request = require('request');
const split = require('split');
const url = require('url');

const dataExtractRegex = /dataLayer\.push\((.*?)\);$/;
const host = 'https://www.kinoheld.de';

function getViewData() {
return new Promise((resolve, reject) => {
request({
url: url.resolve(host, 'kino-berlin/moviemento-kino'),
qs: {
layout: 'shows'
}
})
.pipe(split())
.on('data', (line) => {
const [, json] = line.match(dataExtractRegex) || []

if (json) {
resolve(JSON.parse(json));
}
})
.on('error', reject);
});
}

module.exports = (callback) => {
log('starting');
getViewData()
.then(({ shows, movies }) => {
const showtimes = [];

Object.keys(shows).forEach((key) => {
const show = shows[key];
const movie = movies[show.movieId];

const deepLink = url.resolve(host, show.url);
const language = show.flags[0];
const showtime = new Date(show.start);
const title = movie.name.replace(/\((ov|ome?u)\)/i, '').trim();

showtimes.push({
deepLink,
language,
location: 'Moviemento',
showtime,
title
});
});

log(`got ${showtimes.length} results`);
callback(null, showtimes);
}, callback);
};

0 comments on commit bb6d363

Please sign in to comment.