it's workinggggg
This commit is contained in:
parent
dbed8bb926
commit
a236ef5a51
2 changed files with 41 additions and 5 deletions
12
convert.py
Normal file
12
convert.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
import subprocess as sp
|
||||
import tempfile
|
||||
|
||||
def ogg(inf):
|
||||
_, temppath = tempfile.mkstemp()
|
||||
p1 = sp.Popen(["ffmpeg", "-loglevel", "warning", "-i", inf, "-f", "flac", "-"], stdout=sp.PIPE)
|
||||
p2 = sp.Popen(["oggenc", "-Q", "-", "-o", temppath], stdin=p1.stdout, stdout=sp.PIPE)
|
||||
p1.stdout.close()
|
||||
_, err = p2.communicate()
|
||||
if err:
|
||||
raise Exception(err)
|
||||
return temppath
|
34
unsync.py
34
unsync.py
|
@ -6,8 +6,11 @@ from __future__ import print_function
|
|||
import os
|
||||
import os.path
|
||||
import sys
|
||||
import shutil
|
||||
import mutagen
|
||||
|
||||
import mutaext
|
||||
import convert
|
||||
|
||||
updatabletags = [\
|
||||
'albumartist', 'composer', 'comment' \
|
||||
|
@ -17,6 +20,9 @@ updatabletags = [\
|
|||
updatabletags.extend(mutaext.replaygain_tags)
|
||||
updatabletags.extend(mutaext.extra_tags)
|
||||
|
||||
alltags = list(updatabletags)
|
||||
alltags.extend(['artist', 'album', 'title'])
|
||||
|
||||
def G(d, k):
|
||||
try:
|
||||
return d[k]
|
||||
|
@ -39,7 +45,7 @@ def shouldsync(md):
|
|||
sync = G(md, 'sync')
|
||||
try:
|
||||
rating = int(rating[0])
|
||||
except (IndexError, ValueError):
|
||||
except:
|
||||
pass
|
||||
if sync:
|
||||
sync = sync[0].lower()
|
||||
|
@ -102,6 +108,15 @@ def updatemetadata(mdold, mdnew):
|
|||
modified = True
|
||||
return modified
|
||||
|
||||
def makefilename(md):
|
||||
fn = ""
|
||||
title = md['title'][0]
|
||||
artist = md['artist'][0]
|
||||
album = md['album'][0]
|
||||
fn = u"{1} - {2} - {0}".format(title,artist,album)
|
||||
fn += ".ogg"
|
||||
return fn
|
||||
|
||||
def run(args):
|
||||
if not len(args) in (2, 3):
|
||||
print("I need a path or two!", file=sys.stderr)
|
||||
|
@ -129,8 +144,8 @@ def run(args):
|
|||
|
||||
if inonly:
|
||||
return 0
|
||||
# TODO: don't print anything
|
||||
print("Beginning matching...", file=sys.stderr)
|
||||
|
||||
print("Matching...", file=sys.stderr)
|
||||
|
||||
outdir = args[2]
|
||||
for p in paths(outdir):
|
||||
|
@ -141,12 +156,21 @@ def run(args):
|
|||
print("UPD", p)
|
||||
md.save()
|
||||
else:
|
||||
pass #print("DEL", p)
|
||||
# delete files here
|
||||
print("DEL", p)
|
||||
os.remove(p)
|
||||
|
||||
for md in tosync:
|
||||
if md.seen == False:
|
||||
print("ADD", md.path)
|
||||
outf = os.path.join(outdir, makefilename(md))
|
||||
#print("TO", outf)
|
||||
temppath = convert.ogg(md.path)
|
||||
mdnew = mutagen.File(temppath, easy=True)
|
||||
for tag in alltags:
|
||||
if tag in md:
|
||||
mdnew[tag] = md[tag]
|
||||
mdnew.save()
|
||||
shutil.move(temppath, outf)
|
||||
|
||||
return 0
|
||||
|
||||
|
|
Loading…
Reference in a new issue