Last active
September 19, 2022 19:04
-
-
Save smartass08/ef8a2c596f3d3089b69eb9bdecde9426 to your computer and use it in GitHub Desktop.
Seasonal anime Identifier written in go
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
package main | |
import ( | |
"errors" | |
"fmt" | |
"os" | |
"strings" | |
) | |
type Episode struct { | |
Name string `json:"name"` | |
} | |
const ( | |
subsPlease = "SubsPlease" | |
eraiRaws = "Erai-raws" | |
) | |
var ( | |
errorMessage = errors.New("invalid String provided") | |
) | |
func (e Episode) GetEncode() (encode string, err error) { | |
switch { | |
case strings.Contains(e.Name, subsPlease) || strings.Contains(e.Name, eraiRaws): | |
splitName := strings.SplitAfter(e.Name, "]") | |
if len(splitName) <= 1 { | |
return "", fmt.Errorf("invalid String provided") | |
} | |
encode = splitName[0] | |
} | |
return | |
} | |
func (e Episode) GetResolution() (res string, err error) { | |
switch { | |
case strings.Contains(e.Name, subsPlease): | |
splitName := strings.Split(e.Name, "(") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
splitName = strings.SplitAfter(splitName[1], ")") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
splitName = strings.Split(splitName[0], ")") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
res = splitName[0] | |
case strings.Contains(e.Name, eraiRaws): | |
splitName := strings.Split(e.Name, "[") | |
if len(splitName) <= 2 { | |
return "", errorMessage | |
} | |
splitName = strings.Split(splitName[2], "]") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
res = splitName[0] | |
default: | |
err = fmt.Errorf("no suitable encode provided for getting resolution") | |
} | |
return | |
} | |
func (e Episode) GetTitle() (title string, err error) { | |
switch { | |
case strings.Contains(e.Name, subsPlease): | |
splitName := strings.Split(e.Name, "[") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
splitName = strings.Split(splitName[1], "] ") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
splitName = strings.Split(splitName[1], "- ") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
title = splitName[0] | |
case strings.Contains(e.Name, eraiRaws): | |
splitName := strings.SplitAfter(e.Name, "]") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
splitName = strings.Split(splitName[1], "[") | |
if len(splitName) <= 1 { | |
return "", errorMessage | |
} | |
title = splitName[0] | |
} | |
return | |
} | |
func main() { | |
name := os.Args | |
anime := Episode{Name: name[1]} | |
encoder, err := anime.GetEncode() | |
if err != nil { | |
fmt.Println("Error while obtaining encoder", err) | |
} | |
title, err := anime.GetTitle() | |
if err != nil { | |
fmt.Println("Error while obtaining title", err) | |
} | |
resolution, err := anime.GetResolution() | |
if err != nil { | |
fmt.Println("Error while obtaining resolution", err) | |
} | |
fmt.Printf("Encoder :- %s\nTitle :- %s\nResolution :- %s", encoder, title, resolution) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment