Exemplo n.º 1
0
def build_hash(target, hash_type=hash_type_default):
    """
    Build hash from mp3 data frames in target.

    :param target: object to act on
    :param hash_type: hash to retrieve (optional)
    :rtype: hashlib HASH
    """
    hgen = hashlib.new(hash_type)
    f = open(get_filename(target), 'rb')
    for (hdr, frm) in MP3.frames(f):
        hgen.update(frm)
    return hgen
Exemplo n.º 2
0
 def testGoodFrame(self):
     f = stringio(good_frame_data)
     
     # old-style
     l = list(mp3.frames(f))
     self.assertEquals(len(l), 1)
     self.assertEquals(l, [ (good_frame_header, good_frame_data) ])
     
     # new-style
     f.seek(0)
     r = mp3.Reader(f)
     l = list(r.frames())
     self.assertEquals(len(l), 1)
     self.assertEquals(l, [good_frame_new])
Exemplo n.º 3
0
    def testGoodFrame(self):
        f = stringio(good_frame_data)

        # old-style
        l = list(mp3.frames(f))
        self.assertEquals(len(l), 1)
        self.assertEquals(l, [(good_frame_header, good_frame_data)])

        # new-style
        f.seek(0)
        r = mp3.Reader(f)
        l = list(r.frames())
        self.assertEquals(len(l), 1)
        self.assertEquals(l, [good_frame_new])
Exemplo n.º 4
0
    def handle(self):
        station = self.rfile.readline().split(b' ')[1]
        print('Connection from {}'.format(self.client_address[0]))
        print('They want to play {}'.format(station))

        self.wfile.write(
            b'HTTP/1.1 200 OK\r\nContent-Type: audio/mpeg\r\n\r\n')

        while True:
            music_files = list(glob.glob('music/*.mp3'))
            f = random.choice(music_files)
            with open(f, 'rb') as music_file:
                seconds = 0
                for i, (head, fram) in enumerate(mp3.frames(music_file)):
                    self.wfile.write(fram)
                    seconds += mp3.time(head)
                    t = mp3.time(head) * 0.95
                    time.sleep(t)
Exemplo n.º 5
0
 def testGoodFrame(self):
     f = stringio(good_frame)
     l = list(mp3.frames(f))
     self.assertEquals(len(l), 1)
     self.assertEquals(l, [ (good_frame_header, good_frame) ])
Exemplo n.º 6
0
 def testGoodFrame(self):
     f = stringio(good_frame)
     l = list(mp3.frames(f))
     self.assertEquals(len(l), 1)
     self.assertEquals(l, [(good_frame_header, good_frame)])
Exemplo n.º 7
0
def mp3secs(mp3file):
    secs = 0
    if _bHaveMp3:
        secs = sum([mp3.time(h) for h,f in mp3.frames(mp3file)])
    return secs
Exemplo n.º 8
0
def mp3secs(mp3file):
    secs = 0
    if _bHaveMp3:
        secs = sum([mp3.time(h) for h, f in mp3.frames(mp3file)])
    return secs