From 613eacc6067e45ab81b04bcaed2833905993a0ac Mon Sep 17 00:00:00 2001 From: Kunal Parmar Date: Sun, 15 Sep 2024 01:00:13 -0700 Subject: [PATCH 1/2] Add imdbURL and format Released date --- docs/docs/Examples/Attachments/movies.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/docs/Examples/Attachments/movies.js b/docs/docs/Examples/Attachments/movies.js index 66b0345..b0914b4 100644 --- a/docs/docs/Examples/Attachments/movies.js +++ b/docs/docs/Examples/Attachments/movies.js @@ -3,6 +3,7 @@ const log = msg => console.log(msg); const API_KEY_OPTION = "OMDb API Key"; const API_URL = "https://www.omdbapi.com/"; +const IMDB_BASE_URL = "https://www.imdb.com/title/"; module.exports = { entry: start, @@ -50,6 +51,8 @@ async function start(params, settings) { QuickAdd.variables = { ...selectedShow, + imdbURL: IMDB_BASE_URL + selectedShow.imdbID, + Released: formatDateString(selectedShow.Released), actorLinks: linkifyList(selectedShow.Actors.split(",")), genreLinks: linkifyList(selectedShow.Genre.split(",")), directorLink: linkifyList(selectedShow.Director.split(",")), @@ -67,6 +70,21 @@ function formatTitleForSuggestion(resultItem) { return `(${resultItem.Type === "movie" ? "M" : "TV"}) ${resultItem.Title} (${resultItem.Year})`; } +function formatDateString(dateString) { + const [day, month, year] = dateString.split(' '); + const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + const monthIndex = monthNames.indexOf(month); + + const date = new Date(year, monthIndex, day); + + // Format the date as yyyy-mm-dd + const formattedYear = date.getFullYear(); + const formattedMonth = String(date.getMonth() + 1).padStart(2, '0'); + const formattedDay = String(date.getDate()).padStart(2, '0'); + + return `${formattedYear}-${formattedMonth}-${formattedDay}`; +} + async function getByQuery(query) { const searchResults = await apiGet(API_URL, { "s": query, @@ -101,7 +119,7 @@ function linkifyList(list) { } function replaceIllegalFileNameCharactersInString(string) { - return string.replace(/[\\,#%&\{\}\/*<>$\'\":@]*/g, ''); + return string.replace(/[\\,#%&\{\}\/*<>$\'\":@]*/g, ''); } async function apiGet(url, data) { From 6ced1144cb4734a98046c034a05c127f966f0d3b Mon Sep 17 00:00:00 2001 From: Kunal Parmar Date: Sun, 15 Sep 2024 10:11:41 -0700 Subject: [PATCH 2/2] Use camelCase convention --- docs/docs/Examples/Attachments/movies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/Examples/Attachments/movies.js b/docs/docs/Examples/Attachments/movies.js index b0914b4..19debbb 100644 --- a/docs/docs/Examples/Attachments/movies.js +++ b/docs/docs/Examples/Attachments/movies.js @@ -51,7 +51,7 @@ async function start(params, settings) { QuickAdd.variables = { ...selectedShow, - imdbURL: IMDB_BASE_URL + selectedShow.imdbID, + imdbUrl: IMDB_BASE_URL + selectedShow.imdbID, Released: formatDateString(selectedShow.Released), actorLinks: linkifyList(selectedShow.Actors.split(",")), genreLinks: linkifyList(selectedShow.Genre.split(",")),