[Script] Generate Episode NFO files

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
User avatar
rednoah
The Source
Posts: 24628
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

[Script] Generate Episode NFO files

Post by rednoah »

This post-processing script will generate Episode NFO files:

Groovy: Select all

{ source, target ->
	if (target.video && type =~ /Episode/) {
		XML(target.dir / target.nameWithoutExtension + '.nfo') {
			episodes.each{ e ->
				episodedetails {
					id(e.info.id)
					showtitle(e.series.name)
					title(e.info.title)

					if (e.group) {
						group(e.group)
					}
					season(e.episode ? e.season : 0)
					episode(e.episode ?: e.special)

					premiered(e.info.airdate)
					plot(e.info.overview)
					thumb(e.info.image)

					e.info.crew.each{ p ->
						if (p.actor) { 
							actor {
								name(p.name)
								if (p.character) {
									role(p.character)
								}
								if (p.image) {
									thumb(p.image)
								}
							}
						} else if (p.director) {
							director(p.name)
						} else if (p.writer || p.department == 'Writing') {
							credits(p.name)
						}
					}

					fileinfo {
						streamdetails {
							target.mediaInfo.Video.each{ s ->
								video {
									codec(s.'Encoded_Library/Name' ?: s.'CodecID/Hint' ?: s.'Format')
									width(s.'Width')
									height(s.'Height')
									bitrate(s.'BitRate')
									duration(s.'Duration'.toFloat().div(60000).round())
								}
							}
							target.mediaInfo.Audio.each{ s ->
								audio {
									codec(s.'CodecID/Hint' ?: s.'Format')
									language(s.'Language/String3')
									channels(s.'Channel(s)_Original' ?: s.'Channel(s)')
									bitrate(s.'BitRate')
								}
							}
							target.mediaInfo.Text.each{ s ->
								subtitle {
									codec(s.'Format')
									language(s.'Language/String3')
								}
							}
						}
					}
				}
			}
		}
	}
}

ScreenshotScreenshot



Console Output: Select all

$ ls
Coupling - S01E01 - Flushed.mkv
Coupling - S01E01 - Flushed.nfo

xml: Select all

<episodedetails>
  <id>213367</id>
  <showtitle>Coupling</showtitle>
  <title>Flushed</title>
  <group>Season 1</group>
  <season>1</season>
  <episode>1</episode>
  <premiered>2000-05-12</premiered>
  <plot>Jeff reckons Steve is still in 'The Zone' with Jane: the time after the breakup when there can still be sex, but he wants to date Susan instead. When he has a meal in a restaurant with Jane, Susan walks in.</plot>
  <thumb>https://image.tmdb.org/t/p/original/gz4IzyXabKUy7f3Z7iBKrQCafZK.jpg</thumb>
  <actor>
    <name>Raji James</name>
    <role>Waiter</role>
    <thumb>https://image.tmdb.org/t/p/original/izS150ZuPJiDiqMbuC2N2QK0uGj.jpg</thumb>
  </actor>
  <credits>Steven Moffat</credits>
  <fileinfo>
    <streamdetails>
      <video>
        <codec>AVC</codec>
        <width>720</width>
        <height>576</height>
        <bitrate>2249115</bitrate>
        <duration>29</duration>
      </video>
      <audio>
        <codec>E-AC-3</codec>
        <language>eng</language>
        <channels>2</channels>
        <bitrate>224000</bitrate>
      </audio>
      <subtitle>
        <codec>UTF-8</codec>
        <language>eng</language>
      </subtitle>
      <subtitle>
        <codec>UTF-8</codec>
        <language>eng</language>
      </subtitle>
    </streamdetails>
  </fileinfo>
</episodedetails>
:idea: Please read the FAQ and How to Request Help.
Post Reply