YAML not recognised as property // import movie from TMdb

What I’m trying to do

Hey there, so I’ve been trying to import my movies from TMdb into Obsidian while using the QuickAdd-Plugin. Therefore I modified the movies.js by chhoumann. So far everything went rather smooth. However, when I import a movie the information is not recognised as different properties or properties at all. Instead the information just shows up on top as the note as plain text.

Things I have tried

ChatGPT and I spend the afternoon together - I’m new to js - and I couldn’t figure out where the issue is. I tried using a template, but it didn’t work. I tried copying script from other plugins which achieve the import into properties. But for some reason it’s not working.

let QuickAdd;
let Settings;

async function start(params, settings) {
    QuickAdd = params;
    Settings = settings;

    const query = await QuickAdd.quickAddApi.inputPrompt("Film titel: ");
    if (!query) {
        notice("No query entered.");
        throw new Error("No query entered.");
    }

    let selectedShow;

    // TMDb: Search and use film ID
    const results = await getByQuery(query);
    const choice = await QuickAdd.quickAddApi.suggester(results.map(formatTitleForSuggestion), results);
    if (!choice) {
        notice("No choice selected.");
        throw new Error("No choice selected.");
    }

    selectedShow = await getByTmdbId(choice.id);

    // Set the variables for the template
    const templateVariables = {
        title: selectedShow.title || selectedShow.name,
        originaltitle: selectedShow.original_title || selectedShow.original_name,
        subtitle: selectedShow.title || selectedShow.name,
        directors: selectedShow.directors.map(director => director.name).join(", "),
        writers: selectedShow.writers ? selectedShow.writers.join(", ") : "N/A",
        actors: selectedShow.cast.map(actor => actor.name).join(", "),
        geschlecht: "N/A", // Platzhalter, kann dynamisch ergänzt werden
        genre: selectedShow.genres.map(genre => genre.name).join(", "),
        studio: selectedShow.production_companies.map(company => company.name).join(", "),
        year: selectedShow.release_date ? selectedShow.release_date.split("-")[0] : "N/A",
        totalTime: selectedShow.runtime || "N/A",
        coverUrl: `Sonstiges/Bildersammlung/${replaceIllegalFileNameCharactersInString(selectedShow.title || selectedShow.name)}-poster.jpg`, // Angepasster Pfad zum Ordner
        status: selectedShow.status || "ungesehen",
        country: selectedShow.production_countries.map(country => country.name).join(", "),
        originalsprache: selectedShow.original_language.toUpperCase(),
        gesehenAuf: "N/A", // Platzhalter, kann dynamisch ergänzt werden
        meins: false,
        favorit: false,
        begonnen: "N/A",
        beendet: "N/A",
        bewertet: "☆☆☆☆☆", // Beispielwert
        tags: ["film"]
    };

    // Create new note with adapted variables in Obsidian format
    const noteTitle = templateVariables.title;
    const noteContent = `
---
title: "${templateVariables.title}"
originaltitle: "${templateVariables.originaltitle}"
subtitle: "${templateVariables.subtitle}"
directors:
  - "${templateVariables.directors}"
writers:
  - "${templateVariables.writers}"
actors:
  - "${templateVariables.actors}"
geschlecht:
  - weiblich
  - männlich
  - nonbinär
  - trans
genre:
  - "${templateVariables.genre}"
studio:
  - "${templateVariables.studio}"
year: "${templateVariables.year}"
totalTime: "${templateVariables.totalTime}"
coverUrl: "${templateVariables.coverUrl}"
status:
  - ungesehen
  - beendet
  - nochmal
country: "${templateVariables.country}"
originalsprache: "${templateVariables.originalsprache}"
gesehenAuf: "${templateVariables.gesehenAuf}"
meins: ${templateVariables.meins}
favorit: ${templateVariables.favorit}
begonnen: "${templateVariables.begonnen}"
beendet: "${templateVariables.beendet}"
bewertet: "${templateVariables.bewertet}"
tags:
  - film
---

# film informationen
- **Titel:** ${templateVariables.title}
- **Jahr:** ${templateVariables.year}
- **Genre:** ${templateVariables.genre}
- **Regisseur:** ${templateVariables.directors}
- **Drehbuchautor:** ${templateVariables.writers}
- **Schauspieler:** ${templateVariables.actors}
`;

    // Use native Obsidian function app.vault.create()
    const folder = "Importt";  // Folder for the note
    const path = `${folder}/${replaceIllegalFileNameCharactersInString(noteTitle)}.md`;

    try {
        await app.vault.create(path, noteContent); // Erstellt die Notiz
        notice(`Neue Notiz für "${templateVariables.title}" wurde erfolgreich erstellt!`);
    } catch (err) {
        notice("Fehler beim Erstellen der Notiz: " + err.message);
    }
}

So, if anyone has any idea how I can solve this riddle, I’d be eternally grateful ^o^/

I’ve never used QuickAdd or its script and this is all just a guess/shot in the dark but for YAML/Frontmatter/Properties to be recognized as such the very first --- of the YAML/frontmatter/Properties needs to be placed on the very 1st line of the note :blush:

And I’m not sure this:

const noteContent = `
---
title: "${templateVariables.title}"

// rest of the script/template ... 

… actually puts the --- on the very 1st line :woman_shrugging:

This:

const noteContent = `---
title: "${templateVariables.title}"

// rest of the script/template ... 

… maybe, potentially, could work :sweat_smile: :woman_shrugging: ?

1 Like

Oh wow, thanks. That actually solved it. Thank you sooo muuch! (≧∇≦)ノ

1 Like