<commit_before>package nsf

import (
	"fmt"
	"time"

	"github.com/mjibson/mog/codec"
	"github.com/mjibson/nsf"
)

func init() {
	codec.RegisterCodec("NSF", "NESM\u001a", []string{"nsf"}, ReadNSFSongs)
}

func ReadNSFSongs(rf codec.Reader) ([]codec.Song, error) {
	r, _, err := rf()
	if err != nil {
		return nil, err
	}
	defer r.Close()
	n, err := nsf.ReadNSF(r)
	if err != nil {
		return nil, err
	}
	songs := make([]codec.Song, n.Songs)
	for i := range songs {
		songs[i] = &NSFSong{
			NSF:    n,
			Index:  i + 1,
			Reader: rf,
		}
	}
	return songs, nil
}

type NSFSong struct {
	NSF     *nsf.NSF
	Index   int
	Playing bool
	Reader  codec.Reader
}

func (n *NSFSong) Init() (sampleRate, channels int, err error) {
	if n.NSF == nil {
		r, _, err := n.Reader()
		if err != nil {
			return 0, 0, err
		}
		defer r.Close()
		n.NSF, err = nsf.ReadNSF(r)
		if err != nil {
			return 0, 0, err
		}
	}
	n.NSF.Init(n.Index)
	n.Playing = true
	return int(n.NSF.SampleRate), 1, nil
}

func (n *NSFSong) Play(samples int) ([]float32, error) {
	return n.NSF.Play(samples), nil
}

func (n *NSFSong) Close() {
	n.NSF = nil
	n.Playing = false
}

func (n *NSFSong) Info() (si codec.SongInfo, err error) {
	if n.NSF != nil {
		si = codec.SongInfo{
			Time:   time.Minute * 2,
			Artist: n.NSF.Artist,
			Album:  n.NSF.Song,
			Track:  float64(n.Index),
			Title:  fmt.Sprintf("%s:%02d", n.NSF.Song, n.Index),
		}
		return
	}
	r, _, err := n.Reader()
	if err != nil {
		return
	}
	defer r.Close()
	ns, err := nsf.ReadNSF(r)
	if err != nil {
		return
	}
	si = codec.SongInfo{
		Time:   time.Minute * 2,
		Artist: ns.Artist,
		Album:  ns.Song,
		Track:  float64(n.Index),
		Title:  fmt.Sprintf("%s:%d", ns.Song, n.Index),
	}
	return
}<commit_msg>Use NSF's new time limit<commit_after>package nsf

import (
	"fmt"

	"github.com/mjibson/mog/codec"
	"github.com/mjibson/nsf"
)

func init() {
	codec.RegisterCodec("NSF", "NESM\u001a", []string{"nsf"}, ReadNSFSongs)
}

func ReadNSFSongs(rf codec.Reader) ([]codec.Song, error) {
	r, _, err := rf()
	if err != nil {
		return nil, err
	}
	defer r.Close()
	n, err := nsf.ReadNSF(r)
	if err != nil {
		return nil, err
	}
	songs := make([]codec.Song, n.Songs)
	for i := range songs {
		songs[i] = &NSFSong{
			NSF:    n,
			Index:  i + 1,
			Reader: rf,
		}
	}
	return songs, nil
}

type NSFSong struct {
	NSF     *nsf.NSF
	Index   int
	Playing bool
	Reader  codec.Reader
}

func (n *NSFSong) Init() (sampleRate, channels int, err error) {
	if n.NSF == nil {
		r, _, err := n.Reader()
		if err != nil {
			return 0, 0, err
		}
		defer r.Close()
		n.NSF, err = nsf.ReadNSF(r)
		if err != nil {
			return 0, 0, err
		}
	}
	n.NSF.Init(n.Index)
	n.Playing = true
	return int(n.NSF.SampleRate), 1, nil
}

func (n *NSFSong) Play(samples int) ([]float32, error) {
	return n.NSF.Play(samples), nil
}

func (n *NSFSong) Close() {
	n.NSF = nil
	n.Playing = false
}

func (n *NSFSong) Info() (si codec.SongInfo, err error) {
	if n.NSF != nil {
		si = codec.SongInfo{
			Time:   n.NSF.Limit,
			Artist: n.NSF.Artist,
			Album:  n.NSF.Song,
			Track:  float64(n.Index),
			Title:  fmt.Sprintf("%s:%02d", n.NSF.Song, n.Index),
		}
		return
	}
	r, _, err := n.Reader()
	if err != nil {
		return
	}
	defer r.Close()
	ns, err := nsf.ReadNSF(r)
	if err != nil {
		return
	}
	si = codec.SongInfo{
		Time:   ns.Limit,
		Artist: ns.Artist,
		Album:  ns.Song,
		Track:  float64(n.Index),
		Title:  fmt.Sprintf("%s:%d", ns.Song, n.Index),
	}
	return
}
{'fraction_non_alphanumeric': 0.1749710312862109, 'fraction_numerical': 0.010428736964078795, 'mean_word_length': 2.853794642857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3899059', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1536, 'n_words': 373}