From abb14b2aaed40251f3018101ba4ff7bd07f30877 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Wed, 23 Sep 2015 17:39:17 +0200 Subject: [PATCH] Better search for series name at TvDB (egrep) --- saneRenamix.sh | 31 ++++++++++++------------------- testing/test.sh | 10 ++++++---- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/saneRenamix.sh b/saneRenamix.sh index 4e3e50b..1d4eeb1 100755 --- a/saneRenamix.sh +++ b/saneRenamix.sh @@ -232,9 +232,7 @@ function funcGetSeriesIdFromTvdb { if $debug; then echo -e "\033[36mfuncGetSeriesIdFromTvdb $1\033[37m"; fi; local title; local tmp; - local shorten; title="$1"; - shorten=false; while true; do series_db="https://www.thetvdb.com/api/GetSeries.php?seriesname=${title}&language=$lang" @@ -249,11 +247,11 @@ function funcGetSeriesIdFromTvdb { fi - tmp="$(grep -i -m 1 -B 3 -A 1 ">$title<" "$wget_file")" + tmp="$(grep -Ei -m 1 -B 3 -A 1 ">${title// /\\W+}<" "$wget_file")" if [ ${#tmp} -eq 0 ]; then # No series with this name found - tmp="$(grep -Pzo "(?s)>langCurrent\n" "$wget_file")" # Let's get all series from the query + tmp="$(grep -Pzo --binary-files=text "(?s)>langCurrent\n" "$wget_file")" # Let's get all series from the query if [ $(echo "$tmp" | wc -l) -eq 1 ]; then # If we only found one series - tmp="$(grep -Pzo "(?s).*?$langCurrent.*?" "$wget_file")" # Lets use this one + tmp="$(grep -Pzo --binary-files=text "(?s).*?$langCurrent.*?" "$wget_file")" # Lets use this one else eecho -e " TvDB: $(echo "$tmp" | wc -l) series found with this title ($title)" logNexit 12 @@ -271,24 +269,19 @@ function funcGetSeriesIdFromTvdb { series_alias=${series_alias%<*} series_alias=${series_alias#*>} - echo "$file_title|_|$series_title_tvdb|#|$series_id" >> "$PwD/series.cache" - eecho -e " TVDB:\tSeries found.\tID: $series_id" - eecho -e " \t \tName: $series_title_tvdb" + if [ -n "$series_id" -a -n "$series_title_tvdb" ]; then + echo "$file_title|_|$series_title_tvdb|#|$series_id" >> "$PwD/series.cache" + eecho -e " TVDB:\tSeries found.\tID: $series_id" + eecho -e " \t \tName: $series_title_tvdb" + fi break fi - if $shorten; then - title="${title//\*/ }" # Remove wildcards from current run - tmp="${title% *}" # Shorten the title by one word - if [ ${#tmp} -le 4 ] || [ "$tmp" == "$title" ]; then # Too short or was not shortened - break; - fi - title="$(echo $tmp | sed -e 's/^[^a-zA-Z0-9]*//' -e 's/ *$//')" - shorten=false; - else - title="${title// /*}" # Replace spaces with wildcards - shorten=true; + tmp="${title% *}" # Shorten the title by one word + if [ ${#tmp} -le 4 ] || [ "$tmp" == "$title" ]; then # Too short or was not shortened + break; fi + title="$(echo $tmp | sed -e 's/^[^a-zA-Z0-9]*//' -e 's/ *$//')" done } diff --git a/testing/test.sh b/testing/test.sh index 11c64e5..644a333 100755 --- a/testing/test.sh +++ b/testing/test.sh @@ -18,6 +18,8 @@ files=( ["Good_Wife_15.03.11_00-40_sixx_40_TVOON_DE.mpg.HQ.avi.otrkey"]="Good.Wife..S05E22..Ein.seltsames.Jahr.otrkey" # Use , as delimiter ["H2O_Ploetzlich_Meerjungfrau_15.02.28_11-55_orf1_30_TVOON_DE.mpg.avi.otrkey"]="H2O.-.Plötzlich.Meerjungfrau..S03E06..Bella.irrt.otrkey" +# Series and episode name in title + ["Irene_Huss_Kripo_Goeteborg_Der_im_Dunkeln_wacht_S02E01_15.08.08_22-55_ard_90_TVOON_DE.mpg.HQ.avi"]="Irene.Huss,.Kripo.Göteborg..S02E01..Der.im.Dunkeln.wacht.HQ.avi" ); if [ -f test.sh ]; then @@ -52,12 +54,12 @@ for the_file in "${!files[@]}"; do result="$($path/saneRenamix.sh $srArgs -s -f "$the_file")"; - if [ -L $path/$epg_file ]; then # We have created it above - rm $path/$epg_file - fi - if [ "$result" != "${files["$the_file"]}" ]; then echo -e "\033[31m$the_file -> $result"; echo "'$result' != '${files[$the_file]}'"; + else + if [ -L $path/$epg_file ]; then # We have created it above + rm $path/$epg_file + fi fi done;