Exemple #1
0
 def test_len(self):
     playlist = g.Playlist()
     assert len(playlist) == 0
     playlist.extend(self.files)
     assert len(playlist) == 3
     playlist.remove(self.files[1])
     assert len(playlist) == 2
Exemple #2
0
 def test_delitem(self):
     playlist = g.Playlist()
     playlist.extend(self.files)
     del playlist[1]
     assert len(playlist) == 2
     assert playlist[0].file == self.files[0]
     assert playlist[1].file == self.files[2]
Exemple #3
0
def main(infiles):
    _log.debug('Creating a playlist and loudness detector')
    loudness_detector = groove.LoudnessDetector()
    playlist = groove.Playlist()

    _log.debug('Opening files and adding to playlist')
    for infile in infiles:
        gfile = groove.File(infile)
        gfile.open()
        playlist.append(gfile)

    _log.debug('Attaching playlist to detector')
    loudness_detector.playlist = playlist

    _log.debug('Processing playlist')
    for loudness, peak, duration, pitem in loudness_detector:
        if pitem is None:
            print('\nAll files complete.')
        else:
            print('\nfile complete: {0}\n'.format(pitem.file.filename))

        print(
            'suggested gain: {0:.2f}, sample peak: {1}, duration: {2}'.format(
                loudness_to_replaygain(loudness), peak, duration))

    _log.debug('Detaching playlist')
    loudness_detector.playlist = None

    _log.debug('Closing files and clearing playlist')
    while len(playlist) > 0:
        playlist[0].file.close()
        del playlist[0]

    return 0
Exemple #4
0
def main(raw, *infiles):
    # Create a playlist
    playlist = groove.Playlist()

    # open and add all input files to playlist
    for infile in infiles:
        gfile = groove.File(infile)
        gfile.open()
        playlist.append(gfile)

    # Create the fingerprinter and attach the playlist
    printer = groove.Fingerprinter(base64_encode=not raw)
    printer.playlist = playlist

    # Iterate over the fingerprinter
    for fp, duration, pitem in printer:
        print()
        print("duration {}: {}".format(duration, pitem.file.filename))
        print(fp)

    # Detach the playlist
    printer.playlist = None

    # Close and remove files from the playlist
    while len(playlist) > 0:
        playlist[0].file.close()
        del playlist[0]

    return 0
Exemple #5
0
    def test_remove(self):
        playlist = g.Playlist()
        playlist.extend(self.files)
        playlist.remove(self.files[1])
        assert len(playlist) == 2
        assert playlist[0].file == self.files[0]
        assert playlist[1].file == self.files[2]

        with pytest.raises(ValueError):
            playlist.remove(self.files[1])
Exemple #6
0
 def test_setitem(self):
     # Broken, see https://github.com/andrewrk/libgroove/issues/123
     # ATM this probably leaks
     playlist = g.Playlist()
     playlist.append(self.files[0])
     playlist.append(self.files[2])
     playlist[0] = self.files[1]
     assert len(playlist) == 2
     assert playlist[0].file == self.files[1]
     assert playlist[1].file == self.files[2]
Exemple #7
0
 def run(self, result=None):
     with \
         g.File('tests/samples/mono-180hz.mp3') as gf0, \
         g.File('tests/samples/mono-261hz.mp3') as gf1, \
         g.File('tests/samples/mono-523hz.mp3') as gf2:
         self.files = [gf0, gf1, gf2]
         self.playlist = g.Playlist()
         self.playlist.extend(self.files)
         self.sink = g.Sink()
         self.sink.playlist = self.playlist
         print('RUN METHOD')
         return super(TestBuffer, self).run(result)
Exemple #8
0
    def test_getitem(self):
        playlist = g.Playlist()
        playlist.extend(self.files)

        for n in range(-len(self.files), len(self.files)):
            assert playlist[n].file == self.files[n]

        with pytest.raises(IndexError):
            playlist[4]

        with pytest.raises(TypeError):
            playlist[0:2]
Exemple #9
0
def main(bitrate, fmt, codec, mime, outname, *infilenames):
    # Create a playlist and encoder
    playlist = groove.Playlist()
    encoder = groove.Encoder()
    encoder.bitrate = bitrate * 1000
    encoder.format_short_name = fmt
    encoder.codec_short_name = codec
    encoder.mime_type = mime
    encoder.filename = outname

    # Open all the files and add them to the playlist
    for fname in infilenames:
        gfile = groove.File(fname)
        gfile.open()
        playlist.append(gfile, 1.0, 1.0)

    # If we are only converting one file, copy the audio format and metadata
    if len(playlist) == 1:
        pitem = playlist[0]

        infmt = pitem.file.audio_format()
        outfmt = encoder.target_audio_format
        outfmt.clone(infmt)

        tags = pitem.file.get_tags()
        encoder.set_tags(tags)

    # attach the playlist to the encoder
    encoder.playlist = playlist

    # Open the ouput file and write the results
    with open(outname, 'wb') as ofile:
        while True:
            try:
                buff = encoder.get_buffer(True)
            except groove.Buffer.End:
                break
            ofile.write(buff.data)

            # unref the buffer to advance
            buff.unref()

    # Detach the playlist
    encoder.playlist = None

    # Close and remove files from the playlist
    while len(playlist) > 0:
        playlist[0].file.close()
        del playlist[0]

    return 0
Exemple #10
0
    def test_reversed(self):
        playlist = g.Playlist()
        playlist.extend(self.files)

        for item, gfile in zip(reversed(playlist), reversed(self.files)):
            assert item.file == gfile
Exemple #11
0
    def test_iter(self):
        playlist = g.Playlist()
        playlist.extend(self.files)

        for item, gfile in zip(playlist, self.files):
            assert item.file == gfile
Exemple #12
0
 def test_clear(self):
     playlist = g.Playlist()
     playlist.extend(self.files)
     playlist.clear()
     assert len(playlist) == 0
Exemple #13
0
 def test_append(self):
     playlist = g.Playlist()
     playlist.append(self.files[0])
     playlist.append(self.files[1])
     assert playlist[0].file == self.files[0]
     assert playlist[1].file == self.files[1]
Exemple #14
0
 def test_insert(self):
     playlist = g.Playlist()
     playlist.append(self.files[0])
     playlist.append(self.files[1])
     playlist.insert(1, self.files[2])
     assert playlist[1].file == self.files[2]
Exemple #15
0
 def test_index(self):
     playlist = g.Playlist()
     playlist.extend(self.files)
     assert playlist.index(self.files[1]) == 1
Exemple #16
0
 def test_gain(self):
     playlist = g.Playlist()
     playlist.gain = 0.5
     assert playlist.gain == 0.5
Exemple #17
0
 def test_pop(self):
     playlist = g.Playlist()
     playlist.append(self.files[0])
     with pytest.raises(NotImplementedError):
         playlist.pop()
Exemple #18
0
def main(infiles, volume=1.0, exact=False, dummy=False):
    _log.debug('Creating a player and playlist')
    player = groove.Player()
    playlist = groove.Playlist()

    _log.debug('Opening files and adding to playlist')
    for infile in infiles:
        gfile = groove.File(infile)
        gfile.open()
        playlist.append(gfile)

    _log.debug('Setting options for playlist and player')
    playlist.gain = volume
    player.use_exact_audio_format = exact
    player.device = groove.Player.dummy_device if dummy else groove.Player.default_device

    _log.debug('Attaching playlist to player')
    player.playlist = playlist

    _log.debug('Entering player event loop')
    while True:
        _log.debug('Getting event')
        # Can't interrupt this
        # in reality blocking calls should be done in a separate thread
        event = player.event_get(True)
        _log.debug('Got event %d', event)

        if event == None:
            break

        elif event == groove.PlayerEvent.buffer_underrun:
            _log.error('Buffer underrun')
            continue

        elif event == groove.PlayerEvent.device_reopened:
            _log.error('Device re-opened')
            continue

        elif event == groove.PlayerEvent.now_playing:
            pitem, seconds = player.position()

            if pitem is None:
                _log.debug('Reached end of playlist')
                break

            # Print item info
            _log.debug('Playing new file')
            tags = pitem.file.get_tags()
            if 'artist' in tags and 'title' in tags:
                print('Now playing: {0} - {1}'.format(tags['artist'],
                                                      tags['title']))
            else:
                print('Now playing: {0}'.format(pitem.file.filename))

    _log.debug('Detaching playlist from player')
    player.playlist = None

    _log.debug('Closing files and clearing playlist')
    while len(playlist) > 0:
        playlist[0].file.close()
        del playlist[0]

    return 0