Linux CLI - Listing media files across multiple drives (KODI)

  • 30 March 2017
  • charm
Screen capture of the results of our ls command

Our KODI entertainment system currently houses 3 hard drives with media spread across all 3 drives. Two issues have arisen from having media spread across three drives. First, it's hard to get a sense of all the media, despite the fact the media is organized into directories with names like Bluray_TV (for Bluray Television Shows we've bought). Second, it's a bit more difficult to back up. The second problem is solved by buying larger drives: 3 x 6TB drives are on my list. I've always had good luck with Seagate drives (I might be charmed). The first problem is solvable using ls, some switches, and piping that to sort and uniq.

Our KODI server has the following kinds of media:

  • Movies (ripped from our DVD collection)
  • Movies (ripped from our Bluray collection)
  • Television shows (ripped from our DVD collection)
  • Television shows (ripped from our Bluray collection - currently only 1 show, but 4 seasons)
  • Music (ripped from our CD collection, we actually have some tapes, but I prefer just to listen to the tapes)
  • Music Videos (ripped from Bluray, only one concert)
  • Pictures (from our cameras)

What we really cared about listing were the movies and television shows. I started with something like:

ls -R ~/Videos/Blueray2/ ~/Videos/Bluray_tv/ /mnt/Blueray/ /mnt/DVD/Movies/ /mnt/DVD/TV/

Aside from the bad spelling of Bluray, it's actually not "Blueray," but Blu-ray (wikipedia), this file listing had several problems. The first problem was that media gets listed by directory/folder. This isn't so much an issue as it makes sense to separate Blu-rays from DVDs, but in this case what I really care about is whether I have a certain movie or not. For example: I have Police Academy 1, 2, 3, 4 and 7, but not 5 or 6. Listing them by type of content would mean I have to look through the two Blu-ray movie folders (~/Videos/Blueray2, /mnt/Blueray) then the DVD movie folder (/mnt/DVD/Movies) - looking through 3 listings rather than 1. The sort command helps with this:

ls -R ~/Videos/Blueray2/ ~/Videos/Bluray_tv/ /mnt/Blueray/ /mnt/DVD/Movies/ /mnt/DVD/TV/ | sort

Now videos get sorted by name, but there's another problem, unwanted files. In our video list there are a lot of *.jpg files scraped by KODI. We don't want those files to show. In this case we can use the ls --ignore= switch to ignore certain types of files:

ls --ignore=*.jpg -R Blueray2/ Bluray_tv/ /mnt/Blueray/ /mnt/DVD/Movies/ /mnt/DVD/TV/ | sort

Great, we now have a listing a little closer, but I want it redirected to a file that I can look through. Normally I'd use > to redirect to a file, but using > after sort just results in an empty text file, this is where piping to uniq comes in handy:

ls --ignore=*.jpg -R Blueray2/ Bluray_tv/ /mnt/Blueray/ /mnt/DVD/Movies/ /mnt/DVD/TV/ | sort | uniq > movies.txt

Now we have a file list that's a little closer to being manageable. There's still a matter of filtering out a few other unwanted file types (.srt subtitles and the like), but this is a little closer. There's also a matter of filtering out the directories...I haven't quite figured out the simplest way to do this yet.

Add new comment