Esempio 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
Esempio 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])
Esempio 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])
Esempio 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)
 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) ])
Esempio 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)])
Esempio n. 7
0
def mp3secs(mp3file):
    secs = 0
    if _bHaveMp3:
        secs = sum([mp3.time(h) for h,f in mp3.frames(mp3file)])
    return secs
Esempio n. 8
0
def mp3secs(mp3file):
    secs = 0
    if _bHaveMp3:
        secs = sum([mp3.time(h) for h, f in mp3.frames(mp3file)])
    return secs