<commit_before>package arn

import (
	"bytes"
	"strconv"
	"strings"
)

// AnimeEpisodes ...
type AnimeEpisodes struct {
	AnimeID string          `json:"animeId"`
	Items   []*AnimeEpisode `json:"items"`
}

// Merge combines the data of both episode slices to one.
func (episodes *AnimeEpisodes) Merge(b []*AnimeEpisode) {
	if b == nil {
		return
	}

	for index, episode := range b {
		if index >= len(episodes.Items) {
			episodes.Items = append(episodes.Items, episode)
		} else {
			episodes.Items[index].Merge(episode)
		}
	}
}

// AvailableCount counts the number of available episodes.
func (episodes *AnimeEpisodes) AvailableCount() int {
	available := 0

	for _, episode := range episodes.Items {
		if len(episode.Links) > 0 {
			available++
		}
	}

	return available
}

// String returns a text representation of the anime episodes.
func (episodes *AnimeEpisodes) String() string {
	b := bytes.Buffer{}

	for _, episode := range episodes.Items {
		b.WriteString(strconv.Itoa(episode.Number))
		b.WriteString(" | ")
		b.WriteString(episode.Title.Japanese)
		b.WriteString(" | ")
		b.WriteString(episode.AiringDate.StartDateHuman())
		b.WriteByte('\n')
	}

	return strings.TrimRight(b.String(), "\n")
}

// Save saves the episodes in the database.
func (episodes *AnimeEpisodes) Save() {
	DB.Set("AnimeEpisodes", episodes.AnimeID, episodes)
}

// GetAnimeEpisodes ...
func GetAnimeEpisodes(id string) (*AnimeEpisodes, error) {
	obj, err := DB.Get("AnimeEpisodes", id)

	if err != nil {
		return nil, err
	}

	return obj.(*AnimeEpisodes), nil
}
<commit_msg>Added AnimeEpisodes.Anime()<commit_after>package arn

import (
	"bytes"
	"strconv"
	"strings"

	"github.com/aerogo/nano"
)

// AnimeEpisodes ...
type AnimeEpisodes struct {
	AnimeID string          `json:"animeId"`
	Items   []*AnimeEpisode `json:"items"`
}

// Merge combines the data of both episode slices to one.
func (episodes *AnimeEpisodes) Merge(b []*AnimeEpisode) {
	if b == nil {
		return
	}

	for index, episode := range b {
		if index >= len(episodes.Items) {
			episodes.Items = append(episodes.Items, episode)
		} else {
			episodes.Items[index].Merge(episode)
		}
	}
}

// AvailableCount counts the number of available episodes.
func (episodes *AnimeEpisodes) AvailableCount() int {
	available := 0

	for _, episode := range episodes.Items {
		if len(episode.Links) > 0 {
			available++
		}
	}

	return available
}

// Anime returns the anime.
func (episodes *AnimeEpisodes) Anime() *Anime {
	anime, _ := GetAnime(episodes.AnimeID)
	return anime
}

// String returns a text representation of the anime episodes.
func (episodes *AnimeEpisodes) String() string {
	b := bytes.Buffer{}

	for _, episode := range episodes.Items {
		b.WriteString(strconv.Itoa(episode.Number))
		b.WriteString(" | ")
		b.WriteString(episode.Title.Japanese)
		b.WriteString(" | ")
		b.WriteString(episode.AiringDate.StartDateHuman())
		b.WriteByte('\n')
	}

	return strings.TrimRight(b.String(), "\n")
}

// Save saves the episodes in the database.
func (episodes *AnimeEpisodes) Save() {
	DB.Set("AnimeEpisodes", episodes.AnimeID, episodes)
}

// StreamAnimeEpisodes returns a stream of all anime episodes.
func StreamAnimeEpisodes() chan *AnimeEpisodes {
	channel := make(chan *AnimeEpisodes, nano.ChannelBufferSize)

	go func() {
		for obj := range DB.All("AnimeEpisodes") {
			channel <- obj.(*AnimeEpisodes)
		}

		close(channel)
	}()

	return channel
}

// GetAnimeEpisodes ...
func GetAnimeEpisodes(id string) (*AnimeEpisodes, error) {
	obj, err := DB.Get("AnimeEpisodes", id)

	if err != nil {
		return nil, err
	}

	return obj.(*AnimeEpisodes), nil
}

{'fraction_non_alphanumeric': 0.1381888673497646, 'fraction_numerical': 0.0011077263915812794, 'mean_word_length': 3.8876860622462788, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5648263', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1304, 'n_words': 310}