-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsekvens.sh
executable file
·205 lines (143 loc) · 3.54 KB
/
sekvens.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
# find all "armin van buuren contianing [0-9][0-9][0-9]
# sequence the $smallest and $highest number and give output.
# hack delimiter
#OLDIFS=$IFS
#IFS=$'\n'
helpmsg(){
#echo -e "sekvens.sh"
echo -ne "\n"
echo -e "\tUsage"
echo -ne "\n"
echo -e "\t$0/path/to/save/location -n \"armin van buuren a state of trance\" -d 3"
echo -ne "\n"
echo -e "\t-t" "\t" "Location of your files"
echo -e "\t-n" "\t" "Name of podcast/show"
echo -e "\t-d" "\t" "Digits per episode number (ie. 800 has 3)"
echo -e "\t-p" "\t" "Prints this message"
echo -e "\t-h" "\t" "Prints missing shows to a file (default: missing.log)"
echo -ne "\n"
}
#regex="^(va|armin.van.buuren)+.*a.state.of.trance.*[0-9][0-9][0-9].*2016.*"
#ARCHIVE_PATH=$1
#ARCHIVE_PATH=$(ls "${ARCHIVE_PATH}" | egrep -oi ${regex})
#TEST=$(echo -ne "$ARCHIVE_PATH" "\n"| egrep -o "(_|-)+[0-9]{3}(_|-)+" | tr -d '-' | tr -d '_' | sort -n)
#lower=$(echo -ne "$ARCHIVE_PATH" "\n"| egrep -o "(_|-)+[0-9]{3}(_|-)+" | tr -d '-' | tr -d '_' | sort -rnk3 | awk '!x[$2]++')
#upper=$(echo -ne "$ARCHIVE_PATH" "\n"| egrep -o "(_|-)+[0-9]{3}(_|-)+" | tr -d '-' | tr -d '_' | sort -nk3 | awk '!x[2]++')
#echo -ne "$ARCHIVE_PATH"
#echo $lower
#echo $upper
#SEQ=$(seq $lower $upper)
#comm -13 <(echo -e "${TEST}" | sort | uniq) <(echo "${SEQ}")
main(){
target=""
name=""
digits=""
print_to_file=false
OLDIFS=$IFS
IFS=$'\n'
while getopts "t:n:d:ph" opt; do
case $opt in
t)
target=$OPTARG
;;
n)
name=$OPTARG
;;
d)
digits=$OPTARG
;;
p)
# if this is true, tonight we feast
if $OPT;then
print_to_file=true
else
print_to_file=false
fi
;;
h)
# prints help msg
helpmsg
exit 1
;;
\?)
echo "Invalid option. -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
*)
helpmsg
exit 1
;;
esac
done
IFS=$OLDIFS
}
prepare_name(){
# prepares the regex code for generate_list()
# takes n and d as param.
#echo $1
#echo $2
name_done=$(echo "$2.*(-|_)+[0-9]{$3}+(_|-)+.*" | tr ' ' '.*')
#echo "$name_done"
name_done=$1$name_done
}
print_summary(){
# matches the
#
#
# takes array of folder_list (complete list of releases)
echo ""
}
generate_list(){
# generates the first list
# takes name-regex param
# implement some kinda path check feature done
if [[ -d $target ]];then
get_folders=$(find $1 -mindepth 1 -maxdepth 1 -type d | egrep -io "$2"| sort -n)
init=0
for x in $get_folders;do
folder_list[init]=${x}
init=$((init+1))
done
#folder_list=$(ls $target| egrep -io $name_done)
# debug purpose
for i in ${folder_list[@]};do
echo -ne "$i\n"
done
else
echo -ne "Target path does not exist. Quitting.\n"
exit 1
fi
#echo ${folder_list[@]}
}
get_sequence(){
# debugging
#echo #$folder_list[@]
#echo ${folder_list[@]} | egrep -io "(_|-)+[0-9]{$1}(_|-)+" | tr -d '-' | tr -d '_' | sort -n
#for x in $folder_list[@];do
up=$(echo -ne "${folder_list[@]}" "\n" | egrep -oi "(_|-)+[0-9]{$1}(_|-)+" | tr -d '-' | tr -d '_' | sort -rnk3 | awk '!x[2]++')
echo -ne "UP: $up\n"
#done
#for y in $folder_list[@];do
low=$(echo -ne "${folder_list[@]}" "\n" | egrep -oi "(_|-)+[0-9]{$1}(_|-)+" | tr -d '-' | tr -d '_' | sort -nk3 | awk '!x[2]++')
echo -ne "LOW: $low\n"
#done
}
### FUCK THAT
#compare_lists(){
# compares
#}
#missing_to_file(){
# writes missing files to list
# takes param
#}
#main "$@"
#prepare_name "$name" "$digits"
main "$@"
prepare_name "$target" "$name" "$digits"
generate_list "$target" "$name_done"
get_sequence "$digits"