예제 #1
0
def toc( cyr2lat =False):
    if 0:
        print( '''
CD_DA
 CD_TEXT {
  LANGUAGE_MAP { 0 : EN }
  LANGUAGE 0 {
    TITLE "Title"
    PERFORMER "Performer"
  } }
''')
    allsize = 0
    for a in albumi.values():
        print( '\n//group=', a.album )
        groupsize = 0
        for i in a.items:
            d = dict( i,
                pause   = i.pause and 'PREGAP 0:%(pause)s:0' % i or '',
                psecs   = prnsec( i.secs),
                )
            if cyr2lat:
                d['title'] = zaglavie( lat2cyr.zvuchene.cyr2lat( i.title))

            print( '''\
 TRACK AUDIO
  COPY
  CD_TEXT { LANGUAGE 0 {
    TITLE "%(title)s"
   } }
  %(pause)s
  FILE "%(fname)s" 0
  //size= %(psecs)s
  //secs= %(secs).1f
''' % d )
            ssize = i.secs + i.pause
            allsize += ssize
            groupsize += ssize
        print( '//groupsize=', prnsec( groupsize), a.album )
        print( '//allsize=', prnsec( allsize) )
    print( '\n//allsize=', prnsec( allsize) )
예제 #2
0
    def write( me,
            maketoc =False,
            scale   =1,
            fps     =1,
            offset  =0,
            do_nothing  =False,
            verbose     =False,
            makedir = False,
            path    = '',
            ofile   = None,
            ofile_as_sfx =None, #priority over ofile
            infile  = None,
            inpath  = '.',
            **kargs_ignore
            ):
        options = DictAttr( locals())

        if not infile.startswith( '/') :
            infile = join( inpath, infile)

        if options.verbose:
            print( infile)
            for c in me.cuts: print( ' '.join( k+'='+str(v) for k,v in c.items()))

        for a in infile, splitext( infile)[0]:
            a += '.wav'
            if exists( a):
                infile = a
                break
        else:
            print( '!!! nema go', a)
            return

        import wave
        i = wave.open( infile, 'r')
        cur = 0
        p = DictAttr()
        params = (p.nchannels, p.sampwidth, p.framerate, p.nframes, p.comptype, p.compname) = i.getparams()
        #size = p.nframes/float(p.framerate)
        #print nframes, framerate
        if verbose: print( '%sHz %s x %sbit' % (p.framerate, p.nchannels, p.sampwidth*8))

        def sec2frames(sec):
            return int(sec * p.framerate)

        ofile = basename( ofile or infile)    #no dirs
        for a in 'wav avi flac mp3'.split():
            if ofile.endswith( '.'+a): ofile = ofile[:-1-len(a)]
        if ofile_as_sfx: ofile += ofile_as_sfx
        opath = options.path
        if opath:
            makedirs( opath)
            ofile = join( opath, ofile)
        if options.makedir:
            makedirs( ofile)
            ofile += '/'
        else:
            ofile += '.'

        nfmt = len(me.cuts)>=10 and '%02d' or '%d'
        n=0
        oname = ''
        for rec in me.cuts:
            #print '> %(name)r : %(start)s - %(end)s  %(nopause)s' % rec
            nopause = rec.nopause and 'nopause' or ''

            if not rec.name:
                assert oname
                #oname = oname + '.x'   #има номерация и без това
            else:
                oname = rec.name
            ss = sum( point2sec( x, options.scale, options.fps ) for x in rec.start.split('+'))
            se = sum( point2sec( x, options.scale, options.fps ) for x in rec.end.split('+'))
            if options.offset:
                ss += options.offset
                se += options.offset
            fs,fe = [sec2frames(x) for x in (ss,se) ]
            print( ' ', oname, '>', prnsec(ss),':', prnsec(se), nopause)

            n+=1
            ooname = ofile + '.'.join( [ nfmt % n, oname, 'wav'] )
            print( '      ', ooname)

            if options.do_nothing and (not maketoc or fe <= p.nframes): continue

            skip = fs-cur
            while skip:
                sk = min( 9*60, skip)    #11mb/min
                i.readframes( sk)
                skip -= sk
            data = i.readframes( fe - fs )
            assert data
            cur = fe

            size = se-ss if fe <= p.nframes else len(data)/float( p.nchannels * p.sampwidth * p.framerate)
            me.add2toc( nomer= n, src= ofile, name= oname, fname= ooname, nopause= nopause, size= size,)

            if options.do_nothing: continue

            o = wave.open( ooname, 'w')
            o.setparams( params)
            o.writeframes( data)
            o.close()