65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
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())
|
|
}
|
|
|
|
}
|
|
}
|