Temporary fix for Erai's inconsistent title uploading format

This commit is contained in:
Kenneth Jao 2025-02-03 22:13:01 +08:00
parent 797bfde19d
commit 672826979c
2 changed files with 75 additions and 59 deletions

120
cli.go
View File

@ -56,68 +56,78 @@ func (m *SubscriptionManager) Add() {
fmt.Println() fmt.Println()
// Get available subscriptions. // Get available subscriptions.
fmt.Println("Available subscriptions:") // fmt.Println("Available subscriptions:")
titles, err := GetReleaseSchedule() // titles, err := GetReleaseSchedule()
if err != nil { // if err != nil {
fmt.Println("Unable to get release schedule.") // fmt.Println("Unable to get release schedule.")
return // return
} // }
subMap := GetSubMap(&m.Subscriptions) // subMap := GetSubMap(&m.Subscriptions)
var available []string // var available []string
i := 0 // i := 0
for _, title := range titles { // for _, title := range titles {
title = strings.Split(title, " | ")[0] // title = strings.Split(title, " | ")[0]
_, exists := subMap[title] // _, exists := subMap[title]
if !exists { // if !exists {
i++ // i++
available = append(available, title) // available = append(available, title)
fmt.Println(fmt.Sprintf("\t[%02d] %v", i, title)) // fmt.Println(fmt.Sprintf("\t[%02d] %v", i, title))
} // }
} // }
fmt.Println() // fmt.Println()
// Get comma-separated list of additions. // Get comma-separated list of additions.
newSubs := []string{} newSubs := []string{}
var add string // var add string
var name string var name string
for {
fmt.Print("Add subscriptions. (M for manual): ")
fmt.Scan(&add)
add = strings.ToLower(add)
if add == "m" {
var err error
fmt.Print("Name: ")
in := bufio.NewReader(os.Stdin)
name, err = in.ReadString('\n')
name = name[:len(name)-1]
e.Panic(err)
newSubs = append(newSubs, name)
} else {
addSplit := strings.Split(add, ",")
retry := false
for _, indexString := range addSplit {
index, err := strconv.Atoi(indexString)
if err != nil {
fmt.Println("Error in indices. Try again.")
retry = true
break
}
if index <= 0 || index > len(available) {
fmt.Fprintln(os.Stdout, "Error in indices. %v is invalid. Try again", index)
retry = true
break
}
newSubs = append(newSubs, available[index-1]) var err error
} fmt.Print("Name: ")
if retry { in := bufio.NewReader(os.Stdin)
continue name, err = in.ReadString('\n')
} name = name[:len(name)-1]
} e.Panic(err)
break newSubs = append(newSubs, name)
}
// for {
// fmt.Print("Add subscriptions. (M for manual): ")
// fmt.Scan(&add)
// add = strings.ToLower(add)
// if add == "m" {
// var err error
// fmt.Print("Name: ")
// in := bufio.NewReader(os.Stdin)
// name, err = in.ReadString('\n')
// name = name[:len(name)-1]
// e.Panic(err)
// newSubs = append(newSubs, name)
// } else {
// addSplit := strings.Split(add, ",")
// retry := false
// for _, indexString := range addSplit {
// index, err := strconv.Atoi(indexString)
// if err != nil {
// fmt.Println("Error in indices. Try again.")
// retry = true
// break
// }
// if index <= 0 || index > len(available) {
// fmt.Fprintln(os.Stdout, "Error in indices. %v is invalid. Try again", index)
// retry = true
// break
// }
// newSubs = append(newSubs, available[index-1])
// }
// if retry {
// continue
// }
// }
// break
// }
var hevc string var hevc string
fmt.Print("Only HEVC? (Y/n): ") fmt.Print("Only HEVC? (Y/n): ")

14
main.go
View File

@ -25,8 +25,7 @@ import (
"github.com/mrobinsn/go-rtorrent/rtorrent" "github.com/mrobinsn/go-rtorrent/rtorrent"
) )
const ReleaseURL string = "https://www.erai-raws.info/release-schedule/" const ReleaseURL string = "https://www.erai-raws.info/release-schedule-v2/"
const RSSURL string = "https://www.erai-raws.info/feed/?res=1080p&type=magnet&subs%5B0%5D=us&v0=no&d157edc6b50f28b2776442c03d067d56"
const NyaaURL string = "https://nyaa.si/" const NyaaURL string = "https://nyaa.si/"
const SocketPath string = "/tmp/anitoru.sock" const SocketPath string = "/tmp/anitoru.sock"
@ -141,11 +140,18 @@ func GetReleaseSchedule() ([]string, error) {
res, err := http.Get(ReleaseURL) res, err := http.Get(ReleaseURL)
defer res.Body.Close() defer res.Body.Close()
e.Log("hello")
return titles, e.If(err).ThenIf(func() error { // The function will run first before return. return titles, e.If(err).ThenIf(func() error { // The function will run first before return.
doc, err = goquery.NewDocumentFromReader(res.Body) doc, err = goquery.NewDocumentFromReader(res.Body)
return err return err
}).Then(func() { }).Then(func() {
e.Log("here")
doc.Find("html").Each(func(i int, s *goquery.Selection) {
e.Log(s.Text())
})
doc.Find("table .aa_ss_ops_new").Each(func(i int, s *goquery.Selection) { doc.Find("table .aa_ss_ops_new").Each(func(i int, s *goquery.Selection) {
e.Log(s.Text())
titles = append(titles, strings.TrimSpace(s.Text())) titles = append(titles, strings.TrimSpace(s.Text()))
}) })
}).End() }).End()
@ -219,9 +225,9 @@ func GetAllAvailable(name string, onlyHEVC bool) ([]Anime, error) {
cols = cols.Next() // Filename cols = cols.Next() // Filename
title := cols.Text() title := cols.Text()
if !strings.Contains(title, "[ENG]") { /*if !strings.Contains(title, "[ENG]") {
return return
} }*/
isHEVC := strings.Contains(title, "[HEVC]") isHEVC := strings.Contains(title, "[HEVC]")
if onlyHEVC && !isHEVC { if onlyHEVC && !isHEVC {