Skip to content

Commit

Permalink
feat: add validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Caixetadev committed Jan 6, 2024
1 parent 34d0a44 commit 3f73c61
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
15 changes: 9 additions & 6 deletions cmd/gophimation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
// Fazer opção para voltar para a lista de animes.

import (
"fmt"
"os"

"github.com/Caixetadev/gophimation/pkg/constants"
Expand Down Expand Up @@ -37,15 +36,19 @@ func main() {

case len(os.Args) > 1:
animeSearch := search.Search()
episodeSelected, _ := episode.SelectEpisode(animeSearch)
selectVideo.SelectVideo(episodeSelected)

episodeSelected, nextEpisode := episode.SelectEpisode(animeSearch)
videoSelected := selectVideo.SelectVideo(episodeSelected)
if nextEpisode != nil {
go selectVideo.SelectVideo(*nextEpisode)
}
util.PlayVideo(videoSelected.Url, videoSelected.Name)
default:
animeMostWatched := mostWatched.MostWatched()
episodeSelected, nextEpisode := episode.SelectEpisode(animeMostWatched)
fmt.Printf("EP SELECIONADO: %s. PROXIMO EP: %s\n", episodeSelected, nextEpisode)
videoSelected := selectVideo.SelectVideo(episodeSelected)
go selectVideo.SelectVideo(nextEpisode)
if nextEpisode != nil {
go selectVideo.SelectVideo(*nextEpisode)
}
util.PlayVideo(videoSelected.Url, videoSelected.Name)
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/episode/episode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/gocolly/colly"
)

func SelectEpisode(URL string) (string, string) {
func SelectEpisode(URL string) (string, *string) {
var selectedOption int
var episodes []models.Anime

Expand Down Expand Up @@ -56,5 +56,9 @@ func SelectEpisode(URL string) (string, string) {

go presence.Presence("https:"+image, nameAnime, fmt.Sprintf("Episódio %02d", selectedOption), "https://www.stickersdevs.com.br/wp-content/uploads/2022/01/gopher-adesivo-sticker.png")

return episodes[selectedOption-1].URL, episodes[(selectedOption+1)-1].URL
if selectedOption == len(episodes) {
return episodes[selectedOption-1].URL, nil
}

return episodes[selectedOption-1].URL, &episodes[(selectedOption+1)-1].URL
}
11 changes: 9 additions & 2 deletions pkg/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ package random
import (
"github.com/Caixetadev/gophimation/pkg/episode"
"github.com/Caixetadev/gophimation/pkg/selectVideo"
"github.com/Caixetadev/gophimation/pkg/util"
)

func Random() {
s, _ := episode.SelectEpisode("random")
selectVideo.SelectVideo(s)
episodeSelected, nextEpisode := episode.SelectEpisode("random")

videoSelected := selectVideo.SelectVideo(episodeSelected)
if nextEpisode != nil {
go selectVideo.SelectVideo(*nextEpisode)
}

util.PlayVideo(videoSelected.Url, videoSelected.Name)
}

0 comments on commit 3f73c61

Please sign in to comment.