Skip to content

Instantly share code, notes, and snippets.

@RayBB
Created July 25, 2020 01:53
Show Gist options
  • Save RayBB/210a6b84fab05ee0eddd4b6efc332c4f to your computer and use it in GitHub Desktop.
Save RayBB/210a6b84fab05ee0eddd4b6efc332c4f to your computer and use it in GitHub Desktop.
Import episodes to The Movie Database
/*
The Movie Database Episode Importer
This is a small script that can be run in the console of https://www.themoviedb.org/ to create episodes for a show.
*/
function buildFormData(dateString, title, episodeNumber) {
const formData = new FormData();
const air_date = (new Date(dateString)).toISOString();
const data = {
"id": null,
"episode_number": episodeNumber,
"name": title,
"overview": "",
"air_date": air_date,
"locked_fields": ""
}
formData.append('data', JSON.stringify(data));
return new URLSearchParams(formData);
}
async function addNewEpisode(date, title, episodeNumber, seasonNumber) {
console.log(episodeNumber, title, date)
const data = buildFormData(date, title, episodeNumber)
postURL = `https://www.themoviedb.org/tv/106428-the-coolest-places-on-earth/season/${seasonNumber}/remote/episodes?timezone=America/New_York&translate=false`
return fetch(postURL, { method: 'POST', body: data, })
.then(response => { console.log(response.json()) })
.catch(e => { console.log(e) })
}
async function main() {
console.log('main starting');
for (episode of episodes) {
const title = episode[0];
const date = episode[1];
const number = episode[2];
console.log(episode['date'], episode['title'], episode['episodeNumber'], episode['season']);
await addNewEpisode(episode['date'], episode['title'], episode['episodeNumber'], episode['season']);
}
}
let episodes = [] // need to replace this with the output from below script
main()
/*
// Run this script to get a list of episodes from an IMDB page and copy them to your clipboard
outArray = []
document.querySelectorAll(".list_item").forEach(function (div) {
const out = {
date: div.querySelector(".airdate").innerText.replace(".", ""),
title: div.querySelector("strong").innerText,
season: document.querySelector("#episode_top").innerText.replace("Season", "").trim(),
episodeNumber: div.querySelector(".image").innerText.replace(/.*Ep/s, "")
}
outArray.push(out)
})
console.log(outArray)
copy(outArray) // copies to clipboard
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment