commit 98fe1d0b726f09438c43fee8c7dd081a810521c4 Author: Daniel Tam Date: Mon Nov 21 01:11:57 2022 -0600 initial upload diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/fix_subs_in_nested_downloads.iml b/.idea/fix_subs_in_nested_downloads.iml new file mode 100644 index 0000000..2986543 --- /dev/null +++ b/.idea/fix_subs_in_nested_downloads.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ae4a7e8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..9661ac7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/fix_subs_in_nested_downloads.go b/fix_subs_in_nested_downloads.go new file mode 100644 index 0000000..9df89d3 --- /dev/null +++ b/fix_subs_in_nested_downloads.go @@ -0,0 +1,64 @@ +package main + +import ( + "fmt" + "log" + "os" + "regexp" + "strings" +) + +func checkForSubsDir(dir []os.DirEntry) bool { + for _, item := range dir { + if strings.ToLower(item.Name()) == "subs" { + return true + } + } + return false +} + +func processSeason(seasonDir string) { + + // Get files within each directory + seasonsDirList, err := os.ReadDir(seasonDir) + if err != nil { + log.Fatal(err) + } + + // Ensure there's a subs directory + if !checkForSubsDir(seasonsDirList) { + return + } + + for _, seasonsDirItems := range seasonsDirList { + fmt.Println(seasonsDirItems.Name()) + } + +} + +func main() { + topDir := "/mnt/z/From Scratch (2022) [tvdb-400691]/" + // Read in the top directory + topDirList, err := os.ReadDir(topDir) + if err != nil { + log.Fatal(err) + } + + // Each of the seasons directories + for _, seasonsDir := range topDirList { + + // Ensure there's a Sxx in the name (for the season number) + ensureSeason, _ := regexp.MatchString(`.[sS][0-9]{1,2}.`, seasonsDir.Name()) + + // Or if the folder is just called Season xx + if !ensureSeason { + ensureSeason, _ = regexp.MatchString(`[sS]eason\s[0-9]{1,2}`, seasonsDir.Name()) + } + + // Process the season if it is a season folder + if ensureSeason { + processSeason(topDir + seasonsDir.Name()) + } + + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fcf2aeb --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module fix_subs_in_nested_downloads + +go 1.19