Iâm avoiding touching the SQLite database with any UPDATE query, purely because I firmly believe the issue should be corrected a the file server level, seems the Plex metadata is driven by the file information itself. It makes no sense to me to modify the SQLite DB directly to me anyway.
Iâve wrote a very basic loop to fix the current media file I have, I am evaluating options on the best possible methods to maintain this job going forward. Essentially for MP4 and MKV its quite easy to run mkvpropedit or mp4box in a loop of media files, for example I did this:
MEDIA_LIST="media_files_list.txt"
while IFS= read -r MEDIA
do
if [[ $MEDIA == *"mp4"* ]]
then
/usr/local/bin/mp4box -lang 1=eng "$MEDIA"
elif [[ $MEDIA == *"mkv"* ]]
then
/usr/bin/mkvpropedit "$MEDIA" --edit track:a1 --set language=eng
else
echo "$MEDIA is not a MP4 or MKV file"
fi
done < "$MEDIA_LIST"
This assumes that the first audio track within the files are is English. I generally donât have many multiple audio tracks.
I only have MP4 or MKV files, any other format I converted (remuxed to mkv) such as avi, mpg, divx etc, prior to doing this, as I could not find any command line tool to modify the audio track of an avi file and others easily, plus avi is OLD, most basic clients support MP4 these days.
The media list was generated by essentially exporting my media library with plex2csv, the reason I used this is because I wanted to understand how the schema of the data is, which is what plex2csv does (exports your media library via the SQLite DB at a specific level), to automate this, a SELECT query would need to be done on the SQLite database to look for blank values on audio language or N/A on the audio track and write this to a file somewhere. Unfortunately, my SQL skills are limited, as youâd need to perhaps perform an INNER JOIN on a couple of tables, like media_part and others to get both the Part File value in the query (language and part file are in different tables), but thatâs my next goal. The CSV export was good to understand the fields though.
From there this script could be automated via cron to run at intervals to query the Plex DB, identify the files that need to be tagged with the correct Language ISO code and then use something similar to the loop through the list to correctly tag the audio.
Something like this would need to be perhaps smarter to handle multiple audio tracks in a file and when eng is not the first audio stream etc. Its doable, just finding the time really, or looking at potential pre-existing solutions. Mostly it would be driven by the SQLite DB however, though only SELECT queries would be needed to output the required data and not any modifications directly.