Thursday, December 1, 2022

#1 2019-04-28 09:35:49 pm

alear
Member
Registered: 2016-10-02
Posts: 30

Batch remove metadata from mkv files based on a list

Hello,


The next mkvproedit command remove all tags and title from a mkv video file. It works ok for one file.

/Users/MIGUEL/Documents/JMkvpropedit/mkvpropedit /Volumes/_PELIS_/MKV/Dumbo(1941).mkv --tags all: -d title



I have several external hard disks with mkv files inside folders.

Example:
One external hard disk with +1000 mkv files in a folder and I want to remove metadata of +600 files listed in a text file.


I would like the script ask something like this:
- Choose your folder
- Select the txt list
then remove metadata of the mkv files with the mkvproedit command


My folder with mkv files is like this:

7 años.mkv
Speed1994.mkv
The Graduate (1967).mkv
Horizon.mkv
The_Manigificent_Seven.mkv
ThePunisher.mkv
Dumbo(1941).mkv
The_Pink_Panther_(1963).mkv
Retratos_Salvajes.mkv
Carlito’s Way 1993.mkv



My text file list is:

Speed1994.mkv
Horizon.mkv
The_Manigificent_Seven.mkv
Dumbo(1941).mkv
The_Pink_Panther_(1963).mkv
Retratos_Salvajes.mkv




Appreciate your help. Thank you in advance.

Alejandro.


I found the below code in this post (would be something similar I would like)
https://macscripter.net/viewtopic.php?id=45654

Applescript:


set path2source to choose folder with prompt "Select your folder" default location (path to desktop)
set path2list to choose file with prompt "Select your textList" of type {"txt"}

set theList to paragraphs of (read path2list)

tell

Model: mac mini 2011
AppleScript: 2.6.1
Browser: Safari 537.36
Operating System: macOS 10.9


Filed under: metadata, mkv, remove

Offline

 

#2 2019-05-05 09:39:10 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2588

Re: Batch remove metadata from mkv files based on a list

I have an executable UNIX file mkvpropedit inside the bundle of MKVToolNix-32.0.0 application. So, I wrote the following script that works:

Applescript:


set mkvPropEdit_path to "/Applications/MKVToolNix-32.0.0.app/Contents/MacOS/mkvpropedit "
set movies_Path to choose folder with prompt "SELECT YOUR FOLDER" default location (path to desktop)
set filter_List to choose file with prompt "SELECT YOUR TEXT LIST" of type {"txt"}

set filter_List to paragraphs of (read filter_List)
tell application "System Events" to set mkv_Movies to every file of movies_Path whose name extension is "mkv"

repeat with next_Movie in mkv_Movies
   tell application "System Events" to set next_Movie to POSIX path of next_Movie
   set next_Movie_Name to do shell script "basename -s .mkv " & quoted form of next_Movie
   if next_Movie_Name is in filter_List then
       do shell script mkvPropEdit_path & next_Movie & " --tags all: -d title"
   end if
end repeat

NOTE: this script works fine with basic Unix paths, but throws out an error with special characters such as space, quote, (, and )  ...

I tried to apply the Quoted Form of Posix Path, but so far without success. The problem is that the  developers of utility mkvpropedit did not think well of the command line. It requires names with special characters in the form:

"mkvpropedit 'my movie(1967)'.mkv --tags all: -d title".
That is, requires filename extеnsion outside of nested quotes. 

Quoted Form of Posix Path on other side gives only following form:
"mkvpropedit 'my movie(1967).mkv' --tags all: -d title" (which not accepts UNIX shell. Here is problem with quotation syntax)

Any help?  One solution I think, is temporarily rename processed video file (potentially any of them can has difficult name), doing do shell script, then renaming back to original difficult name. Not manually, of course.

Last edited by KniazidisR (2019-05-05 12:53:21 pm)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 15.6.1
Ram: 4 GB

Offline

 

#3 2019-05-05 11:37:25 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2588

Re: Batch remove metadata from mkv files based on a list

Let's say "SOLVED". Complete script is that:

Applescript:


-- get path to mkvpropedit UNIX executable (is inside MKVToolNix app bundle)
set mkvPropEdit_path to "/Applications/MKVToolNix-32.0.0.app/Contents/MacOS/mkvpropedit "
-- get path to movies folder (from user)
set movies_Path to choose folder with prompt "SELECT YOUR FOLDER" default location (path to desktop)
-- get list with movies names, which need metadata removing (from user)
set filter_List to choose file with prompt "SELECT YOUR TEXT LIST" of type {"txt"}
set filter_List to paragraphs of (read filter_List)
-- get all mkv files of movies folder
tell application "System Events" to set mkv_Movies to every file of movies_Path whose name extension is "mkv"
-- convert movies folder's alias path to posix path (to use later)
set movies_Path to POSIX path of movies_Path

-- process all mkv video files in loop
repeat with next_Movie in mkv_Movies
   
   tell application "System Events"
       -- backing up original name of mkv video file (to restore later)
       set temp_Name to name of next_Movie
       -- converting file specifier to Posix path (to use in shell command)
       set posix_Path to POSIX path of next_Movie
       -- get name of file without full path and extension (to compare with list)
       set next_Movie_Name to do shell script "basename -s .mkv " & quoted form of posix_Path
       
       -- if processed file name mathches to list, then continue removing of metadata in it
       if next_Movie_Name is in filter_List then
           -- temporarely rename potencially difficult name of file to easy name
           set name of next_Movie to "myMovie.mkv"
           -- remove all metadata from file
           set posix_Path to movies_Path & "myMovie.mkv"
           do shell script mkvPropEdit_path & quoted form of (movies_Path & "myMovie") & ".mkv --tags all: -d title"
           -- restore original name of file, when complete with metadata
           set alias_Path to (POSIX file posix_Path as string) as alias
           set name of alias_Path to temp_Name
       end if
   end tell
   
end repeat

Last edited by KniazidisR (2022-11-02 12:05:50 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 15.6.1
Ram: 4 GB

Offline

 

#4 2022-11-01 08:54:28 am

kiwilegal
Member
From:: France
Registered: 2006-01-20
Posts: 351

Re: Batch remove metadata from mkv files based on a list

Hi there

I have been trying to re-purpose this script to remove meta data from all MKVs in a folder, with no txt list.

But I am getting an error message when it tries to do the "do shell script mkvPropEdit_path & posix_Path & " --tags all: -d title""

The error is "More than one file name has been given ('/Users/username/Desktop/Folder' and '1/myMovie.mkv'.

It looks like the script cannot handle a path where there is a space in a folder name. I have a folder named "Folder 1", where the MKV files are located. Or am I misreading this?

Any suggestions to solve this would be gratefully received.

Thanks

Andrew

Offline

 

#5 2022-11-02 02:07:49 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2588

Re: Batch remove metadata from mkv files based on a list

I added quoting the folder path in the post #3. Please, try and say us if this worked for you.

I can't find proper syntax for non-English folder and movie names... mkvpropedit tool guides on the net doesn't provide any example with non-English movie name which can contain spaces as well...

Last edited by KniazidisR (2022-11-02 02:32:37 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 15.6.1
Ram: 4 GB

Offline

 

#6 2022-11-02 09:14:40 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 267

Re: Batch remove metadata from mkv files based on a list

This works for me. Note the version change in the tool.

Basically, instead of using applescript's 'quoted form' it uses the shell's escaping '\' to handle spaces. Also, it reads the list file as utf-8 to better handle file names with non-latin scripts.

Applescript:

use scripting additions
-- get path to mkvpropedit UNIX executable (is inside MKVToolNix app bundle)
set mkvPropEdit_path to "/Applications/MKVToolNix-41.0.0.app/Contents/MacOS/mkvpropedit "

-- get path to movies folder (from user)
set movies_Path to choose folder with prompt "Select movies folder" default location (path to downloads folder)

-- get list with movies names, which need metadata removing (from user)
set filter_List to choose file with prompt "Select text list" of type {"txt"} default location (path to desktop)
-- read as utf-8 to handle more characters
set filter_List to paragraphs of (read filter_List as «class utf8»)

tell application "System Events" to set mkv_Movies to every file of movies_Path whose name extension is "mkv"
set movies_Path to POSIX path of movies_Path

-- track tag-edited movies
set shellMov to {}

repeat with next_Movie in mkv_Movies
   tell application "System Events"
       -- converting file specifier to Posix path (to use in shell command)
       set posixPath to POSIX path of next_Movie
       
       -- escape spaces in file names
       set AppleScript's text item delimiters to space
       set pp1 to text items of posixPath
       set AppleScript's text item delimiters to "\\ "
       set pp2 to pp1 as text
       tell me to do shell script mkvPropEdit_path & pp2 & " --tags all: -d title"
       
       set end of shellMov to name of next_Movie
   end tell
end repeat

-- list tag-edited movies; if list is long, might be better to export to file
set AppleScript's text item delimiters to linefeed
-- display dialog shellMov as text
set AppleScript's text item delimiters to ""

Offline

 

#7 2022-11-02 03:32:20 pm

wch1zpink
Member
Registered: 2011-08-20
Posts: 108

Re: Batch remove metadata from mkv files based on a list

This works for me.  (I always try to get the job done with as little code as possible)

Notice the difference in the app version I am using... MKVToolNix-71.1.0.app

Applescript:

property mkvPropEdit : quoted form of ¬
   "/Applications/MKVToolNix-71.1.0.app/Contents/MacOS/mkvpropedit"

set path2Source to quoted form of POSIX path of ¬
   (choose folder with prompt "Select your folder" default location (path to desktop))
set path2List to quoted form of POSIX path of ¬
   (choose file with prompt "Select your textList" of type {"txt"})

do shell script "cd " & path2Source & " ;while read line ;do " & mkvPropEdit ¬
   & " \"$line\" --tags all: -d title ;done < " & path2List

If you prefer not to read the files from the list.txt, this will target all .mkv files in the chosen directory.

Applescript:

property mkvPropEdit : quoted form of ¬
   "/Applications/MKVToolNix-71.1.0.app/Contents/MacOS/mkvpropedit"

set path2Source to quoted form of POSIX path of ¬
   (choose folder with prompt "Select your folder" default location (path to desktop))

do shell script "cd " & path2Source & " ;for f in *.mkv ;do " & mkvPropEdit ¬
   & " \"$f\" --tags all: -d title ;done"

Last edited by wch1zpink (2022-11-02 04:09:42 pm)

Offline

 

#8 2022-11-02 07:59:28 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 267

Re: Batch remove metadata from mkv files based on a list

wch1zpink wrote:

This works for me.  (I always try to get the job done with as little code as possible)

Notice the difference in the app version I am using... MKVToolNix-71.1.0.app



Very succinct. I understand the second script but the first one… not so much. Have to do some reading.

I'd like to upgrade 'toolnix' but v41 is the newest that runs on Sierra.

Offline

 

#9 2022-11-18 07:18:45 pm

atokyo
Member
Registered: 2022-11-17
Posts: 3

Re: Batch remove metadata from mkv files based on a list

I am new on the site and before I could respond on this thread (my account wasn't validated) I had reached out to wch1zpink directly to ask a question about their code below, and to ask if there was a way that it could be amended to be able to search sub-folders as well. 

I wanted to thank them here for responding so quickly with an amended code that worked perfectly.  It was a very kind thing to do, and so thank you for that.  The code may be useful for others and so rather than put it here myself, I would invite wch1zpink to add it in as it was their work.


wch1zpink wrote:

This works for me.  (I always try to get the job done with as little code as possible)

Notice the difference in the app version I am using... MKVToolNix-71.1.0.app

If you prefer not to read the files from the list.txt, this will target all .mkv files in the chosen directory.

Applescript:

property mkvPropEdit : quoted form of ¬
   "/Applications/MKVToolNix-71.1.0.app/Contents/MacOS/mkvpropedit"

set path2Source to quoted form of POSIX path of ¬
   (choose folder with prompt "Select your folder" default location (path to desktop))

do shell script "cd " & path2Source & " ;for f in *.mkv ;do " & mkvPropEdit ¬
   & " \"$f\" --tags all: -d title ;done"


Filed under: metadata, batch, mkv

Offline

 

#10 2022-11-19 07:32:41 pm

wch1zpink
Member
Registered: 2011-08-20
Posts: 108

Re: Batch remove metadata from mkv files based on a list

atokyo wrote:

I am new on the site and before I could respond on this thread (my account wasn't validated) I had reached out to wch1zpink directly to ask a question about their code below, and to ask if there was a way that it could be amended to be able to search sub-folders as well. 

I wanted to thank them here for responding so quickly with an amended code that worked perfectly.  It was a very kind thing to do, and so thank you for that.  The code may be useful for others and so rather than put it here myself, I would invite wch1zpink to add it in as it was their work.



@atokyo please go ahead and post my solution to you from the private message... here.  I deleted all of my sent messages and no longer have the code that you asked me for.

Last edited by wch1zpink (2022-11-19 07:34:12 pm)

Offline

 

#11 2022-11-19 07:47:35 pm

atokyo
Member
Registered: 2022-11-17
Posts: 3

Re: Batch remove metadata from mkv files based on a list

In that case, here is the code that wch1zpink made that batch removes the title from MKV files, but will work with a folder with multiple sub-folders.  Very handy!:


My current version of the app is now MKVToolNix-71.1.0.app... So make sure you edit the code to match your version.  Let me know if you run into any problems.

property mkvPropEdit : quoted form of ¬
    "/Applications/MKVToolNix-71.1.0.app/Contents/MacOS/mkvpropedit"

set path2Source to quoted form of POSIX path of ¬
    (choose folder with prompt "Select your folder" default location (path to desktop))

do shell script "find " & path2Source & " -type f -iname \"*.mkv\" -mindepth 1" & ¬
    " |while read line ;do " & mkvPropEdit & " \"$line\" --tags all: -d title ;done"


Filed under: , mkv

Offline

 

#12 2022-11-26 06:37:28 am

atokyo
Member
Registered: 2022-11-17
Posts: 3

Re: Batch remove metadata from mkv files based on a list

I had another thought / question... all the scripts remove the 'title' metadata, which is really helpful, but I also have many files where the video track, audio track, and subtitle tracks of the mkv file have odd wording in the 'name' section for each track.

These additional elements can be removed in the normal way using MKCToolNix, but could the script be amended to also batch remove all 'name' elements as well as the 'title' element?

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)