Naming files from local PLEX database
Naming files from local PLEX database
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
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
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
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
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
@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?)
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
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.
Also the request is non-trivial, as searching the Plex DB using the available API for the file name doesn't return a result.
I only work in black and sometimes very, very dark grey. (Batman)
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
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
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
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.
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.
I only work in black and sometimes very, very dark grey. (Batman)
Re: Naming files from local PLEX database
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)
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
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).
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).
I only work in black and sometimes very, very dark grey. (Batman)
Re: Naming files from local PLEX database
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 :arrow:](./images/smilies/icon_arrow.gif)
![Arrow :arrow:](./images/smilies/icon_arrow.gif)
Re: Naming files from local PLEX database
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.
Dynamic class loading is one of the things that won't work with GraalVM though.
I only work in black and sometimes very, very dark grey. (Batman)
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
hey @devster , did you manage to get this working?
Re: Naming files from local PLEX database
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
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')
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
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 ?
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
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.
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
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.
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
try "Export a json format file" and post it here
https://github.com/Tautulli/Tautulli/wi ... dual-files
https://github.com/Tautulli/Tautulli/wi ... dual-files
Re: Naming files from local PLEX database
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
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
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
https://drive.google.com/file/d/10xam8V ... Zu/previewkim wrote: ↑28 Apr 2021, 14:27 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
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
Yep. Should work. @snickers2k Can you export a sample XML file as well? XML would simplify the format code.
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
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![Sad :(](./images/smilies/icon_e_sad.gif)
but you are right.. tautulli isn't exporting in S01E01 style.. instead with "index"-flag for each Seasons and Episodes
![Sad :(](./images/smilies/icon_e_sad.gif)
Re: Naming files from local PLEX database
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:
Example Output:
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.
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 :idea:](./images/smilies/icon_idea.gif)
Re: Naming files from local PLEX database
for S00E00 format replace
with
e.g.
if using "location"
Code: Select all
"${n} - ${s}x${e.pad 2} - ${t}"
Code: Select all
"${n} - S${s.pad(2)}E${e.pad(2)} - ${t}"
btw:Denn sie wissen nicht, was passiert - S03E04 - Folge 12
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
@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.
-
- Posts: 26
- Joined: 05 Nov 2016, 15:13
Re: Naming files from local PLEX database
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
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