internal

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LinkPriorities = []string{
	"sharepoint.com",
	"wixmp.com",
	"dropbox.com",
	"wetransfer.com",
	"gogoanime.com",
}

LinkPriorities defines the order of priority for link domains

Functions

func AddAnimeToWatchingList

func AddAnimeToWatchingList(animeID int, token string) error

Function to add an anime to the watching list

func AddNewAnime added in v0.0.3

func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime, logFile string)

func ClearLogFile

func ClearLogFile(logFile string) error

ClearLogFile removes all contents from the specified log file

func ClearScreen

func ClearScreen()

ClearScreen clears the terminal screen and saves the state

func ConvertSecondsToMinutes

func ConvertSecondsToMinutes(seconds int) int

func DiscordPresence

func DiscordPresence(clientId string, anime Anime) error

func EditConfig

func EditConfig(configFilePath string)

func EpisodesList

func EpisodesList(showID, mode string) ([]string, error)

episodesList performs the API call and fetches the episodes list

func ExitCurd

func ExitCurd(err error)

func FindKeyByValue

func FindKeyByValue(m map[string]string, value string) (string, error)

FindKeyByValue searches for a key associated with a given value in a map[string]string

func GetAndParseAniSkipData

func GetAndParseAniSkipData(animeMalId int, episode int, timePrecision int, anime *Anime) error

GetAndParseAniSkipData fetches and parses skip times for a given anime ID and episode

func GetAniSkipData

func GetAniSkipData(animeMalId int, episode int) (string, error)

GetAniSkipData fetches skip times data for a given anime ID and episode

func GetAnilistUserID

func GetAnilistUserID(token string) (int, string, error)

Function to get AniList user ID and username

func GetAnimeIDAndImage

func GetAnimeIDAndImage(anilistMediaID int) (int, string, error)

This function retrieves the MAL ID and cover image URL for an anime from AniList

func GetAnimeMalID

func GetAnimeMalID(anilistMediaID int) (int, error)

Function to get MAL ID using AniList media ID

func GetAnimeMap

func GetAnimeMap(animeList AnimeList) map[string]string

GetAnimeMap takes an AnimeList and returns a map with media.id as key and media.title.english as value.

func GetAnimeName

func GetAnimeName(anime Anime) string

Function to get the anime name (English or Romaji) from an Anime struct

func GetEpisodeData

func GetEpisodeData(animeID int, episodeNo int, anime *Anime) error

GetEpisodeData fetches episode data for a given anime ID and episode number

func GetEpisodeURL

func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error)

Get anime episode url respective to given config If the link is found, it returns a list of links. Otherwise, it returns an error.

Parameters: - config: Configuration of the anime search. - id: Allanime id of the anime to search for. - epNo: Anime episode number to get links for.

Returns: - []string: a list of links for specified episode. - error: an error if the episode is not found or if there is an issue during the search.

func GetMPVPausedStatus

func GetMPVPausedStatus(ipcSocketPath string) (bool, error)

func GetMPVPlaybackSpeed

func GetMPVPlaybackSpeed(ipcSocketPath string) (float64, error)

func GetPercentageWatched

func GetPercentageWatched(ipcSocketPath string) (float64, error)

func GetTokenFromFile

func GetTokenFromFile(filePath string) (string, error)

func GetUserData

func GetUserData(token string, userID int) (map[string]interface{}, error)

Function to get user data from AniList

func LoadJSONFile

func LoadJSONFile(filePath string) (map[string]interface{}, error)

Function to load a JSON file

func LocalAddAnime

func LocalAddAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, watchingTime int, animeDuration int, animeName string)

Function to add an anime entry

func LocalDeleteAnime

func LocalDeleteAnime(databaseFile string, anilistID int, allanimeID string)

Function to delete an anime entry by Anilist ID and Allanime ID

func LocalUpdateAnime

func LocalUpdateAnime(databaseFile string, anilistID int, allanimeID string, watchingEpisode int, playbackTime int, animeDuration int, animeName string) error

Function to update or add a new anime entry

func Log

func Log(data interface{}, logFile string) error

LogData logs the input data into a specified log file with the format [LOG] time lineNumber: logData

func MPVSendCommand

func MPVSendCommand(ipcSocketPath string, command []interface{}) (interface{}, error)

func ParseAniSkipResponse

func ParseAniSkipResponse(responseText string, anime *Anime, timePrecision int) error

ParseAniSkipResponse parses the response text from the AniSkip API and updates the Anime struct

func PercentageWatched

func PercentageWatched(playbackTime int, duration int) float64
func PrioritizeLink(links []string) string

PrioritizeLink takes an array of links and returns a single link based on priority

func RateAnime

func RateAnime(token string, mediaID int, score float64) error

Function to rate an anime on AniList

func RestoreScreen

func RestoreScreen()

RestoreScreen restores the original terminal state

func RoundTime

func RoundTime(timeValue float64, precision int) float64

RoundTime rounds a time value to the specified precision

func SearchAnime

func SearchAnime(query, mode string) (map[string]string, error)

searchAnime performs the API call and fetches anime information

func SearchAnimeAnilist

func SearchAnimeAnilist(query, token string) (map[string]string, error)

SearchAnimeAnilist sends the query to AniList and returns a map of title to ID

func SearchAnimeByTitle

func SearchAnimeByTitle(jsonData map[string]interface{}, searchTitle string) []map[string]interface{}

Function to search for an anime by title in user data

func SeekMPV

func SeekMPV(ipcSocketPath string, time int) (interface{}, error)

func SetupCurd

func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime, logFile string)

func StartCurd

func StartCurd(userCurdConfig *CurdConfig, anime *Anime, logFile string) string

func StartVideo

func StartVideo(link string, args []string) (string, error)

func UpdateAnimeProgress

func UpdateAnimeProgress(token string, mediaID, progress int) error

Function to update anime progress

func UpdateCurd

func UpdateCurd(repo, fileName string) error

func WriteTokenToFile

func WriteTokenToFile(token string, filePath string) error

CreateOrWriteTokenFile creates the token file if it doesn't exist and writes the token to it

Types

type AniListAnime

type AniListAnime struct {
	ID    int `json:"id"`
	Title struct {
		Romaji  string `json:"romaji"`
		English string `json:"english"`
		Native  string `json:"native"`
	} `json:"title"`
}

AniListAnime is the struct for the API response

type Anime

type Anime struct {
	Title         AnimeTitle `json:"title"`
	Ep            Episode    `json:"ep"`
	CoverImage    string     `json:"url"`            // Assuming this field corresponds to the cover image URL
	TotalEpisodes int        `json:"total_episodes"` // If provided by the API
	MalId         int        `json:"mal_id"`
	AnilistId     int        `json:"anilist_id"` // Assuming you have an Anilist ID in your struct
	Rewatching    bool
	AllanimeId    string // Can be populated as necessary
}

func FindAnimeByAnilistIDInAnimes

func FindAnimeByAnilistIDInAnimes(animes []Anime, anilistID int) (*Anime, error)

FindAnimeByAnilistIDInAnimes searches for an anime by its AniList ID in a slice of Anime

func GetAnimeDataByID

func GetAnimeDataByID(anilistID int, token string) (Anime, error)

GetAnimeDataByID retrieves detailed anime data from AniList using the anime's ID and user token

func LocalFindAnime

func LocalFindAnime(animeList []Anime, anilistID int, allanimeID string) *Anime

Function to find an anime by either Anilist ID or Allanime ID

func LocalGetAllAnime

func LocalGetAllAnime(databaseFile string) []Anime

Function to get all anime entries from the database

type AnimeList

type AnimeList struct {
	Watching  []Entry `json:"watching"`
	Completed []Entry `json:"completed"`
	Paused    []Entry `json:"paused"`
	Dropped   []Entry `json:"dropped"`
	Planning  []Entry `json:"planning"`
}

func ParseAnimeList

func ParseAnimeList(input map[string]interface{}) AnimeList

type AnimeTitle

type AnimeTitle struct {
	Romaji   string `json:"title_romanji"`
	English  string `json:"title"`
	Japanese string `json:"title_japanese"`
}

type CurdConfig

type CurdConfig struct {
	Player                   string `config:"Player"`
	SubsLanguage             string `config:"SubsLanguage"`
	SubOrDub                 string `config:"SubOrDub"`
	StoragePath              string `config:"StoragePath"`
	PercentageToMarkComplete int    `config:"PercentageToMarkComplete"`
	NextEpisodePrompt        bool   `config:"NextEpisodePrompt"`
	SkipOp                   bool   `config:"SkipOp"`
	SkipEd                   bool   `config:"SkipEd"`
	SkipFiller               bool   `config:"SkipFiller"`
	SkipRecap                bool   `config:"SkipRecap"`
	ScoreOnCompletion        bool   `config:"ScoreOnCompletion"`
	SaveMpvSpeed             bool   `config:"SaveMpvSpeed"`
	DiscordPresence          bool   `config:"DiscordPresence"`
}

CurdConfig struct with field names that match the config keys

func LoadConfig

func LoadConfig(configPath string) (CurdConfig, error)

LoadConfig reads or creates the config file, adds missing fields, and returns the populated CurdConfig struct

type Entry

type Entry struct {
	Media    Media   `json:"media"`
	Progress int     `json:"progress"`
	Score    float64 `json:"score"`
	Status   string  `json:"status"`
}

func FindAnimeByAnilistID

func FindAnimeByAnilistID(list AnimeList, idStr string) (*Entry, error)

FindAnimeByID searches for an anime by its ID in the AnimeList

type Episode

type Episode struct {
	Title        AnimeTitle   `json:"title"`
	Number       int          `json:"number"`
	SkipTimes    SkipTimes    `json:"skip_times"`
	Player       playingVideo `json:"player"`
	Resume       bool         `json:"resume"`
	Started      bool         `json:"started"`
	Duration     int          `json:"duration"`
	Links        []string     `json:"links"`
	IsFiller     bool         `json:"filler"`
	IsRecap      bool         `json:"recap"`
	Aired        string       `json:"aired"`
	Synopsis     string       `json:"synopsis"`
	ContinueLast bool
	IsCompleted  bool
}

type Media

type Media struct {
	Duration int        `json:"duration"`
	Episodes int        `json:"episodes"`
	ID       int        `json:"id"`
	Title    AnimeTitle `json:"title"`
}

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model represents the application state for the selection prompt

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the model

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles user input and updates the model

func (Model) View

func (m Model) View() string

View renders the UI and only shows as many options as fit in the terminal

type Page

type Page struct {
	Media []AniListAnime `json:"media"`
}

Page represents the page in AniList response

type ResponseData

type ResponseData struct {
	Page Page `json:"Page"`
}

ResponseData represents the full response structure

type SelectionOption

type SelectionOption struct {
	Label string
	Key   string
}

SelectionOption holds the label and the internal key

func DynamicSelect

func DynamicSelect(options map[string]string) (SelectionOption, error)

DynamicSelect displays a simple selection prompt without extra features

type Skip

type Skip struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

type SkipTimes

type SkipTimes struct {
	Op Skip `json:"op"`
	Ed Skip `json:"ed"`
}

type User

type User struct {
	Token     string
	Username  string
	Id        int
	AnimeList AnimeList
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL