-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3213e34
commit 9b1c740
Showing
6 changed files
with
172 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package convert | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type ShowEpisodes struct { | ||
Episodes []string `json:"converted"` | ||
} | ||
|
||
// Define a struct for the entire JSON structure | ||
type ConvertedData struct { | ||
Converted map[string]ShowEpisodes `json:"converted"` | ||
} | ||
|
||
func filterPathList(paths []string) []string { | ||
return []string{} | ||
} | ||
|
||
func readConvertedJson() ConvertedData { | ||
|
||
file, err := os.Open("../videos/converted.json") | ||
if err != nil { | ||
os.Create("../videos/converted.json") | ||
fmt.Println("error opening the file", err) | ||
} else { | ||
|
||
defer file.Close() | ||
} | ||
|
||
decoder := json.NewDecoder(file) | ||
|
||
var readData ConvertedData | ||
|
||
if err := decoder.Decode(&readData); err != nil { | ||
fmt.Println("error decoding json", err) | ||
} | ||
|
||
return readData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package convert | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
func ExtractShowName(pathString string) string { | ||
pathString = filepath.ToSlash(pathString) | ||
pathString = strings.ReplaceAll(pathString, " ", "") | ||
|
||
parts := strings.Split(pathString, "/") | ||
|
||
showKeywords := []string{"season", "series", "show", "s"} | ||
|
||
// Iterate over path parts from the end to the beginning | ||
for i := len(parts) - 1; i >= 0; i-- { | ||
// Check if the part contains a show keyword | ||
for _, keyword := range showKeywords { | ||
if strings.Contains(strings.ToLower(parts[i]), keyword) && i > 0 { | ||
// Find the next non-empty part as the show name | ||
for j := i - 1; j >= 0; j-- { | ||
if parts[j] != "" { | ||
return strings.TrimSpace(parts[j]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return "" | ||
} | ||
func ExtractFolderPath(pathString string) string { | ||
// takes a path string and extracts the video name | ||
// algorithm works by splitting the string by the last \\ | ||
// left side is the path | ||
|
||
backSlashCount := strings.Count(pathString, "\\") | ||
counter := 0 | ||
retIndex := 0 | ||
|
||
for i := 0; i < len(pathString); i++ { | ||
if string(pathString[i]) == "\\" { | ||
counter += 1 | ||
if counter == backSlashCount { | ||
retIndex = i | ||
} | ||
} | ||
} | ||
|
||
retIndex += 1 | ||
return pathString[:retIndex] | ||
} | ||
|
||
func FormatPath(pathString string) string { | ||
formattedString := "" | ||
|
||
for i := range pathString { | ||
if unicode.IsSpace(rune(pathString[i])) || string(pathString[i]) == " " { | ||
formattedString = strings.Replace(pathString, " ", "%20", -1) | ||
} | ||
} | ||
|
||
if len(formattedString) != 0 { | ||
return formattedString | ||
|
||
} else { | ||
return pathString | ||
} | ||
} | ||
|
||
func DeFormatter(mediaName string) string { | ||
mediaName = strings.ReplaceAll(mediaName, "%20", "") | ||
return mediaName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters