-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdup-tv-finder
executable file
·88 lines (83 loc) · 3.7 KB
/
dup-tv-finder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
#
# Copyright 2016 Jeremy Hansen <jebrhansen -at- gmail.com>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This script is used to detect multiple instances of TV show episodes.
# Currently, it ignores any srt (subtitle) files, but it does pick up other,
# possibly desired, extensions, such as nfo and sub. Be congnizant of that
# when you look at your results. This does expect that your shows are labeled
# using a folder for the show, and within there, individual folders for each
# season (the naming scheme of those shouldn't matter), and that your
# episodes use the "Showname - SXXEXX - Episodename" format.
# (e.g. Star Trek/Star Trek - Season 1/Star Trek - S01E01 - The Man Trap.avi)
shopt -s nullglob
TVDIR=${TVDIR:-"/share/TV/ongoing/TV Shows"}
echo -e "\nChecking in ====== $TVDIR ====== directory\n"
# Loop through all directories in $TVDIR
for SERIES in "$TVDIR/"*; do
# Store the name in $SERIES
SERIES=$(basename "$SERIES")
# Loop through all seasons within a series
for SEASON in "$TVDIR/$SERIES/"*; do
# Store the season folder in $SEASON
SEASON=$(basename "$SEASON")
# Loop through all the episodes within a season folder
for FIRST in "$TVDIR/$SERIES/$SEASON/"*; do
# Store the episode's filename
FIRST=$(basename "$FIRST")
# Skip common subtitle filetypes to prevent false positives
if [[ ! ${FIRST##*.} =~ ^(mpl|srt|ssa|sub)$ ]]; then
# Get the SXXEXX designator
CUR_EP=$(echo "$FIRST" | awk -F' - ' '{print $2}')
# Rudimentary progress indicator
printf "."
# If the $CUR_EP variable doesn't contain SXXEXX (typically because there's dashes
# in the show name), run an until loop and work through the sections with awk
if [[ $CUR_EP != S[0-9]*E[0-9]* ]]; then
COUNT=0
REGEX="(S[0-9]*E[0-9]*)"
until [[ $CUR_EP =~ $REGEX ]]; do
((COUNT++))
CUR_EP=$(echo "$FIRST" | awk -F' - ' -v COUNT="$COUNT" '{print $COUNT}')
# If it checks 5 fields in the filename and doesn't find SXXEXX, assume the
# file isn't an episode and exit the loop
if [[ $COUNT == 5 ]]; then break; fi
done
fi
# If $CUR_EP exists and equals the $PRE_EP, echo the names of the shows and what matched
if [[ -n $CUR_EP && "$CUR_EP" == $PRE_EP ]]; then
printf "\n"
echo Repeat: $SERIES/$SEASON/$FIRST
echo Repeat: $SERIES/$SEASON/$SECOND
echo $CUR_EP "==" $PRE_EP
fi
# Store the previous episode filename (and location)
SECOND=$FIRST
# Store the previous episode designator
PRE_EP=$CUR_EP
fi
done
# Clear these out when moving to another season to prevent false positives
SECOND=''
PRE_EP=''
done
done
# Add a new line so the prompt comes back on its own line
printf "\n"