How can I simplify this Autohotkey v1 script (fewer lines of code) in order to replace filenames by checking their time ranges and weekdays, along with the specified strings?
; Extract the day, month, and year from the input string using SubStr
day := SubStr(str, InStr(str, "") - 8, 2)
month := SubStr(str, InStr(str, "") - 6, 2)
year := SubStr(str, InStr(str, "_") - 4, 4)
date := month . "/" . day . "/" . year
;MsgBox, Converted string: %DATETOFEED%
FormatTime, Weekday , % Substr(date,7)Substr(date,1,2)Substr(date,4,2), dddd
;{ Tagging based on channel and airing time
Tagging:
filename6 := filename5 ; Initialize filename6 with filename5
; If a filename contains the string "SKAI HD" and the number between the two underscores is between 1439 and 1740, replace that string with the new string "MSR2023"
if (InStr(filename5, "SKAI HD") && InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 1439 && number <= 1740)
{
filename6 := StrReplace(filename5, "SKAI HD", "MSR2023")
}
}
; If a filename contains the string "MEGA HD" and the number between the two underscores is between 0450 and 0730 replace that string with the new string "Κοινωνία Ώρα Μega"
if (InStr(filename5, "MEGA HD") && InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 450 && number <= 730)
{
filename6 := StrReplace(filename5, "MEGA HD", "Κοινωνία Ώρα Μega")
}
}
; If a filename contains the string "ANT1 HD" and the number between the two underscores is between 1940 and 2130,,; replace that string with the new string "Ράδιο Αρβύλα"
if (InStr(filename5, "ANT1 HD") && InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 1940 && number <= 2110)
{
filename6 := StrReplace(filename5, "ANT1 HD", "Ράδιο Αρβύλα")
}
}
; If a filename contains the string "ERT 1 HD" and the number between the two underscores is between 2130 and 2250,,; replace that string with the new string "Κάνε ότι Κοιμάσαι"
if (InStr(filename5, "ERT 1 HD") && InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 2130 && number <= 2250)
{
filename6 := StrReplace(filename5, "ERT 1 HD", "Κάνε ότι Κοιμάσαι")
}
}
;{ If a filename contains the string "MEGA HD" and the number between the two underscores is between 2300 and 0030, replace that string with the new string "Milky Way"
if (InStr(filename5, "MEGA HD") && InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 2300 && number <= 2359) or (number >= 0000 && number <= 30)
{
filename6 := StrReplace(filename5, "MEGA HD", "Milky Way")
}
}
;}
; If a filename contains the string "ALPHA HD" and the number between the two underscores is between 1740 and 1850 and it's a weekend, replace that string with the new string "Το Σόι Σου"
if (InStr(filename5, "ALPHA HD") && InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 1740 && number <= 1850) and (Weekday = "Saturday" or "Sunday")
{
filename6 := StrReplace(filename5, "ALPHA HD", "Το Σόι Σου")
}
}
; If a filename contains the string "ALPHA HD" and the number between the two underscores is between 1255 and 1400, replace that string with the new string "Το Σόι Σου"
if (InStr(filename5, "ALPHA HD") && InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 1255 && number <= 1400)
{
filename6 := StrReplace(filename5, "ALPHA HD", "Το Σόι Σου")
}
}
; If a filename contains the string "ALPHA HD" and the number between the two underscores is between 2050 and 2230,,; replace that string with the new string "Φόνοι Στο Καμπαναριό"
if (InStr(filename5, "ALPHA HD") and InStr(filename5, "_"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 2050 and number <= 2230) and (Weekday = "Saturday" or "Friday")
{
filename6 := StrReplace(filename5, "ALPHA HD", "Φόνοι Στο Καμπαναριό")
}
else if (number >= 2050 and number <= 2359) && !(Weekday = "Saturday" or "Friday")
; else if (number >= 2050 and number <= 2359 and !(Weekday = "Friday"))
{
filename6 := StrReplace(filename5, "ALPHA HD", "ALPHA HD")
}
}
; If a filename contains the string "ALPHA HD" and the number between the two underscores is between 1950 and 2100, replace that string with the new string "Μην Αρχίζεις Τη Μουρμούρα"
if (InStr(filename5, "ALPHA HD") && InStr(filename5, "_") && InStr(filename5, "2023"))
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if (number >= 1950 && number <= 2100) and (Weekday = "Sunday")
{
filename6 := StrReplace(filename5, "ALPHA HD", "Μην Αρχίζεις Τη Μουρμούρα S11E")
}
}
if (InStr(filename5, "STAR HD") && InStr(filename5, "_")) ;; this includes ranges, seems to work, not sure. OR is expressed differently.
{
number := SubStr(filename5, InStr(filename5, "_") + 1, 4)
if ((number >= 2050 && number <= 2359) || (number >= 0 && number <= 200)) && (Weekday = "Friday")
{
filename6 := StrReplace(filename5, "STAR HD", "Fame Story Live")
}
else if ((number >= 2250 && number <= 2359) || (number >= 0 && number <= 130)) && !(Weekday = "Friday")
{
filename6 := StrReplace(filename5, "STAR HD", "Fame Story")
}
else
{
filename6 := StrReplace(filename5, "STAR HD", "STAR HD")
}
}
Please make sure to check for time ranges but also for days using the Weekday variable. Also make sure that when a value for Weekday is specified i.e Friday which is compared with these lines I've provided:
date := month . "/" . day . "/" . year
;MsgBox, Converted string: %DATETOFEED%
FormatTime, Weekday , % Substr(date,7)Substr(date,1,2)Substr(date,4,2), dddd
Please make sure that this matches ONLY files in which their date suggests it was a Friday indeed.
For example, using the code I've showed you, the file "STAR HD-K8 Φάρμα (Ε)(02112023_233731)" should become "Fame Story - 2023-11-02_23.37." and "STAR HD-K8 Fame Story - Live(03112023_231322)" should become "Fame Story Live - 2023-11-03_23.13". NOT the other way around.