mProjectsCode / obsidian-media-db-plugin

A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your vault.
GNU General Public License v3.0
250 stars 30 forks source link

Support disabling default front matter and add support for Templater #119

Closed kelszo closed 9 months ago

kelszo commented 10 months ago

These changes should be completely backwards compatible. The goal of this pull request is to make Media DB more compatible with the Book Search plugin and other plugins. Additionally, to provide a more streamlined and unified way for templating.

Closes: #91

Changes:

Example of usage of changes:

movie.md (template)

---
tags: movie
title: {{ title }}
en_title: {{ englishTitle }}
director: 
{{ LIST:director }}
year: {{ year }}
premiere: "{{ premiere }}"
genres:
{{ LIST:genres }}
duration: "{{ duration }}"
actors: 
{{ LIST:actors }}

cover: {{ image }}
created: <% moment(tp.file.creation_date()).format("YYYY-MM-DDTHH:mm") %>
updated: <% moment(tp.file.creation_date()).format("YYYY-MM-DDTHH:mm") %>
watched: false
rating: 

id: {{ id }}
type: {{ type }}
dataSource: {{ dataSource }}
---

# {{title}}
Writers: <% media.writer.map(author => `[[${author}]]`).join(', ') %>

//```json
<% JSON.stringify(media, null, 4) %>
//```

Resulting markdown: Stalker (1979).md

---
tags: movie
title: Stalker
en_title: Stalker
director:
  - Andrei Tarkovsky
year: 1979
premiere: 17/04/1980
genres:
  - Drama
  - Sci-Fi
duration: 162 min
actors:
  - Alisa Freyndlikh
  - Aleksandr Kaydanovskiy
  - Anatoliy Solonitsyn
cover: https://m.media-amazon.com/images/M/MV5BMDgwODNmMGItMDcwYi00OWZjLTgyZjAtMGYwMmI4N2Q0NmJmXkEyXkFqcGdeQXVyNzY1MTU0Njk@._V1_SX300.jpg
created: 2023-12-28T17:36
updated: 2023-12-28T17:36
watched: false
rating: 
id: tt0079944
type: movie
dataSource: OMDbAPI
---

# Stalker
Writers: [[Arkadiy Strugatskiy]], [[Boris Strugatskiy]], [[Andrei Tarkovsky]]

//```json
{
    "type": "movie",
    "title": "Stalker",
    "englishTitle": "Stalker",
    "year": "1979",
    "dataSource": "OMDbAPI",
    "url": "https://www.imdb.com/title/tt0079944/",
    "id": "tt0079944",
    "userData": {
        "watched": false,
        "lastWatched": "",
        "personalRating": 0
    },
    "plot": "A guide leads two men through an area known as the Zone to find a room that grants wishes.",
    "genres": [
        "Drama",
        "Sci-Fi"
    ],
    "director": [
        "Andrei Tarkovsky"
    ],
    "writer": [
        "Arkadiy Strugatskiy",
        "Boris Strugatskiy",
        "Andrei Tarkovsky"
    ],
    "studio": [
        "N/A"
    ],
    "duration": "162 min",
    "onlineRating": 8.1,
    "actors": [
        "Alisa Freyndlikh",
        "Aleksandr Kaydanovskiy",
        "Anatoliy Solonitsyn"
    ],
    "image": "https://m.media-amazon.com/images/M/MV5BYTAzZmEzZjEtNmIzMS00MzlhLWE0Y2ItNDRlNTQwN2E0MDE4XkEyXkFqcGdeQXVyMzY0MTE3NzU@._V1_SX300.jpg",
    "released": true,
    "streamingServices": [],
    "premiere": "17/04/1980"
}
//```
kelszo commented 9 months ago

I have resolved all your comments.

I agree with the part about code execution. The simpler solution was to shift the heavy lifting and ensure reliability through the Templater plugin. Now, it adds a <%* block at the top (provided the user has the Templater plugin installed), allowing all subsequent Templater commands to access the media variable.

Please let me know if any comment that I marked as resolved is not satisfactorily addressed, and I will gladly make the necessary corrections.

kelszo commented 9 months ago

Done! :)

mProjectsCode commented 9 months ago

can you resolve the conflicts? Then i will merge

kelszo commented 9 months ago

Rebased and ready to merge.

(Fixed a typing error in the latest commit)