modified tmdb service
This commit is contained in:
1 parent
fbca314026
commit
f0246f98c9
1 file changed
+31
-177
+31
-177
@@ -1,193 +1,47 @@
|
|||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const moment = require('../utils/moment.js')
|
|
||||||
|
|
||||||
const Entry = require('../models/Entry.js')
|
|
||||||
const Collection = require('../models/Franchise.js')
|
|
||||||
const EntryId = require('../models/EntryId.js')
|
|
||||||
const EntryRating = require('../models/EntryRating.js');
|
|
||||||
const { saveEntry } = require('./entryService.js');
|
|
||||||
|
|
||||||
const tmdb_apiKey = "5323ef3dc430df54dcb9e58c37fd22bb";
|
const tmdb_apiKey = "5323ef3dc430df54dcb9e58c37fd22bb";
|
||||||
|
|
||||||
// async function getMovies(max, url) {
|
|
||||||
// let list = [];
|
|
||||||
|
|
||||||
// await axios.get(url)
|
|
||||||
// .then((response) => {
|
|
||||||
// if (response.status != 200) return console.log('Error fetching the data.');
|
|
||||||
|
|
||||||
// let data = response.data.results;
|
|
||||||
// let count = 0;
|
|
||||||
// if (data != null)
|
|
||||||
// data.forEach(mv => {
|
|
||||||
// if (count < max) {
|
|
||||||
// // console.log(mv);
|
|
||||||
// let movie = {
|
|
||||||
// id: mv.id,
|
|
||||||
// title: mv.title || mv.name,
|
|
||||||
// poster: 'https://image.tmdb.org/t/p/w300' + mv.poster_path,
|
|
||||||
// year: mv.release_date != undefined ? mv.release_date.substring(0, 4) : mv.first_air_date.substring(0, 4),
|
|
||||||
// rating: mv.vote_average
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
// list.push(movie)
|
|
||||||
|
|
||||||
// count++;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// })
|
|
||||||
// return list;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
async function fetchEntryData(tmdb_id, is_tvserie) {
|
async function fetchEntryData(tmdb_id, is_tvserie) {
|
||||||
// fetching the informations
|
// fetching the informations
|
||||||
let type = is_tvserie ? "tv" : "movie";
|
try {
|
||||||
let url = `https://api.themoviedb.org/3/${type}/${tmdb_id}?api_key=${tmdb_apiKey}&language=en-US`
|
let type = is_tvserie ? "tv" : "movie";
|
||||||
let data;
|
let url = `http://api.themoviedb.org/3/${type}/${tmdb_id}?api_key=${tmdb_apiKey}&language=en-US`
|
||||||
await axios.get(url)
|
let data;
|
||||||
.then((response) => {
|
await axios.get(url)
|
||||||
if (response.status != 200) return console.log('Error fetching the data.');
|
.then((response) => {
|
||||||
data = response.data;
|
if (response.status != 200) return console.log('Error fetching the data.');
|
||||||
})
|
data = response.data;
|
||||||
|
})
|
||||||
|
|
||||||
let savedEntry;
|
return data;
|
||||||
|
} catch (error) {
|
||||||
if (is_tvserie)
|
console.log('Error fetching the data.')
|
||||||
savedEntry = await saveEntry(data);
|
return null;
|
||||||
else
|
}
|
||||||
savedEntry = await saveEntry(data);
|
|
||||||
|
|
||||||
return savedEntry.get({ plain: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function fetchSerieData(serieId) {
|
|
||||||
// // getting the informations
|
|
||||||
// let url = `https://api.themoviedb.org/3/tv/${serieId}?api_key=${tmdb_apiKey}&language=en-US`
|
|
||||||
// let data;
|
|
||||||
// await axios.get(url)
|
|
||||||
// .then((response) => {
|
|
||||||
// if (response.status != 200) return console.log('Error fetching the data.');
|
|
||||||
// data = response.data;
|
|
||||||
// })
|
|
||||||
|
|
||||||
// // creating the object
|
async function fetchSeasonData(tmdbTvId, seasonNumber) {
|
||||||
// let serie = new MovieClass();
|
// fetching the informations
|
||||||
|
try {
|
||||||
|
let url = `http://api.themoviedb.org/3/tv/${tmdbTvId}/season/${seasonNumber}?api_key=${tmdb_apiKey}&language=en-US`
|
||||||
|
let data;
|
||||||
|
await axios.get(url)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.status != 200) return console.log('Error fetching the data.');
|
||||||
|
data = response.data;
|
||||||
|
})
|
||||||
|
|
||||||
// serie.tmdb_id = serieId
|
return data;
|
||||||
|
} catch (error) {
|
||||||
// serie.title = data.name
|
console.log('Error fetching the data.')
|
||||||
// serie.release_date = data.first_air_date
|
return null;
|
||||||
// serie.runtime = data.episode_run_time[0]
|
}
|
||||||
// serie.overview = data.overview
|
}
|
||||||
// serie.country = data.production_countries[0].name
|
|
||||||
// serie.status = data.status
|
|
||||||
|
|
||||||
// serie.poster_path = data.poster_path
|
|
||||||
// serie.poster_path = data.backdrop_path
|
|
||||||
|
|
||||||
// serie.is_tvserie = true
|
|
||||||
|
|
||||||
// serie.tmdb_rating = data.vote_average
|
|
||||||
|
|
||||||
// serie.last_air_date = data.last_air_date
|
|
||||||
// serie.date_added = moment().format("YYYY-MM-DD")
|
|
||||||
|
|
||||||
// // gettings the seasons info
|
|
||||||
// if (data.seasons.length != 0)
|
|
||||||
// for (let i = 0; i < data.seasons.length; i++) {
|
|
||||||
// let s = new Season();
|
|
||||||
|
|
||||||
// s.tmdb_id = data.seasons[i].id
|
|
||||||
// s.temp_parent_tmdb_id = serieId
|
|
||||||
|
|
||||||
// s.season_number = data.seasons[i].season_number
|
|
||||||
// s.overview = data.seasons[i].overview
|
|
||||||
// s.air_date = data.seasons[i].air_date
|
|
||||||
|
|
||||||
// s.poster_path = data.seasons[i].poster_path
|
|
||||||
|
|
||||||
// serie.seasons.push(s)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // todo: getting the episodes info
|
|
||||||
|
|
||||||
// // console.log(serie);
|
|
||||||
// return serie;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// async function insertMovieSerie(tmdb_id, isTvSerie) {
|
|
||||||
// try {
|
|
||||||
// await Execute(`INSERT INTO Movies
|
|
||||||
// (tmdb_id, is_in_library, is_tvserie)
|
|
||||||
// VALUES
|
|
||||||
// ('${tmdb_id}', true, ${isTvSerie});`
|
|
||||||
// );
|
|
||||||
|
|
||||||
// console.log(`Inserted into db: ${tmdb_id}`)
|
|
||||||
// } catch (e) {
|
|
||||||
// console.log(e)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async function updateMovieSerieData(movie) {
|
|
||||||
// let error = false;
|
|
||||||
// try {
|
|
||||||
// await Execute(
|
|
||||||
// `UPDATE Movies SET
|
|
||||||
// tmdb_id = '${movie.tmdb_id}',
|
|
||||||
// imdb_id = '${movie.imdb_id}',
|
|
||||||
// title = '${movie.title}',
|
|
||||||
// original_title = '${movie.original_title}',
|
|
||||||
// overview = '${movie.overview}',
|
|
||||||
// release_date = '${movie.release_date}',
|
|
||||||
// runtime = ${movie.runtime},
|
|
||||||
// status = '${movie.status}',
|
|
||||||
// tmdb_rating = ${movie.tmdb_rating},
|
|
||||||
// poster_path = '${movie.poster_path}',
|
|
||||||
// banner_path = '${movie.banner_path}',
|
|
||||||
// country = '${movie.country}',
|
|
||||||
// budget = ${movie.budget},
|
|
||||||
// revenue = ${movie.revenue},
|
|
||||||
|
|
||||||
// is_tvserie = false
|
|
||||||
|
|
||||||
// WHERE id = ${movie.id};`
|
|
||||||
// )
|
|
||||||
|
|
||||||
// // todo : updating the genres
|
|
||||||
// // todo : updating the tags
|
|
||||||
// // todo : updating the actors
|
|
||||||
|
|
||||||
// if (movie.is_tvserie) {
|
|
||||||
// // todo : the seasons
|
|
||||||
// // todo : the episodes
|
|
||||||
// }
|
|
||||||
|
|
||||||
// } catch (e) {
|
|
||||||
// error = true;
|
|
||||||
// console.log(e)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!error) {
|
|
||||||
// console.log(`Movie/Serie Updated: ${movie.id}:${movie.title}`)
|
|
||||||
// return false;
|
|
||||||
// } else {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// getMovies,
|
|
||||||
|
|
||||||
fetchEntryData,
|
fetchEntryData,
|
||||||
// fetchSerieData,
|
fetchSeasonData,
|
||||||
|
|
||||||
// insertMovieSerie,
|
|
||||||
// updateMovieSerieData,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user