<commit_before>package itunes

import (
	"errors"
	"log"
	"sync"

	"github.com/go-ole/go-ole"
	"github.com/go-ole/go-ole/oleutil"
)

type track struct {
	handle    *ole.IDispatch
	artworks  *ole.IDispatch
	wg        *sync.WaitGroup
	parent    *sync.WaitGroup
	closeChan chan bool

	Name   string
	Artist string
}

func createTrack(handle *ole.IDispatch, parent *sync.WaitGroup) (*track, error) {
	if handle == nil {
		return nil, errors.New("handle is nil")
	}
	parent.Add(1)
	properties := [...]string{
		"Name", "Artist",
	}
	values := make([]string, len(properties))

	for i, property := range properties {
		v, err := oleutil.GetProperty(handle, property)
		if err != nil {
			return nil, err
		}

		values[i] = v.ToString()
	}

	track := &track{
		handle:    handle,
		Name:      values[0],
		Artist:    values[1],
		closeChan: make(chan bool),
		parent:    parent,
		wg:        new(sync.WaitGroup),
	}

	return track, nil
}

func (t *track) Close() {
	close(t.closeChan)
	t.wg.Wait()

	t.handle.Release()
	if t.artworks != nil {
		t.artworks.Release()
	}

	t.parent.Done()
}

func (t *track) Play() error {
	_, err := t.handle.CallMethod("Play")
	return err
}

func (t *track) GetArtworks() (chan *artwork, error) {
	t.wg.Add(1)<commit_msg>fix close handle when calling play function<commit_after>package itunes

import (
	"errors"
	"log"
	"sync"

	"github.com/go-ole/go-ole"
	"github.com/go-ole/go-ole/oleutil"
)

type track struct {
	handle    *ole.IDispatch
	artworks  *ole.IDispatch
	wg        *sync.WaitGroup
	parent    *sync.WaitGroup
	closeChan chan bool

	Name   string
	Artist string
}

func createTrack(handle *ole.IDispatch, parent *sync.WaitGroup) (*track, error) {
	if handle == nil {
		return nil, errors.New("handle is nil")
	}
	parent.Add(1)
	properties := [...]string{
		"Name", "Artist",
	}
	values := make([]string, len(properties))

	for i, property := range properties {
		v, err := oleutil.GetProperty(handle, property)
		if err != nil {
			return nil, err
		}

		values[i] = v.ToString()
	}

	track := &track{
		handle:    handle,
		Name:      values[0],
		Artist:    values[1],
		closeChan: make(chan bool),
		parent:    parent,
		wg:        new(sync.WaitGroup),
	}

	return track, nil
}

func (t *track) Close() {
	close(t.closeChan)
	t.wg.Wait()

	t.handle.Release()
	if t.artworks != nil {
		t.artworks.Release()
	}

	t.parent.Done()
}

func (t *track) Play() error {
	t.wg.Add(1)
	defer t.wg.Done()
	_, err := t.handle.CallMethod("Play")
	return err
}

func (t *track) GetArtworks() (chan *artwork, error) {
	t.wg.Add(1)
{'fraction_non_alphanumeric': 0.15740015661707127, 'fraction_numerical': 0.003523884103367267, 'mean_word_length': 3.216171617161716, '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': '3345124', 'n_tokens_mistral': 1046, 'n_tokens_neox': 978, 'n_words': 234}