Page 1 of 2

Naming files from local PLEX database

Posted: 07 Oct 2017, 12:52
by MaxNZ
Hi,

I have flex database fully populated with correct data for each movie/show. However, file names are all out of wack, so I wanted to use Filebot to rename files based on existing Flex database. So when renaming files I'd like Filebot to lookup my local PLEX database instead of online one.. How can this be done? Thanks

Re: Naming files from local PLEX database

Posted: 07 Oct 2017, 22:05
by rednoah
There is no built-in support.

It's perfectly possible though, by writing a custom format that somehow talks to the database and gives you the correct file path based on that. You'd need some Java/Groovy skills for that.

If you could export your database into an easy-to-read file then it'd be much easier:
viewtopic.php?f=8&t=5373

Re: Naming files from local PLEX database

Posted: 21 Aug 2019, 11:09
by snickers2k
@rednoah, this would be a huge feature request. I'm missing this feature for Years now... :/

I guess many of us fixing incorrect matches directly in Plex. But the original filename is still not appropriate. This is a huge Problem.

(Maybe it could be even useful (especially for cloud-users) to use the Plex-db completely, instead of xattr, to lower hits?)

Re: Naming files from local PLEX database

Posted: 21 Aug 2019, 18:40
by devster
Plex matching doesn't need to be fixed if filename is correct, it's a bit of a chicken-n-egg scenario.
Also the request is non-trivial, as searching the Plex DB using the available API for the file name doesn't return a result.

Re: Naming files from local PLEX database

Posted: 22 Aug 2019, 13:24
by snickers2k
Thats true. But i personally have bad expierence without "-non-strict" mode, since there is not always a Year in the title. For example without -non-strict, Title "Baywatch" , without the Year it's doing nothing because of not being able to differentiate "Baywatch Nights". -non-strict is oppurtunistic enough to match "Baywatch".

But this can fail - and it does.

Another thing would be this example: "Noch.Drei.Maenner.noch.ein.Baby.1987.German.AC3D.DL.720p.WebHD.mkv". Filebot is not able to match this, altough i don't know why, because tmdb can find this title. But anyways, Plex had no Problem to recognize.
So being able to get those information from Plex directly would be great.

This is exactly what i'm looking for, but only embedded in filebot: https://github.com/rieck/perplex

Re: Naming files from local PLEX database

Posted: 22 Aug 2019, 22:54
by devster
The script queries an sqlite3 DB.
I think you might be better off exporting it to another format and try using that to rename your files.
rednoah might be able to help more with this.

Re: Naming files from local PLEX database

Posted: 23 Aug 2019, 03:17
by rednoah
If you could rename the information you need via Groovy, either from the sqlite3 db directly or some text file, then you can use generic file mode, and assemble the destination file name with your own custom code:
viewtopic.php?f=3&t=2072

e.g. if you could write *.nfo files for each movie / episode files, then that would make writing custom formats easy (e.g. similar to the examples listed in the post above)

Re: Naming files from local PLEX database

Posted: 23 Aug 2019, 07:47
by devster
Kodi exports to nfo files, Plex unfortunately doesn't (natively).
Can FileBot script query an sqlite db without any additional dependencies?
If querying is possible, the process could be much simpler, as the DB should contain a line with the precise file name and path, and Plex has an API to update the DB afterwards).

Re: Naming files from local PLEX database

Posted: 23 Aug 2019, 09:23
by rednoah
devster wrote: 23 Aug 2019, 07:47 Can FileBot script query an sqlite db without any additional dependencies?
Not sure. Probably not though, since FileBot doesn't use sqlite internally. The JRE or Groovy runtime might include some sort of built-in API though.

@Grab should work in scripts to retrieve and load additional dependencies at Groovy runtime:
:arrow: http://docs.groovy-lang.org/latest/html ... grape.html
:arrow: http://www.octodecillion.com/groovy-with-sqlite/

Re: Naming files from local PLEX database

Posted: 23 Aug 2019, 10:01
by devster
I'll try, this could actually lead to some pretty interesting formats.
Dynamic class loading is one of the things that won't work with GraalVM though.

Re: Naming files from local PLEX database

Posted: 19 Dec 2019, 00:25
by snickers2k
hey @devster , did you manage to get this working?

Re: Naming files from local PLEX database

Posted: 19 Dec 2019, 09:01
by rednoah
I've got additional thoughts on the topic. Doing everything within FileBot using Java / Groovy code is probably tricky, and hard to re-use with different 3rd party tools (thus there'll be less of a developer community).


It's probably easier to write some sort of local Python web service (Python so you can use Plex APIs which are mostly available in Python) and then have your custom format do HTTP web requests (with some identifying information, i.e. file name) and then have your web service respond with the desired file path computed with your own Python code interfacing with Plex.


e.g. do HTTP request and get response text

Code: Select all

"http://www.example.org/index.html".toURL().getText('UTF-8')

Re: Naming files from local PLEX database

Posted: 27 Apr 2021, 18:30
by snickers2k
okay, have no clue how to do this. but i think it would well worth it to have plex db working with filebot.
tautulli supports exporting in various formats...

any chance for a working guide or even working plugin/script inside filebot ?

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 10:16
by rednoah
Perhaps someone could write a standalone Python tool that interfaces with Plex and the exports FileBot-style Extended Attributes for each file? We could then use Local Xattr Mode in a second step to process the files with filebot as usual.

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 13:09
by snickers2k
xattr is a different thing.. not supported by tautulli nor rclone ..

this is what we got

https://github.com/Tautulli/Tautulli/wi ... rter-Guide
csv, json, xml, m3u8

https://github.com/Tautulli/Tautulli/wi ... APIs-Guide
Cloudinary, MaxMind

but i'm obviously the wrong person.
but i'm sure it would bring a lot of new users to filebot, since this would be just ultimate combination of plex+filebot.

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 14:27
by kim
try "Export a json format file" and post it here
https://github.com/Tautulli/Tautulli/wi ... dual-files

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 15:46
by rednoah
If Tautulli can help you export everything as easy-to-read JSON file, then it might be possible to write a Plain File Format that references this file for each file {f} and then generates the new path based on the information in the JSON record.


EDIT:

The Rename files based on sibling XML files example would be similar in concept, but of course completely different in code:
viewtopic.php?t=2072

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 16:16
by snickers2k
kim wrote: 28 Apr 2021, 14:27 try "Export a json format file" and post it here
https://github.com/Tautulli/Tautulli/wi ... dual-files
https://drive.google.com/file/d/10xam8V ... Zu/preview

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 16:53
by kim
Looks like most info is there but missing episode id e.g. E04 in S03E04 but the file path maybe has this info like here:

Code: Select all

    {
        "addedAt": "2020-08-23T22:18:35",
        "audienceRating": 7.0,
        "contentRating": null,
        "duration": null,
        "durationHuman": "0",
        "leafCount": 3,
        "librarySectionID": 63,
        "librarySectionKey": "/library/sections/63",
        "librarySectionTitle": "Spielshows",
        "network": null,
        "originalTitle": null,
        "originallyAvailableAt": "2021-04-15",
        "rating": null,
        "ratingKey": 698597,
        "showOrdering": null,
        "studio": null,
        "summary": "Die Show ist eine spannende Mischung der Genres Spiel- und Improvisations-Show. Thomas Gottschalk, Günther Jauch und Barbara Schöneberger treten in diversen verrückten und haarsträubenden Spielen gegen prominente Gegner an. Welche Promis es in der jeweiligen Show sind, erfahren die TV-Größen allerdings erst zu Beginn der Sendung. Auch wer die Moderation der spaßigen Veranstaltung übernehmen soll, bleibt bis Spielbeginn ein Geheimnis ...",
        "tagline": "Die Jauch-Gottschalk-Schöneberger-Show",
        "title": "Denn sie wissen nicht, was passiert",
        "titleSort": "Denn sie wissen nicht, was passiert",
        "type": "show",
        "userRating": null,
        "year": 2021,
        "guids": [
            {
                "id": "tmdb://123336"
            }
        ],
        "seasons": [
            {
                "addedAt": "2020-08-23T22:18:35",
                "art": "/library/metadata/698597/art/1619209215",
                "artBlurHash": null,
                "guid": "plex://season/6079b88d45121a0036606bf0",
                "index": 3,
                "key": "/library/metadata/698598",
                "lastViewedAt": null,
                "leafCount": 1,
                "librarySectionID": 63,
                "librarySectionKey": "/library/sections/63",
                "librarySectionTitle": "Spielshows",
                "parentGuid": "plex://show/6079b88c45121a0036606bc9",
                "parentIndex": "1",
                "parentKey": "/library/metadata/698597",
                "parentRatingKey": 698597,
                "parentTheme": null,
                "parentThumb": "/library/metadata/698597/thumb/1619209215",
                "parentTitle": "Denn sie wissen nicht, was passiert",
                "ratingKey": 698598,
                "summary": "Drei ahnungslose Moderatoren ohne Plan, die sich neuen Spiel- und Quizrunden mit ungewissem Ausgang stellen: Barbara Schöneberger, Thomas Gottschalk und Günther Jauch tanzen in drei Shows wieder auf dem Vulkan.",
                "thumb": "/library/metadata/698598/thumb/1619209216",
                "thumbBlurHash": "LNE]$M}FWUR+61E|NusCM$wLw{X5",
                "title": "Staffel 3",
                "titleSort": "Staffel 3",
                "type": "season",
                "updatedAt": "2021-04-23T22:20:16",
                "userRating": null,
                "episodes": [
                    {
                        "addedAt": "2020-08-23T22:18:35",
                        "duration": 13235520,
                        "durationHuman": "3 hrs 41 mins",
                        "grandparentTitle": "Denn sie wissen nicht, was passiert",
                        "librarySectionID": 63,
                        "librarySectionKey": "/library/sections/63",
                        "librarySectionTitle": "Spielshows",
                        "locations": [
                            "/mnt/media/Spielshows/Denn sie wissen nicht was passiert/Denn.sie.wissen.nicht.was.passiert.S03E04.GERMAN.1080p.HDTV.x264-aWake-xpost/awa-desiwiniwapas03e04xd.mkv"
                        ],
                        "originallyAvailableAt": "2020-08-22",
                        "parentTitle": "Staffel 3",
                        "rating": null,
                        "ratingKey": 698599,
                        "summary": "Ohne Sicherheitsnetz und ohne Proben- dafür aber mit Köpfchen, einer gehörigen Portion Spielfreude und mit vollem Körpereinsatz. Die zwölfte Show von „Denn sie wissen nicht, was passiert! Die Jauch-Gottschalk-Schöneberger-Show“ präsentiert RTL heute live.",
                        "title": "Folge 12",
                        "titleSort": "Folge 12",
                        "type": "episode",
                        "updatedAt": "2021-04-26T08:13:22",
                        "userRating": null,
                        "year": null,
                        "guids": [
                            {
                                "id": "tmdb://2875152"
                            }
                        ],
                        "media": [
                            {
                                "aspectRatio": 1.78,
                                "audioChannels": 2,
                                "audioCodec": "ac3",
                                "bitrate": 8387,
                                "container": "mkv",
                                "duration": 13235520,
                                "hdr": false,
                                "height": 1080,
                                "title": null,
                                "videoCodec": "h264",
                                "videoFrameRate": "PAL",
                                "videoProfile": "high",
                                "videoResolution": "1080",
                                "width": 1920,
                                "parts": [
                                    {
                                        "container": "mkv",
                                        "file": "/mnt/media/Spielshows/Denn sie wissen nicht was passiert/Denn.sie.wissen.nicht.was.passiert.S03E04.GERMAN.1080p.HDTV.x264-aWake-xpost/awa-desiwiniwapas03e04xd.mkv",
                                        "key": "/library/parts/1398141/1598213915/file.mkv",
                                        "size": 13876115489,
                                        "sizeHuman": "12.92 GB",
                                        "audioStreams": [
                                            {
                                                "audioChannelLayout": "stereo",
                                                "bitrate": 192,
                                                "channels": 2,
                                                "codec": "ac3",
                                                "default": true,
                                                "displayTitle": "Deutsch (AC3 Stereo)",
                                                "extendedDisplayTitle": "Deutsch (AC3 Stereo)",
                                                "language": "Deutsch",
                                                "languageCode": "ger",
                                                "samplingRate": 48000,
                                            }
                                        ],
                                        "videoStreams": [
                                            {
                                                "bitDepth": 8,
                                                "bitrate": 8195,
                                                "codec": "h264",
                                                "codedHeight": 1088,
                                                "codedWidth": 1920,
                                                "displayTitle": "1080p (H.264)",
                                                "extendedDisplayTitle": "1080p (H.264)",
                                                "frameRate": 25.0,
                                                "language": "English",
                                                "languageCode": "eng",
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ],
                "guids": [
                    {
                        "id": "tmdb://190615"
                    }
                ]
            }
        ]
    }

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 17:09
by rednoah
Yep. Should work. @snickers2k Can you export a sample XML file as well? XML would simplify the format code.

Re: Naming files from local PLEX database

Posted: 28 Apr 2021, 21:57
by snickers2k
https://drive.google.com/file/d/1lqg17X ... Pq4Lw/view

but you are right.. tautulli isn't exporting in S01E01 style.. instead with "index"-flag for each Seasons and Episodes :(

Re: Naming files from local PLEX database

Posted: 29 Apr 2021, 09:24
by rednoah
e.g. Plain File Format: read xml file, find part element where the file attribute matches the current file path, navigate xml and extract fields, generate destination file path:

Code: Select all

{
	// find <part> element for the file at hand
	def dom = xml('/path/to/library.xml')
	def part = dom.show.season.episode.media.part.find{ it.'@file' == f }

	// navigate parent elements and access attributes
	def n = part.'..'.'..'.'..'.'..'.'@title'.text()
	def s = part.'..'.'..'.'..'.'@index'.text()
	def e = part.'..'.'..'.'@index'.text()
	def t = part.'..'.'..'.'@title'.text()

	// generate file name
	"${n} - ${s}x${e.pad 2} - ${t}"
}

Example Output:

Code: Select all

Schlag den Star - 13x01 - Pascal Hens vs. Kevin Großkreutz

:idea: Note that the file path {f} must match exactly the <part file="/path/to/file"> value so that we can find the right <part> element. From there it's just a matter of navigating the DOM tree to extract whatever information we need for renaming.

Re: Naming files from local PLEX database

Posted: 29 Apr 2021, 19:38
by kim
for S00E00 format replace

Code: Select all

"${n} - ${s}x${e.pad 2} - ${t}"
with

Code: Select all

"${n} - S${s.pad(2)}E${e.pad(2)} - ${t}"
e.g.
Denn sie wissen nicht, was passiert - S03E04 - Folge 12
btw:
if using "location"

Code: Select all

{
	// find <part> element for the file at hand
	def dom = xml('/path/to/library.xml')
	def part = dom.show.season.episode.location.find{ it == f }

	// navigate parent elements and access attributes
	def n = part.'..'.'..'.'..'.'@title'.text()
	def s = part.'..'.'..'.'@index'.text()
	def e = part.'..'.'@index'.text()
	def t = part.'..'.'@title'.text()

	// generate file name
	"${n} - S${s.pad(2)}E${e.pad(2)} - ${t}"	
}

Re: Naming files from local PLEX database

Posted: 30 Apr 2021, 09:08
by rednoah
@snickers2k Please let us know which code you end up with. Possibly write a tutorial thread for the next guy if it works well for you.

Re: Naming files from local PLEX database

Posted: 01 May 2021, 20:35
by snickers2k
yeah i'm sorry but i found out too late that there is no filepath exported to work with :/

i have plex exported nfo files for every single file.. and now only have to figure out how to force filebot to read them (because in a short test, it didnt worked).
think thats the best option for others who read this and want the files recognized the way they are in plex