MKV Tags

Get answers about using MediaMonkey 4 for Windows.

Moderator: Gurus

danhinsley

MKV Tags

Post by danhinsley »

I wrote a tagging program, and I'm trying to get it to work with MediaMonkey. I looked at http://www.mediamonkey.com/wiki/index.p ... erties/4.0 and wrote the tags appropriately (they are all SimpleTags inside one Tags atom). But I can't seem to set the Type (using the CONTENT_TYPE tag), Series (using COLLECTION.TITLE), Series or Episode numbers (SEASON.PART_NUMBER and EPISODE.PART_NUMBER), Screenwriter (SCREENPLAY_BY), Grouping (COLLECTION.COMMENT). Can you tell me if these are the correct tag names?
MMFrLife
Posts: 2894
Joined: Fri Oct 26, 2012 9:04 pm
Location: MM Forum

Re: MKV Tags

Post by MMFrLife »

Sounds awesome! If you can get the results to read properly in MM, would you be willing to share your
tagging program? :)
Last edited by MMFrLife on Tue Nov 09, 2021 1:49 pm, edited 2 times in total.
MM user since 2003 (lifetime lic. 2012) "Trying to imagine life without music gives me a headache"
Top 2 scripts: RegExp Find & Replace (e.v.) and Magic Nodes (e.v.) ZvezdanD's scripts site
Please take a moment to read the bottom of the linked page to support the one and only - ZvezdanD! (the "originator" since 2006).
MMW 4.1.31.1919; 5.0.4.2690 || back it up...frequently!
|| software for power users: "Q-Dir" (free alt. to explorer) and file/folder renamer: "ReNamer" (den4b)
"The absurd is the essential concept and the first truth"
😜
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: MKV Tags

Post by rivorson »

Change Screenwriter to Track.WRITTEN_BY and they'll all be correct. I don't think Type is read from mkv files though so I don't think you'll get that one to work.

I wrote a script that calls mkvPropEdit to do the tagging, or if mkvPropEdit isn't installed creates an xml file that can be written to the tags using alternative software.

mkvPropEdit is part of mkvToolNix which can be downloaded here:
https://mkvtoolnix.download/

After installing the script, select your files then call mkvTagger from the script menu.

Code: Select all

' MediaMonkey Script
'
' NAME: mkvTagger 1.0
' AUTHOR: rivorson
' DATE : 04 May 2017
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' [mkvTagger]
' FileName=mkvTagger.vbs
' ProcName=TagSelectedFiles
' Order=5
' DisplayName=mkvTagger
' Description=Tag MKV files using mkvPropEdit if installed, or create XML tag files to be used by external software
' Language=VBScript
' ScriptType=0
'

Option Explicit

Dim PostponedTrackItm : Set PostponedTrackItm = Nothing
Const ShowReportAfterTagging = True


Sub TagSelectedFiles()
	'called whenever the user calls this script from the Scripts menu
	'get track list
	Dim ConfirmationResponse: ConfirmationResponse = 0
	Dim tracklist : Set tracklist = SDB.SelectedSongList
	If tracklist.Count = 0 Then 
		Set tracklist = SDB.AllVisibleSongList 
	End If 
	If tracklist.Count = 0 Then 
		Call SDB.MessageBox("Select tracks to be tagged.", mtError, Array(mbOk)) 
		Exit Sub 
	Else
		ConfirmationResponse = SDB.MessageBox("Tag "&tracklist.Count&" tracks?", mtConfirmation, Array(mbYes,mbCancel))  
		If (ConfirmationResponse = mrYes) Then
			TagMKV tracklist, Not ShowReportAfterTagging, FALSE
		End If
	End If 
End Sub

Sub TagMKV(tracklist, SuppressReport, Silent)
	
	Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
	If Not Silent Then
		'progress bar
		Dim bar : Set bar = SDB.Progress
		bar.MaxValue = tracklist.Count
		bar.Text = "mkvTagger: Initialising."
	End If
	SDB.ProcessMessages
	
	'mkvPropEdit file path for tagging
	Dim mkvPropEditPath
	mkvPropEditPath = GetMkvPropEditPath()
	
	If Not fso.FileExists(mkvPropEditPath) Then
		'failed to locate mkvPropEdit.exe
		'proceed no further
		If Not SuppressReport Then SDB.MessageBox "mkvTagger requires mkvPropEdit.exe to function.", mtInformation, Array(mbOk)
		If Not Silent Then
			bar.Text = "mkvTagger: Cannot locate mkvPropEdit.exe"
			SDB.Tools.Sleep 1500
		End If
		Exit Sub
	End If
	
	'create the shell object required to execute the command line
	Dim wshShell : Set wshShell = CreateObject("WScript.Shell")
	'gather the file paths for temporary files
	Dim mkvPropEditOutputFilePath : mkvPropEditOutputFilePath = SDB.TemporaryFolder & "\mkvTaggerOutput.txt" 'output file used to capture the results of the mkvPropEdit process instead of reading it from the console
	Dim TagFilePath : TagFilePath = SDB.TemporaryFolder & "\mkvTags.xml" 'path of the temporary xml file used to tag the files
	
	
	'variables to count the number of files processed
	Dim NonMKVCount 'number of selected files which are not mkv files and ignored
	Dim WriteErrorCount 'number of files for which tagging is attempted but results in an error or warning
	Dim TagSuccessCount 'number of files successfully tagged
	
	'tag each track
	Dim i : i = 0
	For i = 0 To tracklist.Count-1
		If Not Silent Then
			'progress bar
			bar.Text = "mkvTagger: Tagging track "&(i+1)&" of "&(tracklist.Count)&"."
			bar.Increase
		End If
		SDB.ProcessMessages
		
		Dim itm : Set itm = tracklist.Item(i)
		
		
		On Error Resume Next
		If itm.ID <> SDB.Player.CurrentSong.ID OR NOT SDB.Player.IsPlaying Then 'don't write tags for the track that is currently playing because it will interrupt the playback
			On Error Goto 0
			
			If right(itm.Path,3) = "mkv" Then
				'MKV collection, season, and track level arrays. Each array is two dimensional to contain tag and value.
				Dim CollectionLevel : CollectionLevel = Array()
				Dim SeasonLevel : SeasonLevel = Array()
				Dim TrackLevel : TrackLevel = Array()
				
				
				'create different XML elements depending on track type
				Select Case itm.TrackType
				Case 4, 7 'music video, video podcast
					
					'Season level data
					If itm.DiscNumber <> vbNullString Then AddToLevelArray SeasonLevel, "PART_NUMBER", itm.DiscNumber 'Disc number
					If itm.AlbumArtistName <> vbNullString Then AddToLevelArray SeasonLevel, "AUTHOR", itm.AlbumArtistName 'album artist
					If itm.AlbumName <> vbNullString Then AddToLevelArray SeasonLevel, "TITLE", itm.AlbumName 'album
					
					'Track level data
					If itm.ArtistName <> vbNullString Then AddToLevelArray TrackLevel, "AUTHOR", itm.ArtistName 'artist
					If itm.TrackOrder > 0 Then AddToLevelArray TrackLevel, "PART_NUMBER", itm.TrackOrder 'track number
					If itm.MusicComposer <> vbNullString Then AddToLevelArray TrackLevel, "COMPOSER", itm.MusicComposer 'Composer
					If itm.Conductor <> vbNullString Then AddToLevelArray TrackLevel, "CONDUCTOR", itm.Conductor 'CONDUCTOR
					If itm.Lyricist <> vbNullString Then AddToLevelArray TrackLevel, "LYRICIST", itm.Lyricist 'lyricist / writer
					If itm.OriginalArtist <> vbNullString Then AddToLevelArray TrackLevel, "ORIGINAL.AUTHOR", itm.OriginalArtist 'original artist
					If itm.OriginalYear > 0 Then
						Dim TrackOriginalDate : TrackOriginalDate = itm.OriginalYear
						If itm.OriginalMonth > 0 Then
							If itm.OriginalMonth < 10 Then TrackOriginalDate = TrackOriginalDate & "-0" & itm.OriginalMonth Else TrackOriginalDate = TrackOriginalDate & "-" & itm.OriginalMonth
							If itm.OriginalDay > 0 Then
								If itm.OriginalDay < 10 Then TrackOriginalDate = TrackOriginalDate & "-0" & itm.OriginalDay Else TrackOriginalDate = TrackOriginalDate & "-" & itm.OriginalDay
							End If
						End If
						AddToLevelArray TrackLevel, "ORIGINAL.DATE", TrackOriginalDate 'original date
					End If
					If itm.OriginalLyricist <> vbNullString Then AddToLevelArray TrackLevel, "ORIGINAL.LYRICIST", itm.OriginalLyricist 'original lyricist / original writer
					If itm.OriginalTitle <> vbNullString Then AddToLevelArray TrackLevel, "ORIGINAL.TITLE", itm.OriginalTitle 'original title
					If itm.BPM <> vbNullString Then AddToLevelArray TrackLevel, "BPM", itm.BPM 'beats per minute
					
				Case 5, 6 'video, TV
					'Collection level data
					If itm.Series <> vbNullString Then AddToLevelArray CollectionLevel, "TITLE", itm.Series 'Series name
					
					'Season level data
					If itm.SeasonNumber <> vbNullString Then AddToLevelArray SeasonLevel, "PART_NUMBER", itm.SeasonNumber 'season number
					
					'Track level data
					If itm.EpisodeNumber <> vbNullString Then AddToLevelArray TrackLevel, "PART_NUMBER", itm.EpisodeNumber 'episode number
					If itm.Director <> vbNullString Then AddToLevelArray TrackLevel, "DIRECTOR", itm.Director
					If itm.Lyricist <> vbNullString Then AddToLevelArray TrackLevel, "WRITTEN_BY", itm.Lyricist
					If itm.Actors <> vbNullString Then AddToLevelArray TrackLevel, "ACTOR", itm.Actors
				End Select
				
				'data for all video types
				
				'Collection level data
				If itm.Grouping <> vbNullString Then AddToLevelArray CollectionLevel, "COMMENT", itm.Grouping 'grouping [stored in series description tag]
				
				'Track level data
				If itm.Title <> vbNullString Then AddToLevelArray TrackLevel, "TITLE", itm.Title 'track title
				If itm.Year > 0 Then 
					Dim TrackDate : TrackDate = itm.Year
					If itm.Month > 0 Then
						If itm.Month < 10 Then TrackDate = TrackDate & "-0" & itm.Month Else TrackDate = TrackDate & "-" & itm.Month
						If itm.Day > 0 Then
							If itm.Day < 10 Then TrackDate = TrackDate & "-0" & itm.Day Else TrackDate = TrackDate & "-" & itm.Day
						End If
					End If
					AddToLevelArray TrackLevel, "DATE_RECORDED", TrackDate 'for some reason MediaMonkey uses Date Recorded for the date field and Date Released for Original Date
				End If
				If itm.Genre <> vbNullString Then AddToLevelArray TrackLevel, "GENRE", itm.Genre
				If itm.Producer <> vbNullString Then AddToLevelArray TrackLevel, "PRODUCER", itm.Producer
				If itm.Publisher <> vbNullString Then AddToLevelArray TrackLevel, "PUBLISHER", itm.Publisher
				If itm.Copyright <> vbNullString Then AddToLevelArray TrackLevel, "COPYRIGHT", itm.Copyright
				If itm.ParentalRating <> vbNullString Then AddToLevelArray TrackLevel, "LAW_RATING", itm.ParentalRating
				If itm.Comment <> vbNullString Then AddToLevelArray TrackLevel, "SUMMARY", itm.Comment
				If itm.Rating > 0 Then AddToLevelArray TrackLevel, "RATING", itm.Rating
				If itm.ISRC <> vbNullString Then AddToLevelArray TrackLevel, "RATING", itm.ISRC
				If itm.Mood <> vbNullString Then AddToLevelArray TrackLevel, "MOOD", itm.Mood
				
				'check for artwork
				Dim AttachmentCommand
				If itm.AlbumArt.Count > 0 Then
					AttachmentCommand = " --delete-attachment name:Cover --attachment-name Cover --add-attachment """ _
					& itm.AlbumArt.Item(0).PicturePath & """ "
				Else
					AttachmentCommand = vbNullString
				End If
				
				'--- end gathering content from database
				
				
				Dim XMLContent
				Dim XMLDoc
				Set XMLDoc = CreateObject("Microsoft.XMLDOM")
				XMLContent = CreateXMLContent(CollectionLevel, SeasonLevel, TrackLevel)
				XMLDoc.loadXML(XMLContent)
				
				'TagFilePath = Left(itm.Path,InStrRev(itm.Path,"."))&"xml" 'previous version saved each xml file using the track's filename
				
				'check for and delete previous xml tag file
				If fso.FileExists(TagFilePath) Then fso.DeleteFile TagFilePath
				'save XML file so it can be used by mkvPropEdit
				XMLDoc.save TagFilePath
				
				'mkvPropEdit has been found, so call the command line and write the tags to the file
				Dim CommandLine : CommandLine = Chr(34) & mkvPropEditPath & Chr(34) & " " & Chr(34) & itm.Path & Chr(34) & " --tags all:" & Chr(34) & TagFilePath & Chr(34) & AttachmentCommand & " --redirect-output " & Chr(34) & mkvPropEditOutputFilePath & Chr(34)
				
				Dim a, Retry : a = 0: Retry = True
				Dim MaxWriteAttempts : MaxWriteAttempts = 3
				
				Do While a < MaxWriteAttempts AND Retry
					a = a + 1
					
					Dim Output : Output = vbNullString
					Dim ExitCode : ExitCode = 0
					
					'check for and delete any previous output file
					If fso.FileExists(mkvPropEditOutputFilePath) Then fso.DeleteFile mkvPropEditOutputFilePath
					
					'execute
					ExitCode = wshShell.Run (CommandLine, 0, True)
					'then read the output which has been redirected to a temporary file
					If fso.FileExists(mkvPropEditOutputFilePath) Then
						Dim TextStream : Set TextStream = fso.OpenTextFile(mkvPropEditOutputFilePath, 1) 'opens the file for reading
						Output = TextStream.ReadAll 'read the entire file into the local variable
						TextStream.Close 'close the file
						Set TextStream = Nothing 'clean up the object variable
						fso.DeleteFile mkvPropEditOutputFilePath 'the temporary file is no longer needed so delete it
					End If
					
					'Set oExec = wshShell.Exec(CommandLine)
					'Do While oExec.Status = 0
					'	SDB.Tools.Sleep 50 'wait for shell execution to complete
					'Loop
					
					
					Select Case ExitCode 'oExec.ExitCode
					Case 0
						'success
						TagSuccessCount = TagSuccessCount + 1
						Retry = False
					Case 1
						'mkvPropEdit had at least one warning but modification continued. "Depending on the issues involved the resulting files might be ok or not"
						'Count this as success for now. A later version of this script might read the warning message and alert the user
						TagSuccessCount = TagSuccessCount + 1
						Retry = False
					Case 2
						'An error occurred. Error messages range from wrong command line arguments over read/write errors to broken files
						'for the purposes of this script, it is most likely that the file to be tagged is in use so the tag cannot be written. This can occur if MediaMonkey is attempting to write its own tag
						'if this is the case, then wait a second and try again
						
						'-----------------when using wshShell.Exec
						'get output message from mkvPropEdit execution
						'Dim Output
						'Output = vbNullString
						'Do While Not oExec.StdOut.AtEndOfStream
						'	Output = Output & oExec.StdOut.Read(1)
						'Loop
						'-----------------end commented code
						
						If InStr(Output, "could not be opened") <> 0 Then
							'file locked for writing by another application
							'if we have not reached the maximum number of attempts then wait a second then allow the loop to run again
							If a < MaxWriteAttempts Then
								SDB.Tools.Sleep 1000
								Retry = True
							Else
								'last attempt failed. Count the failure.
								WriteErrorCount = WriteErrorCount + 1
								Retry = False
							End If
						Else
							'error message was not related to file being locked. 
							'a future version of this script may read the message and alert the user. For now just count the failure.
							WriteErrorCount = WriteErrorCount + 1
							Retry = False
						End If
					End Select
				Loop
				
				'Delete the xml tag file now that we're done with it
				If fso.FileExists(TagFilePath) Then fso.DeleteFile TagFilePath
				
			Else 'else check on whether file path ends with mkv
				NonMKVCount = NonMKVCount + 1
			End If 'end checking that file path ends with mkv
		Else
			'item to be tagged is the current playing track. 
			'set the PostponedTrackItm as this track and register OnPlaybackEnd event to tag this track when it is no longer playing
			Set PostponedTrackItm = itm
			Script.RegisterEvent SDB, "OnPlaybackEnd", "TagPostponedTrack"
		End If 'end checking that the file to be tagged is not playing
		If Not Silent Then If bar.Terminate Then Exit Sub
	Next
	
	'report success and fail counts
	Dim ResultReport
	If tracklist.Count = 1 Then
		'if there is only one track selected then there is no need to count the variables
		If TagSuccessCount > 0 Then ResultReport = itm.Title & " successfully tagged"
		If WriteErrorCount > 0 Then ResultReport = "Writing tag to " & itm.Title & " failed"
		If NonMKVCount > 0 Then ResultReport = "Selected file is not an MKV file"
	Else
		'more than one track selected
		If Abs(TagSuccessCount > 0 And WriteErrorCount > 0 And NonMKVCount > 0) = 1 Then
			'if all tracks attempted had the same success or error then report the result as such instead of giving a breakdown of each count
			If TagSuccessCount > 0 Then ResultReport = "All selected files successfully tagged"
			If WriteErrorCount > 0 Then ResultReport = "Writing tag failed for all selected files"
			If NonMKVCount > 0 Then ResultReport = "No MKV files selected"
		Else
			'create a summary showing each count
			If TagSuccessCount > 0 Then ResultReport = TagSuccessCount & " files successfully tagged" & VBCrLf
			If WriteErrorCount > 0 Then ResultReport = WriteErrorCount & " files failed tagging" & VBCrLf
			If NonMKVCount > 0 Then ResultReport = NonMKVCount & " files were not MKV format and were ignored" & VBCrLf
			ResultReport = Trim(ResultReport)
		End If
	End If
	If Not SuppressReport Then Call SDB.MessageBox(ResultReport, mtInformation, Array(mbOk)) 
	
	'complete
	If Not Silent Then
		bar.Text = "mkvTagger: Complete."
		SDB.Tools.Sleep 1500 'just barely enough time for the user to see the complete message in the progress bar if they want to see it.
	End If
	
End Sub

Sub TagPostponedTrack()
	'this sub is called when a track was to be tagged but couldn't be done because it was being played by MediaMonkey
	'the track item to be tagged is stored in variable PostponedTrackItm and the sub is fired by the OnPlaybackEnd event
	
	'first make sure that there is a track to be tagged. If not, unregister the event and quit
	If PostponedTrackItm Is Nothing Then
		Script.UnRegisterHandler "TagPostponedTrack"
		Exit Sub
	End If
	
	'next check that the postponed track is not still playing
	If PostponedTrackItm.ID = SDB.Player.CurrentSong.ID AND SDB.Player.IsPlaying Then
		'can't proceed with the postponed track yet. Exit and wait for the next time that OnPlaybackEnd triggers.
		Exit Sub
	End If
	
	'at this point we have passed the checks so we can proceed and tag the track. Then unregister the event
	Dim bar : Set bar = SDB.Progress
	bar.MaxValue = 1
	bar.Text = "mkvTagger tagging postponed track: " & PostponedTrackItm.Title & "."
	
	'mkvTagger sub requires ISDBSongList object
	dim lst
	Set lst = SDB.NewSongList
	lst.Add PostponedTrackItm
	TagMKV lst, True
	bar.Increase
	Script.UnRegisterHandler "TagPostponedTrack"
	
	SDB.Tools.Sleep 1000 'just barely enough time for the user to see the progress bar message if they want to see it.
End Sub

Function AddToLevelArray(arrLevel, Tag, Value)
	ReDim Preserve arrLevel(UBound(arrLevel)+1)
	arrLevel(UBound(arrLevel)) = Array(Tag, Value)
	AddToLevelArray = arrLevel
End Function
Function CreateXMLContent(CollectionLevel, SeasonLevel, TrackLevel)
	Dim XMLDoc
	Dim XMLRoot
	Set XMLDoc = CreateObject("Microsoft.XMLDOM")
	Set XMLRoot = XMLDoc.createElement("Tags")
	XMLDoc.appendChild XMLRoot
	
	Dim XML
	Dim XMLTargets
	Dim XMLTargetTypeValue
	Dim XMLElement
	
	Dim a
	'CollectionLevel
	If IsArray(CollectionLevel) Then
		If UBound(CollectionLevel) >= 0 Then
			Set XML = XMLDoc.createElement("Tag")
			Set XMLTargets = XMLDoc.createElement("Targets")
			Set XMLTargetTypeValue = XMLDoc.createElement("TargetTypeValue")
			XMLTargetTypeValue.Text = "70"
			XMLRoot.appendChild XML
			XML.appendChild XMLTargets
			XMLTargets.appendChild XMLTargetTypeValue
			
			For a = LBound(CollectionLevel) To UBound(CollectionLevel)
				Set XMLElement = CreateDataElement(CollectionLevel(a)(0), CollectionLevel(a)(1))
				XML.appendChild XMLElement
			Next
		End If
	End If
	
	'SeasonLevel
	If IsArray(SeasonLevel) Then
		If UBound(SeasonLevel) >= 0 Then
			Set XML = XMLDoc.createElement("Tag")
			Set XMLTargets = XMLDoc.createElement("Targets")
			Set XMLTargetTypeValue = XMLDoc.createElement("TargetTypeValue")
			XMLTargetTypeValue.Text = "60"
			XMLRoot.appendChild XML
			XML.appendChild XMLTargets
			XMLTargets.appendChild XMLTargetTypeValue
			
			For a = LBound(SeasonLevel) To UBound(SeasonLevel)
				Set XMLElement = CreateDataElement(SeasonLevel(a)(0), SeasonLevel(a)(1))
				XML.appendChild XMLElement
			Next
		End If
	End If
	
	'TrackLevel
	If IsArray(TrackLevel) Then
		If UBound(TrackLevel) >= 0 Then
			Set XML = XMLDoc.createElement("Tag")
			Set XMLTargets = XMLDoc.createElement("Targets")
			Set XMLTargetTypeValue = XMLDoc.createElement("TargetTypeValue")
			XMLTargetTypeValue.Text = "50"
			XMLRoot.appendChild XML
			XML.appendChild XMLTargets
			XMLTargets.appendChild XMLTargetTypeValue
			
			For a = LBound(TrackLevel) To UBound(TrackLevel)
				Set XMLElement = CreateDataElement(TrackLevel(a)(0), TrackLevel(a)(1))
				XML.appendChild XMLElement
			Next
		End If
	End If
	
	CreateXMLContent = XMLDoc.xml
End Function
Function CreateDataElement(elementname, elementstring)
	Dim XMLElement, XMLRoot, XMLSimple, XMLName, XMLString, XMLTagLanguage, XMLDefaultLanguage
	Set XMLElement = CreateObject("Microsoft.XMLDOM")
	Set XMLSimple = XMLElement.createElement("Simple")
	Set XMLName = XMLElement.createElement("Name") : XMLName.Text = elementname
	Set XMLString = XMLElement.createElement("String") : XMLString.Text = elementstring
	Set XMLTagLanguage = XMLElement.createElement("TagLanguage") : XMLTagLanguage.Text = "und"
	Set XMLDefaultLanguage = XMLElement.createElement("DefaultLanguage") : XMLDefaultLanguage.Text = "1"
	
	XMLElement.appendChild XMLSimple
	XMLSimple.appendChild XMLName
	XMLSimple.appendChild XMLString
	XMLSimple.appendChild XMLTagLanguage
	XMLSimple.appendChild XMLDefaultLanguage
	
	Set CreateDataElement = XMLSimple
End Function
Function GetMkvPropEditPath()
	'in a future version, this function could prompt the user to locate mkvPropEdit.exe and save the result. For now use the default install path for mkvToolNix
	
	'check the ini file to see if the location of mkvPropEdit has been saved
	Dim SavedPath : SavedPath = SDB.IniFile.StringValue("mkvTagger", "mkvPropEditPath")
	If SavedPath <> vbNullString Then
		If IsValidMkvPropEdit(SavedPath) Then
			'return the path that has been saved in the ini file and exit
			GetMkvPropEditPath = SavedPath
			Exit Function
		Else
			'saved path is not valid. Remove the key from the ini file.
			SDB.IniFile.DeleteKey "mkvTagger", "mkvPropEditPath"
		End If
	End If
	
	'if the path has not been saved in the ini file then try using the default install path for mkvToolNix
	Dim wshShell : Set wshShell = CreateObject("WScript.Shell")
	Dim mkvPropEditDefaultPath : mkvPropEditDefaultPath = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") & "\MKVToolNix\mkvpropedit.exe"
	If IsValidMkvPropEdit(mkvPropEditDefaultPath) Then
		'file exists. Return the default install path and exit
		GetMkvPropEditPath = mkvPropEditDefaultPath
		Exit Function
	End If
	
	
	'if we reach this point then we must ask the user to locate mkvPropEdit.exe
	Dim dlg : Set dlg = SDB.CommonDialog
	dlg.Filter = "mkvPropEdit.exe|mkvPropEdit.exe"
	dlg.Flags = cdlOFNFileMustExist
	dlg.Title = "Please locate mkvPropEdit.exe"
	Dim Cancelled
	Dim SelectedPath
	Do 
		dlg.ShowOpen
		If dlg.Ok Then
			'user selected a file
			SelectedPath = dlg.FileName
		Else
			'user clicked cancel
			Cancelled = True 'allow exiting the loop
		End If
	Loop Until Cancelled or IsValidMkvPropEdit(SelectedPath)
	
	If Not Cancelled Then
		'user selected a valid mkvPropEdit executable
		'make a note of the location in the ini file
		SDB.IniFile.StringValue("mkvTagger", "mkvPropEditPath") = SelectedPath
	End If
	
	'if the user clicked cancel or the file was not located, return blank
	If Cancelled Then GetMkvPropEditPath = vbNullString Else GetMkvPropEditPath = SelectedPath
End Function
Function IsValidMkvPropEdit(TestPath)
	'tests the supplied mkvPropEdit path to check that it is a valid mkvPropEdit executable
	'this is achieved by calling the executable with no parameters
	'if the file is not executable then an error will occur
	'mkvPropEdit will return an exit code of 2. If the exit code received is not 2 then the file is not mkvPropEdit
	Dim wshShell : Set wshShell = CreateObject("WScript.Shell")
	Dim ExitCode
	On Error Resume Next
	ExitCode = wshShell.Run("""" & TestPath & """", 0, True)
	If Err.Number = 0 And ExitCode = 2 Then IsValidMkvPropEdit = True Else IsValidMkvPropEdit = False
	Err.Clear
End Function
Lowlander
Posts: 56492
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Re: MKV Tags

Post by Lowlander »

Type is a MediaMonkey Database only tag (used to distribute files along Collections): http://www.mediamonkey.com/wiki/index.p ... _Rules/4.0
jan_axhell
Posts: 3
Joined: Tue Nov 09, 2021 3:52 am

Re: MKV Tags

Post by jan_axhell »

rivorson wrote: Thu May 04, 2017 1:47 pm Change Screenwriter to Track.WRITTEN_BY and they'll all be correct. I don't think Type is read from mkv files though so I don't think you'll get that one to work.

I wrote a script that calls mkvPropEdit to do the tagging, or if mkvPropEdit isn't installed creates an xml file that can be written to the tags using alternative software.

mkvPropEdit is part of mkvToolNix which can be downloaded here:
https://mkvtoolnix.download/

After installing the script, select your files then call mkvTagger from the script menu.
Hello,
I know this is a very old thread, but it seems to be the most recent talking about MKV tagging.
I'm trying to tag Music Videos in MKV format. I have manually tagged all my videos and MediaMonkey shows the correct info in the List View, but it seems that MKV info is stored in some other internal database, because if I check those files with MediaInfo, they do not contain it. MP4 files do contain it, MKV not.
I have tried the above script as-is (I know nothing about VBScript), but what it does is
- removes Artist and Album Artist
- assigns Title to Album

Anybody knows how to leave that stuff as-is and just write it to the tag?

This is an example of a Music Video before and after being tagged with the script.
The problem seems to be in the ARTIST -> AUTHOR switch, but I have no clue on how to handle it.
When the script assigns ARTIST to AUTHOR, artist's name in MediaMonkey disappears leaving an empty field.

BEFORE

Code: Select all

General
Unique ID                                : 277354723078563325452226952098712202495 (0xD0A8939EA4295F8D1EB52B00E9752CFF)
Complete name                            : Q:\- Electro Dream-Pop Dub-step\Allie X\Allie X – Rings a Bell (Visualizer) (2026p).mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 410 MiB
Duration                                 : 4 min 16 s
Overall bit rate                         : 13.4 Mb/s
Writing application                      : Lavf58.18.104
Writing library                          : Lavf58.18.104
ErrorDetectionType                       : Per level 1
ARTIST                                   : Allie X

Video
ID                                       : 1
Format                                   : VP9
Codec ID                                 : V_VP9
Duration                                 : 4 min 16 s
Width                                    : 3 840 pixels
Height                                   : 2 026 pixels
Display aspect ratio                     : 1.895
Frame rate mode                          : Constant
Frame rate                               : 24.000 FPS
Color space                              : YUV
Language                                 : English
Default                                  : Yes
Forced                                   : No
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : A_AAC-2
Duration                                 : 4 min 16 s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 44.1 kHz
Frame rate                               : 43.066 FPS (1024 SPF)
Compression mode                         : Lossy
Title                                    : ISO Media file produced by Google Inc.
Language                                 : English
Default                                  : Yes
Forced                                   : No
AFTER

Code: Select all

General
Unique ID                                : 277354723078563325452226952098712202495 (0xD0A8939EA4295F8D1EB52B00E9752CFF)
Complete name                            : Q:\- Electro Dream-Pop Dub-step\Allie X\Allie X – Rings a Bell (Visualizer) (2026p).mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 410 MiB
Duration                                 : 4 min 16 s
Overall bit rate                         : 13.4 Mb/s
Movie name                               : Rings a Bell (Visualizer) (2026p)
Track name/Position                      : 0
Writing application                      : Lavf58.18.104
Writing library                          : Lavf58.18.104
BPM                                      : -1
Cover                                    : Yes
ErrorDetectionType                       : Per level 1
Attachments                              : Cover
AUTHOR                                   : Allie X
DATE_RECORDED                            : 2019
GENRE                                    : Electro Dream-Pop Dub-step

Video
ID                                       : 1
Format                                   : VP9
Codec ID                                 : V_VP9
Duration                                 : 4 min 16 s
Width                                    : 3 840 pixels
Height                                   : 2 026 pixels
Display aspect ratio                     : 1.895
Frame rate mode                          : Constant
Frame rate                               : 24.000 FPS
Color space                              : YUV
Language                                 : English
Default                                  : Yes
Forced                                   : No
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : A_AAC-2
Duration                                 : 4 min 16 s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 44.1 kHz
Frame rate                               : 43.066 FPS (1024 SPF)
Compression mode                         : Lossy
Language                                 : English
Default                                  : Yes
Forced                                   : No

This is instead an example of an MP4 containing all the right tags:

Code: Select all

General
Complete name                            : Q:\- Electro Dream-Pop Dub-step\Allie X\Allie X – Regulars (1080p).mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 65.7 MiB
Duration                                 : 3 min 43 s
Overall bit rate                         : 2 462 kb/s
Movie name                               : Regulars
Album                                    : Allie X - Official Video
Album/Performer                          : Allie X
Performer                                : Allie X
Genre                                    : Electro Dream-Pop Dub-step
Recorded date                            : 2019
Writing application                      : Lavf58.18.104
Comment                                  : [removed youtube URL]
replaygain_track_gain                    : -11.11 dB
replaygain_track_peak                    : 1.212074
replaygain_album_gain                    : -9.96 dB
replaygain_album_peak                    : 1.379856

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings                          : CABAC / 3 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 3 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 3 min 43 s
Bit rate                                 : 2 329 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.047
Stream size                              : 62.1 MiB (95%)
Title                                    : ISO Media file produced by Google Inc.
Writing library                          : x264 core 155 r2901 7d0ff22
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 3 min 43 s
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 44.1 kHz
Frame rate                               : 43.066 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 3.42 MiB (5%)
Title                                    : ISO Media file produced by Google Inc.
Default                                  : Yes
Alternate group                          : 1

Peke
Posts: 17457
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: MKV Tags

Post by Peke »

Hi,
Main reason for addon above your post and why you observe such behavior is that MKV have very specific TAGGING format which require in 99% of cases that whole file gets remuxed and even then there is slight chance it will not be 100% correct. We decided to go safe route and do not try to tag MKV directly unlike MP4 which have much clear standard and way to tag.

Thus that addon was created to use official MKV tool to tag files.

Personally I do not tag MKV at all but use external information (be it NFO or XML) that contain correct tags and such support is in work for MM5.x but not yet ready for public use (it have not passed internal tests fully).
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
jan_axhell
Posts: 3
Joined: Tue Nov 09, 2021 3:52 am

Re: MKV Tags

Post by jan_axhell »

Ah... I see. Thanks for enlightening me.
I realized something was wrong with MKVs when I scanned my collection with EMBY and only MP4s showed correct Artist/Title. So MKV is natively bugged.
Any way to export the "virtual" tags I have assigned to MKVs in MM to such NFOs?
EMBY actually stores info inside sidecar NFOs.
Peke
Posts: 17457
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: MKV Tags

Post by Peke »

Hi,
Best examples of apps correctly handle NFO files for Movies, TV Series, Anime, ... is KODI (As TV media Center), Radarr, Sonarr many other apps support them. Hope Mm will be one of them soon.

MKV is not messed natively, just it prefers written tags on encode, remux.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
jan_axhell
Posts: 3
Joined: Tue Nov 09, 2021 3:52 am

Re: MKV Tags

Post by jan_axhell »

Hope Mm will be one of them soon.
Yes, I know that, AFAIK EMBY is a fork of KODI. So if I understand correctly, as of now MM is unable to export stored tag info to sidecar NFOs? But where is that info stored? The GUI shows correct data for both MP4s and MKVs. Artist column shows correct names for both formats, Title as well and so on.
Lowlander
Posts: 56492
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Re: MKV Tags

Post by Lowlander »

It's stored in the MediaMonkey database only: https://www.mediamonkey.com/support/kno ... ini-files/
Post Reply