owdevel / ytdl-nfo

youtube-dl JSON metadata to Kodi-style NFO converter
The Unlicense
66 stars 17 forks source link

extractor sytax question #29

Open srosorcxisto opened 4 months ago

srosorcxisto commented 4 months ago

Firstly, Thank you to the developers for creating this extraordinarily useful script.

I am attempting to write an extractor that captures a nested list of cast members into the actor section of the NFO spec. The output from yt-dlp looks like this:

"cast": [
  "Penn Jillette",
  "Teller"
],

and the resulting XML should look like this:

<actor>
      <name>Penn Jillette</name>
</actor>
<actor>
      <name>Teller</name>
</actor>

Similarly, I am also trying to add a simple list? For example this info.json:

"categories": [ 
  "Entertainment",
  "Comedy"
],

To these xml nfo tags?

<genre>Entertainment</genre>
<genre>Comedy</genre>

I have been very successful creating extractors for sites that have a simple set of elements, but this is the first time I have tried to make one that involves lists or recursion. So far my attempts have all resulted in "object has no attribute" errors.

My questions are:

  1. Does the script support recursion at all in its current state, or am wasting time trying to add a config like this?
  2. Are simple lists supported, and what is the syntax for those?
  3. Once I figure it out, is there a separate documentation project that I can contribute to, or should I submit a pull request here to help document the custom extractor creation process? I would like to write this up for other users If I can get it working myself. I see this project hasn't been active in a while, but it is still useful and I would like to help is I can.

Thank you!

owdevel commented 3 months ago

Hello @srosorcxisto, sorry for taking so long to get back to you. I've been busy with work and this was a little hobby project I started back in university so it has been neglected for too long.

  1. Unfortunately there is no way to do the recursive tags as you've described currently. We could possibly support limited recursion for your example by using another symbol (e.g. actor+name!: "{cast}").... hmm let me try working that out.

  2. Simple lists are supported, see the following based off your example. Adding the ! will cause the extractor to loop through all elements in the array and create tags for it.

Input Json (date is needed to not crash program, usually included in .info.json):

{
    "categories": [
        "Entertainment",
        "Comedy"
    ],
    "upload_date": "20091225"
}

Custom Extractor:

episodedetails:
  - genre!: "{categories}"

Output:

<?xml version="1.0" ?>
<episodedetails>
    <genre>Entertainment</genre>
    <genre>Comedy</genre>
</episodedetails>
  1. No there isn't a separate documentation project, but would love it if you want to help document this project. I had a space in the README.md for custom extractors if you would like to put it there, but also happy if you feel a separate markdown file in a /docs folder would be good.
owdevel commented 3 months ago

I've added the > operator to create nested tags with lists. See #36 . I'll leave this open issue open if you want to continue discussing 3 and contribute to the readme.