update checks
This commit is contained in:
39
fix-subs.go
39
fix-subs.go
@@ -4,17 +4,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkForSubsDir(dir []os.DirEntry) bool {
|
func checkForSubsDir(dir []os.DirEntry) string {
|
||||||
for _, item := range dir {
|
for _, item := range dir {
|
||||||
if strings.ToLower(item.Name()) == "subs" {
|
if strings.ToLower(item.Name()) == "subs" {
|
||||||
return true
|
return item.Name()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSeason(seasonDir string) {
|
func processSeason(seasonDir string) {
|
||||||
@@ -26,12 +27,38 @@ func processSeason(seasonDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure there's a subs directory
|
// Ensure there's a subs directory
|
||||||
if !checkForSubsDir(seasonsDirList) {
|
subsDir := checkForSubsDir(seasonsDirList)
|
||||||
|
if len(subsDir) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(seasonDir)
|
||||||
|
|
||||||
|
// Go through each file
|
||||||
for _, seasonsDirItems := range seasonsDirList {
|
for _, seasonsDirItems := range seasonsDirList {
|
||||||
fmt.Println(seasonsDirItems.Name())
|
|
||||||
|
// If ends with .txt, ignore
|
||||||
|
if filepath.Ext(seasonsDirItems.Name()) == ".txt" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is a directory, ignore
|
||||||
|
fileInfo, err := os.Stat(seasonDir + "/" + seasonsDirItems.Name())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if fileInfo.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the filename without extension
|
||||||
|
filename := strings.TrimSuffix(seasonsDirItems.Name(), filepath.Ext(seasonsDirItems.Name()))
|
||||||
|
|
||||||
|
// Ensure the directory within subs exist matching this filename
|
||||||
|
|
||||||
|
// Move the srt files within the directory into the season's directory
|
||||||
|
|
||||||
|
fmt.Println(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -60,5 +87,7 @@ func main() {
|
|||||||
processSeason(topDir + seasonsDir.Name())
|
processSeason(topDir + seasonsDir.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Complete")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user