Jump to content

How to do tags in the filesystem


bakaouji
Go to solution Solved by bakaouji,

Recommended Posts

bakaouji

Hi,

Apart from the Metadata manager, how else can I set up tags for files/folders/collections? Which (if any) of the following options exist for tagging:

  1. - nfo / xml files
  2. - Extract from folder or file names
  3. - API?

If so, can I please get a link or further details. I can't find anything on the knowledge base.

I was looking to set up tags like HDR, 4K, Blu-ray, 1080p.

 

Link to comment
Share on other sites

bakaouji

Hi,

I have gotten nfos to work to a certain extent by following the kodi standard. I created a tvshow.nfo in my Altered Carbon folder with this format:

<tvshow>
    <uniqueid type="tmdb" default="true">68421</uniqueid>
    <tag>Blu-ray</tag>
</tvshow>

Folder structure:

Altered Carbon
- Altered Carbon S01
 - Altered Carbon S01E01 
 - Altered Carbon S01E02
- Altered Carbon S02
 - Altered Carbon S02E01
 - Altered Carbon S02E02
- tvshow.nfo

Then I did a refresh of metadata on the Altered Carbon folder. The blu-ray tag is scanning correctly.

However, if I change the nfo to:

<tvshow>
    <uniqueid type="tmdb" default="true">68421</uniqueid>
    <tag>HDR</tag>
</tvshow>

I don't see any tags. The only tags that are working for me are Blu-ray and 720p. 

Do you know why that could be?  I also tried saving HDR from the metadata manager, but it still doesnt persist.

Edited by bakaouji
Link to comment
Share on other sites

  • 2 weeks later...
Happy2Play
On 7/5/2020 at 8:01 PM, Luke said:

That's strange. @Happy2Play are you able to reproduce this?

I just randomly chose a Series and added <tag>HDR</tag> to that Series and did a Scan library files and refreshed the page and that tag appeared for the series.  I then changed the tag to <tag>This is My Changed TAG</tag> and did a Scan library files and refreshed the page and that tag appeared for the series.

This was all manually editing the nfo file.  But tested via the UI and had no issues either.

Link to comment
Share on other sites

  • Solution
bakaouji

Hi Guys,

After i restarted my server, it started working fine, no issues with tags being picked up :)

Sorry, I forgot to post my update here.

 

Link to comment
Share on other sites

Thanks for the update.

Can you mark the thread as answered?

Link to comment
Share on other sites

  • 2 years later...

Sorry, for reviving such an old but I have a few questions on this approach:

1. Does this also work on episode level?
Just did a quick test and it worked fine for TV Show and Season level but on episode level it didn't pick up the <tag> of the NFO I edited.

I think I found the answer in the logs:

2023-01-26 23:27:48.131 Error App: Error reading existng nfo
	*** Error Report ***
	Version: 4.8.0.21
	Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
	Operating system: Linux version 5.15.0-43-generic (buildd@lcy02-amd64-076) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #46-Ubuntu SMP
	Framework: .NET 6.0.8
	OS/Process: x64/x64
	Runtime: opt/emby-server/system/System.Private.CoreLib.dll
	Processor count: 4
	Data path: /var/lib/emby
	Application path: /opt/emby-server/system
	System.Xml.XmlException: System.Xml.XmlException: The 'tag' start tag on line 110 position 2 does not match the end tag of 'episodedetails'. Line 111, position 3.
	   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
	   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
	   at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag)
	   at System.Xml.XmlTextReaderImpl.ParseEndElement()
	   at System.Xml.XmlTextReaderImpl.ParseElementContent()
	   at System.Xml.XmlTextReaderImpl.Skip()
	   at NfoMetadata.Savers.BaseNfoSaver.AddCustomTags(String path, List`1 xmlTagsUsed, XmlWriter writer, ILogger logger, IFileSystem fileSystem)
	   at NfoMetadata.Savers.BaseNfoSaver.Save(BaseItem item, LibraryOptions libraryOptions, Stream stream, String xmlPath)
	Source: System.Private.Xml
	TargetSite: Void Throw(System.Exception)

I probably just misplaced the <tag> information and therefore Emby didn't pick it up, right?

2. Will Emby remove the tags again if I remove them from the NFO?

Edited by neik
Link to comment
Share on other sites

1 hour ago, neik said:

Sorry, for reviving such an old but I have a few questions on this approach:

1. Does this also work on episode level?
Just did a quick test and it worked fine for TV Show and Season level but on episode level it didn't pick up the <tag> of the NFO I edited.

I think I found the answer in the logs:

2023-01-26 23:27:48.131 Error App: Error reading existng nfo
	*** Error Report ***
	Version: 4.8.0.21
	Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
	Operating system: Linux version 5.15.0-43-generic (buildd@lcy02-amd64-076) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #46-Ubuntu SMP
	Framework: .NET 6.0.8
	OS/Process: x64/x64
	Runtime: opt/emby-server/system/System.Private.CoreLib.dll
	Processor count: 4
	Data path: /var/lib/emby
	Application path: /opt/emby-server/system
	System.Xml.XmlException: System.Xml.XmlException: The 'tag' start tag on line 110 position 2 does not match the end tag of 'episodedetails'. Line 111, position 3.
	   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
	   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
	   at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag)
	   at System.Xml.XmlTextReaderImpl.ParseEndElement()
	   at System.Xml.XmlTextReaderImpl.ParseElementContent()
	   at System.Xml.XmlTextReaderImpl.Skip()
	   at NfoMetadata.Savers.BaseNfoSaver.AddCustomTags(String path, List`1 xmlTagsUsed, XmlWriter writer, ILogger logger, IFileSystem fileSystem)
	   at NfoMetadata.Savers.BaseNfoSaver.Save(BaseItem item, LibraryOptions libraryOptions, Stream stream, String xmlPath)
	Source: System.Private.Xml
	TargetSite: Void Throw(System.Exception)

I probably just misplaced the <tag> information and therefore Emby didn't pick it up, right?

2. Will Emby remove the tags again if I remove them from the NFO?

Yes, episodes support tags, and that error looks like you have malformed xml.

Link to comment
Share on other sites

6 hours ago, Luke said:

Yes, episodes support tags, and that error looks like you have malformed xml.

Yeah, I think so.
Will need to do some further testing.

8 hours ago, neik said:

2. Will Emby remove the tags again if I remove them from the NFO?

What about this?

Link to comment
Share on other sites

1 minute ago, neik said:

Yeah, I think so.
Will need to do some further testing.

What about this?

Yes, but there's an open issue where removing all of them won't do it, which @Happy2Play can link you to.

  • Like 1
Link to comment
Share on other sites

4 minutes ago, Luke said:

Yes, but there's an open issue where removing all of them won't do it, which @Happy2Play can link you to.

That reflects my testing as well.
When remoivng the tag I added to the NFO on season level it just got added back again by Emby.

Shouldn't be a big issue for my usecase though.
Thank you!

Link to comment
Share on other sites

Happy2Play
3 hours ago, neik said:
3 hours ago, Luke said:

Yes, but there's an open issue where removing all of them won't do it, which @Happy2Play can link you to.

That reflects my testing as well.
When remoivng the tag I added to the NFO on season level it just got added back again by Emby.

Shouldn't be a big issue for my usecase though.
Thank you!

 

  • Thanks 1
Link to comment
Share on other sites

rbjtech

@neik - have you investigated adding tags via the API ?

It's easy to add/remove them via a curl command or other API integrations - it may be easier than relying on NFO's.   Once added, it then writes the tag's back to the NFO anyway and visa versa.

Something to think about.. :)

  • Like 2
Link to comment
Share on other sites

On 1/27/2023 at 12:46 PM, rbjtech said:

@neik - have you investigated adding tags via the API ?

It's easy to add/remove them via a curl command or other API integrations - it may be easier than relying on NFO's.   Once added, it then writes the tag's back to the NFO anyway and visa versa.

Something to think about.. :)

I had a short view on it but maybe I need to dig deeper.

Will have another look once I can find more time.

  • Thanks 1
Link to comment
Share on other sites

I'm struggling on identifying the files that have portuguese subtitle (internal or external) or portuguese audio available.
Asked ChatGPT got this:

Quote

You can retrieve a list of items by making a GET request to the endpoint /Items with the appropriate query parameters. For example, you can use the IncludeItemTypes parameter to specify that you want to retrieve only video items, and the Fields parameter to specify the fields that you want to include in the response.

To filter the list based on the presence of a Portuguese subtitle, you will need to iterate through the list of items and check the MediaStreams property of each item. The MediaStreams property is an array of objects that contains information about the audio and subtitle streams in the item. Each object in the array has a Type property that indicates whether the stream is an audio or subtitle stream, and a Language property that indicates the language of the stream.

Here's an example of how you could use the curl command to retrieve a list of video items, and filter them by Portuguese subtitles:

curl -X GET -H "Authorization: Bearer ACCESS_TOKEN" "http://emby_server_url:8096/emby/Items?IncludeItemTypes=Video&Fields=MediaStreams" > items.json

(...)

Replaced the ACCESS_TOKEN part with a newly generatd API Key but all I get is "Access token is invalid or expired.".

Any hint is much appreciated.
Thank you!

Link to comment
Share on other sites

Happy2Play
4 hours ago, neik said:

I'm struggling on identifying the files that have portuguese subtitle (internal or external) or portuguese audio available.
Asked ChatGPT got this:

Replaced the ACCESS_TOKEN part with a newly generatd API Key but all I get is "Access token is invalid or expired.".

Any hint is much appreciated.
Thank you!

So something like this

curl -X GET "http://localhost:8098/emby/Items?HasSubtitles=true&Recursive=true&Fields=MediaStreams&IncludeItemTypes=Video&api_key=yourapikey" -H "accept: application/json"

Don't see it in the api but add &SubtitleLanguages=por within the query.  But may be different language codes.

I got this from filtering a library with subtitlelanguage and looked at the query in the server log.  So filtering a library with all your variables will show the query in the server log to better build your command. (debug logging)

Movie with por subs

curl -X GET "http://localhost:8098/emby/Items?HasSubtitles=true&Recursive=true&Fields=MediaStreams&IncludeItemTypes=Movie&SubtitleLanguages=por&api_key=yourapikey" -H "accept: application/json"

all with por subs - remove include type movie

curl -X GET "http://localhost:8098/emby/Items?HasSubtitles=true&Recursive=true&Fields=MediaStreams&SubtitleLanguages=por&api_key=yourapikey" -H "accept: application/json"

Edited by Happy2Play
  • Like 2
Link to comment
Share on other sites

Thank you, Happy! 

Tried to do a little bash script to loop through all the ID's and add the tag "Portuguese" to the items.
Question: Will this do what I want it to do?

#!/bin/bash

curl -X GET "http://localhost:8096/emby/Items?HasSubtitles=true&Recursive=true&Fields=MediaStreams&AudioLanguages=por&api_key=xxxxxxxxxxxxxxxxxxxxx" -H "accept: application/json" > audio.json

curl -X GET "http://localhost:8096/emby/Items?HasSubtitles=true&Recursive=true&Fields=MediaStreams&SubtitleLanguages=por&api_key=xxxxxxxxxxxxxxxxx" -H "accept: application/json" > subtitle.json

IDS_LIST=$(cat audio.json | jq '.Items[] | select(.MediaStreams[].Language == "por") | .Id')

for id in $ID_LIST; do
  curl -X POST "http://localhost:8096/emby/Items/953736/Tags/Add?api_key=xxxxxxxxxxxxxxx" -H "accept: */*" -H "Content-Type: application/json" -d "{\"Tags\":[{\"Name\":\"Portuguese\",\"Id\":\"Portuguese\"}]}"
done

IDS_LIST=$(cat subtitle.json | jq '.Items[] | select(.MediaStreams[].Language == "por") | .Id')

for id in $ID_LIST; do
  curl -X POST "http://localhost:8096/emby/Items/953736/Tags/Add?api_key=xxxxxxxxxxxxxxxx" -H "accept: */*" -H "Content-Type: application/json" -d "{\"Tags\":[{\"Name\":\"Portuguese\",\"Id\":\"Portuguese\"}]}"
done

I would just run it but it might cause some damage (e.g. mislabeling) I would like to avoid. 🙂

PS: ChatGPT isn't that cool after all... haha

Edited by neik
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...