Saturday, February 24, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 5495  / 2 Years ago, sun, april 17, 2022, 6:35:45

This is a tricky one. I need to do the following using 2 folders, the movie folder and the subtitle folder:




  1. Search for every movie inside the movie folder, for each file it finds, grab the files name and try to search for it in the subtitle folder.


  2. If the file is found do nothing. If the file is not found, output the file name to a log file that will collect all movies that do not have a subtitle.




The movie folder has the following format:



/Movies

/Movies/SomeMovieFolder1

/Movies/SomeMovieFolder2

/Movies/SomeMovieFolder3

/Movies/SomeMovieFolder...

/Movies/SomeMovieFolderN



And inside each movieFolder is the actual movie (Each movie is in it's own folder inside the Movie folder.



The subtitle folder has all subtitles in the same place. In the subtitles folder.



My thinking would be 2 find commands looped together using a while. This would be a shell script (bash).



Movies are MP4 or MKV formats. Subtitles are SRT format.


More From » scripts

 Answers
1

If filenames of the movies and subtitles files match and only the extensions differ, something like this should work.



#!/bin/bash

movie_dir=~/Movies
subtitle_dir=~/Subtitles
log=~/log.txt

for i in "$movie_dir"/*;do
filname="${i%.*}"
if [ ! -e "$subtitle_dir/$filename.srt" ];then
echo "$filename" >> "$log"
fi
done


EDIT
For when each movie file is in it's own folder then try:



#!/bin/bash

movie_dir=~/Movies
subtitle_dir=~/Subtitles
log=~/log.txt

find "$movie_dir" -type f -name "*.mp4" -o -name "*.mkv" | while read i;do
filename="$(basename "${i%.*}")"
if [ ! -e "$subtitle_dir/$filename.srt" ];then
echo "$filename" >> "$log"
fi
done


This second way should work regardless of the movie folder structure, again as long as the filenames are the same.


[#31367] Monday, April 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
listeerrated

Total Points: 354
Total Questions: 112
Total Answers: 100

Location: Guam
Member since Fri, Jun 18, 2021
3 Years ago
;