I wrote a bash script to be used by nautilus to add 'Title' metadata to video files.
what it does
- filters the input list to exclude any file that doesn't end in either '.avi' '.mkv' or '.mp4' - these are the formats I have included, but you can easily edit it to include any other file format that ffmpeg can handle (including audio files)
- if the filename is in the format of 'Show Name.S##E##.Episode Name.extension' it will automagically fill the title popup to 'Show Name S##E##: Episode Name' allowing for you to just add the episode name at the end. this works so long as 'Show Name' and 'S##E##' are separated by either a period or a space. works even if there is no episode name following the 'S##E##' it will just end in 'S##E##: '. note: there is no filtering of either the show name or the episode name, so you will need to have those done in advance.
- if the filename is not in that format, it automagically fills the title popup with the filename, minus the file extension.
- if the user hits 'close' or 'cancel' then it skips the file
- re-encodes (using 'copy' for both video and audio) with the new metadata, using a temporary file at '/path/to/.file' (this is very fast since it is just copying, not transcoding)
- deletes the old file, replacing it with the new one
- works on networked files, too! (assuming you have write permissions to those paths)
how to use
- save the script to '~/.gnome2/nautilus-scripts/Tag Videos'
- give it execute permissions (i.e. by right clicking on it, going to 'properties,' the 'permissions' tab, and placing a check mark beside 'allow executing file as program')
- right click on a file, or selection of files, then go to Scripts > Tag Videos
- enter the title you want in the popup.
Tag Videos:
Code:#!/bin/bash while read -r f do # the file path of our hidden temporary file. nF=$(echo "$f" | sed 's|\(.*/\).*$|\1|').$(echo "$f" | sed 's|.*/\(.*\)$|\1|') # create title suggestion for this file. # strip the file extension and folder path Title=$(echo "${f%.*}" | sed 's|.*/\(.*\)|\1|') # auto populate 'Show Title S##E##: Episode Title' for filenames using that # structure. the episode title will be missing if it is not present in the file # name. also, there is no filtering of either the show title or the episode title # so that will need to be done in advance. if [[ "$Title" =~ [sS][0-9]{1,2}[eE][0-9]{2} ]]; then Title=$(echo "$Title" | sed 's|\(.*\)[ .]\([sS][0-9]\{2\}[eE][0-9]\{2\}\)|\1 \U\2: |') # check if there is an episode name following the episode number. if [[ ! "$Title" =~ [eE][0-9]{2}$ ]]; then # if there is, filter out a separating '.' if one exists. Title=$(echo "$Title" | sed 's|\([eE][0-9]\{2\}: \)\.|\1|') fi fi # prompt user for new title. Title=$(zenity --entry --title="Video Title" --text="Enter a new title for the video file $Title." --entry-text="$Title") # if no title (i.e. user hit 'Cancel' during the Zenity popup), skip. if [ ! -n "$Title" ]; then continue fi # use ffmpeg to re-encode with new tag. gnome-terminal -x ffmpeg -i "$f" -metadata title="$Title" -acodec copy -vcodec copy -scodec copy "$nF" & # pretend that the old file didnt exist. rm -f \"$Filename\" mv \".$Filename\" \"$Filename\" done < <( echo "$NAUTILUS_SCRIPT_SELECTED_URIS" | grep -iE '.avi$|.mp4$|.mkv$' | sed 's|%20| |g') exit
Bookmarks