Skip to content

Commit 846cb1f

Browse files
authored
Merge pull request #736 from kunalparmar/master
Add imdbUrl and format Released date
2 parents 04b2e04 + 6ced114 commit 846cb1f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/docs/Examples/Attachments/movies.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const log = msg => console.log(msg);
33

44
const API_KEY_OPTION = "OMDb API Key";
55
const API_URL = "https://www.omdbapi.com/";
6+
const IMDB_BASE_URL = "https://www.imdb.com/title/";
67

78
module.exports = {
89
entry: start,
@@ -50,6 +51,8 @@ async function start(params, settings) {
5051

5152
QuickAdd.variables = {
5253
...selectedShow,
54+
imdbUrl: IMDB_BASE_URL + selectedShow.imdbID,
55+
Released: formatDateString(selectedShow.Released),
5356
actorLinks: linkifyList(selectedShow.Actors.split(",")),
5457
genreLinks: linkifyList(selectedShow.Genre.split(",")),
5558
directorLink: linkifyList(selectedShow.Director.split(",")),
@@ -67,6 +70,21 @@ function formatTitleForSuggestion(resultItem) {
6770
return `(${resultItem.Type === "movie" ? "M" : "TV"}) ${resultItem.Title} (${resultItem.Year})`;
6871
}
6972

73+
function formatDateString(dateString) {
74+
const [day, month, year] = dateString.split(' ');
75+
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
76+
const monthIndex = monthNames.indexOf(month);
77+
78+
const date = new Date(year, monthIndex, day);
79+
80+
// Format the date as yyyy-mm-dd
81+
const formattedYear = date.getFullYear();
82+
const formattedMonth = String(date.getMonth() + 1).padStart(2, '0');
83+
const formattedDay = String(date.getDate()).padStart(2, '0');
84+
85+
return `${formattedYear}-${formattedMonth}-${formattedDay}`;
86+
}
87+
7088
async function getByQuery(query) {
7189
const searchResults = await apiGet(API_URL, {
7290
"s": query,
@@ -101,7 +119,7 @@ function linkifyList(list) {
101119
}
102120

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

107125
async function apiGet(url, data) {

0 commit comments

Comments
 (0)