Beispiel #1
0
 def mfile( me, what):
     name = getattr( options, what, None)
     if not name: return
     fl = 'w'
     if name[0]=='+':
         fl = 'a'
         name = name[1:]
     if me.mfnames.get( what) == name: fl = 'a'
     me.mfnames[ what] = name
     return eutf.filew_utf( name, fl)
Beispiel #2
0
def go( fime, fdir, nedei =False, command =None, move =True, decode =False):
    class Ddf( DictAttr):
        def __missing__( az, k): return ''
    ot_ime = Ddf( razglobi( fime))
    ot_ime.setdefault( 'ime', '_')
    cnomer = ot_ime.get( 'nomer')
    opis = '''
име: {ime}
етикети: {zagolemi} {dok}
издание: радио
откъде: {rubrika} {data}
'''.format( **ot_ime ) + '\n'.join(
        v+': '+str(ot_ime[k]) for k,v in dict(
        godina  = 'година',
        nomer   = '#част',
        avtori_plus = 'автор',
        opisanie= 'опис',
        ).items() if ot_ime.get(k) )

    opis = opis.strip()
    print( opis)
    opis += '''
срез:
участници:
 редактор:
 превод:
 драматизация:
 изпълнение:
 музика:
 запис:
 з.реж:
 з.оп:
 з.оф:
 м.оф:
 режисьор:
съдържание:
описание:

# vim:ts=4:sw=4:expandtab:ft=yaml'''

    dirname = ot_ime.get( 'dirname', fime )
    nomer   = cnomer

    print( '-----'*4)
    if nedei: return

    dir = join( fdir, dirname)
    orgdir = join( dir, '0')

    osextra.makedirs( orgdir, exist_ok= True)

    fnomer = nomer and '.'+str( nomer) or ''
    if not command: ext = '.wav'
    else: ext = ot_ime.ext
    wime = join( dir, dirname + fnomer + ext)
    print( ' > ', dir)
    print( ' >>', wime)

    if command:
        command( fime, wime)
        return

    fopis = join( dir, 'opis')
    while exists( fopis): fopis+='1'
    with eutf.filew_utf( fopis ) as f:
        print( opis, file= f)

    print( move and 'mv' or 'ln', fime, orgdir)
    bezext,ext = splitext( fime)
    ima_wav = False
    for f in glob( osextra.globescape( bezext)+'.*'):
        bf = basename( f)
        if f.endswith( '.wav'):
            ima_wav = True
            if cnomer: bf = str(cnomer)+'.'+bf
        (move and os.rename or os.link)( f, join( orgdir, bf ))

    #os.rename( fime, nime)
    if not ima_wav and optz.decode:
        bf = basename( fime)
        nime = join( orgdir, bf)
        if cnomer: bf = str(cnomer)+'.'+bf
        wwime = splitext( join( orgdir, bf))[0]+'.wav'
        if nime.endswith('.flac'):
            cmds = [ 'flac', '-d', '-o', wwime, nime ]
            print( cmds)
            subprocess.call( cmds)
        elif nime.endswith('.mp3'):
            cmds = 'lame --nohist -h -v -V 0 -S --decode'.split() + [ nime, wwime ]
            print( cmds)
            subprocess.call( cmds)