Created
November 14, 2021 23:04
-
-
Save shabegom/5781a0bb1024c88db2118cdb4826cc0a to your computer and use it in GitHub Desktop.
get movie info from IMDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%* | |
async function imdbSearch() { | |
const apiKey = $OMDB_API_KEY; | |
const searchPrompt = await tp.system.prompt("What movie?") | |
const response = await fetch( | |
`https://omdbapi.com/?apikey=${apiKey}&s=${searchPrompt}` | |
).then(res => res.json()) | |
if (response.Search[0]) { | |
const choice = await tp.system.suggester(choice => `${choice.Title} ${choice.Year}`, response.Search, false, "Choose which Movie") | |
if (choice) { | |
let movie = await fetch( | |
`https://omdbapi.com/?apikey=${apiKey}&i=${choice.imdbID}` | |
).then(res => res.json()) | |
if (movie) { | |
const item = [] | |
const title = `# ${movie.Title}` | |
const poster = `<img src=${movie.Poster} width="300px" />` | |
const director = `**Director**:: ${movie.Director.split(",").map(director => `[[${director}]]`).join(", ")}` | |
const writer = `**Writer**:: ${movie.Writer.split(",").map(writer => `[[${writer}]]`).join(", ")}` | |
const cast = `**Starring**:: ${movie.Actors.split(",").map(star => `[[${star}]]`).join(", ")}` | |
const year = `**Year**:: [[${movie.Year}]]` | |
const runtime = `**Runtime**:: ${movie.Runtime}` | |
const genre = `**Genre**:: ${movie.Genre.split(", ").map(genre => "#" + genre).join(", ")}` | |
const plot = `**Plot**:: ${movie.Plot}` | |
const link = `**IMDB**:: [Link](https://www.imdb.com/title/${choice.imdbID}/)` | |
const watched = await tp.system.suggester(["Yes","No"],[true,false],false,"Watched Yet?") | |
const rating = watched ? `**Rating**:: ${await tp.system.suggester(["⭐️","⭐️⭐️","⭐️⭐️⭐️","⭐️⭐️⭐️⭐️","⭐️⭐️⭐️⭐️⭐️"],["⭐️","⭐️⭐️","⭐️⭐️⭐️","⭐️⭐️⭐️⭐️","⭐️⭐️⭐️⭐️⭐️"])}` : undefined | |
const isWatched = watched ? 'watched: Y' : 'watched: N' | |
const frontmatter = ['---',"tags: movie",isWatched,"---"].join("\n") | |
item.push(frontmatter,title,poster,"","### Metadata",director,writer,cast,year,runtime,genre,link,plot) | |
if (rating) { | |
item.push(rating) | |
} | |
const review = watched ? `**Review**:: ${await tp.system.prompt("Review")}` : undefined | |
if (review) { | |
item.push(review) | |
} | |
await tp.file.move("Movies/"+movie.Title) | |
return item.join("\n") | |
} | |
} | |
} | |
} | |
tR += await imdbSearch() | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment