Skip to content

Commit

Permalink
Merge pull request #736 from kunalparmar/master
Browse files Browse the repository at this point in the history
Add imdbUrl and format Released date
  • Loading branch information
chhoumann authored Nov 3, 2024
2 parents 04b2e04 + 6ced114 commit 846cb1f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docs/docs/Examples/Attachments/movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(",")),
Expand All @@ -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,
Expand Down Expand Up @@ -101,7 +119,7 @@ function linkifyList(list) {
}

function replaceIllegalFileNameCharactersInString(string) {
return string.replace(/[\\,#%&\{\}\/*<>$\'\":@]*/g, '');
return string.replace(/[\\,#%&\{\}\/*<>$\'\":@]*/g, '');
}

async function apiGet(url, data) {
Expand Down

0 comments on commit 846cb1f

Please sign in to comment.