Commit 3d410338 authored by Rob Nelson's avatar Rob Nelson
Browse files

Fix some minor problems

parent 5c2e94aa
......@@ -5,11 +5,7 @@ MIT license
REQUIRES:
sudo apt-get install -y sox libsox-fmt-all libav-tools
<<<<<<< HEAD
sudo -H pip install mutagen pyyaml
=======
pip install mutagen pyyaml
>>>>>>> 4ca9bbac8ccbf336b22c6d79b6929187fa8a9339
'''
import glob
import hashlib
......@@ -29,11 +25,6 @@ from functools import reduce
sys.path.append('lib/ryetalin')
import ryetalin
<<<<<<< HEAD
=======
OUTPUT_DIR=os.path.abspath(u'files-upl')
OUTPUT_EXT=u'mp3' # WAS MP3
>>>>>>> 4ca9bbac8ccbf336b22c6d79b6929187fa8a9339
OUTPUT_DIR = os.path.abspath(u'files-upl')
OUTPUT_EXT = u'mp3' # WAS MP3
......@@ -227,8 +218,9 @@ def check_for_dead_files(infile, basedir=OUTPUT_DIR):
if sys.version_info[0] < 3:
if isinstance(infile, unicode):
infile = infile.decode('utf-8')
if isinstance(infile, bytes):
infile = infile.decode('utf-8')
else:
if isinstance(infile, bytes):
infile = infile.decode('utf-8')
title, ext = os.path.splitext(os.path.basename(infile))
playlist = os.path.relpath(os.path.dirname(infile), u'./' + basedir)
sourcefile = os.path.join(playlist, cleanFilename(title))
......@@ -240,7 +232,7 @@ def check_md5s(infile):
global md5s, deadfiles
pathchunks = infile.split(os.sep)[-3:]
title, ext = os.path.splitext(os.path.basename(infile))
title, _ = os.path.splitext(os.path.basename(infile))
md5 = pathchunks[0] + pathchunks[1] + title
if md5 not in md5s:
deadfiles += [infile]
......@@ -249,9 +241,8 @@ def check_count(_):
global FILECOUNT
FILECOUNT+=1
# Copy the file's tags and convert to id3v2
# Copy the file's tags and convert to id3v2
def update_tags(origf, newf):
orig = ryetalin.Open(origf)
if orig is None:
......@@ -299,7 +290,6 @@ def update_tags(origf, newf):
class TimeExecution(object):
def __init__(self, label):
self.start_time = None
self.label = label
......@@ -309,7 +299,7 @@ class TimeExecution(object):
return self
def __exit__(self, type, value, traceback):
logging.info(' Completed in {1}s - {0}'.format(self.label, secondsToStr(TIME_SOURCE() - self.start_time)))
logging.info(' Completed in %(diff)ds - %(label)s', {'label': self.label, 'diff': secondsToStr(TIME_SOURCE() - self.start_time)})
return False
......@@ -323,8 +313,9 @@ def check_converted(infile, basedir='tmp_files'):
if sys.version_info[0] < 3:
if isinstance(infile, unicode):
infile = infile.decode('utf-8')
if isinstance(infile, bytes):
infile = infile.decode('utf-8')
else:
if isinstance(infile, bytes):
infile = infile.decode('utf-8')
title, ext = os.path.splitext(os.path.basename(infile))
playlist = os.path.relpath(os.path.dirname(infile), u'./' + basedir)
sourcefile = os.path.join(playlist, cleanFilename(title))
......
import mutagen,logging
import mutagen
import logging
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import EasyMP3
from mutagen.easymp4 import EasyMP4, EasyMP4Tags
from mutagen.oggflac import OggFLAC, OggFLACVComment
TagTypes={
EasyMP3 : EasyID3,
EasyMP4 : EasyMP4Tags,
OggFLAC : OggFLACVComment,
#mutagen.ogg.OggOpus : mutagen.ogg.OggOpusVComment,
TagTypes = {
EasyMP3: EasyID3,
EasyMP4: EasyMP4Tags,
OggFLAC: OggFLACVComment,
# mutagen.ogg.OggOpus : mutagen.ogg.OggOpusVComment,
}
class RyeBase(object):
def __init__(self,filename,mutagenf):
# mutagen => rye
self.translation={}
self.filename=filename
#: The actual Mutagen tag handler.
self.mutagen = mutagenf
#: The tag values.
self.tags={}
def load(self):
#print(self.__class__.__name__,self.filename,repr(self.translation))
if self.mutagen is None:
raise Exception('Mutagen unable to open {}'.format(self.filename))
if self.mutagen.tags is None:
self.mutagen.tags = TagTypes[self.mutagen.__class__]()
for tag_name in self.mutagen.tags:
tag_value = None
if isinstance(tag_name,tuple):
tag_name,tag_value = tag_name
else:
tag_value = self.mutagen.tags[tag_name]
if isinstance(tag_value,(tuple,list)):
tag_value=tag_value[0]
if tag_value in (u'0',u''):
continue
tk = self.translateKey(tag_name)
if tk is None:
#logging.warn('Unhandled key {0}'.format(repr(tag_name)))
continue
self.tags[tk]=tag_value
#logging.info(' {0} = {1}'.format(tk,repr(tag_value)))
def getLength(self):
return self.mutagen.info.length
def translateKey(self,key):
return self.translation.get(key,None)
def detranslateKey(self,key):
for k,v in self.translation.items():
if v == key:
return k
return None
def __getitem__(self,key):
return self.tags[key]
def __setitem__(self,key,value):
self.tags[key]=value
def __contains__(self,data):
return data in self.tags
def save(self):
if self.mutagen.tags is None:
self.mutagen.tags = self.mutagen.__class__._Tags()
#print(repr(self.mutagen.tags))
for tag_name in self.tags:
mutatag=self.detranslateKey(tag_name)
self.mutagen.tags[tag_name]=[self.tags[tag_name]]
#print(repr(self.mutagen.tags))
self.mutagen.save()
def __init__(self, filename, mutagenf):
# mutagen => rye
self.translation = {}
self.filename = filename
#: The actual Mutagen tag handler.
self.mutagen = mutagenf
#: The tag values.
self.tags = {}
def load(self):
# print(self.__class__.__name__,self.filename,repr(self.translation))
if self.mutagen is None:
raise Exception('Mutagen unable to open {}'.format(self.filename))
if self.mutagen.tags is None:
self.mutagen.tags = TagTypes[self.mutagen.__class__]()
for tag_name in self.mutagen.tags:
tag_value = None
if isinstance(tag_name, tuple):
tag_name, tag_value = tag_name
else:
tag_value = self.mutagen.tags[tag_name]
if isinstance(tag_value, (tuple, list)):
tag_value = tag_value[0]
if tag_value in (u'0', u''):
continue
tk = self.translateKey(tag_name)
if tk is None:
#logging.warn('Unhandled key {0}'.format(repr(tag_name)))
continue
self.tags[tk] = tag_value
#logging.info(' {0} = {1}'.format(tk,repr(tag_value)))
def getLength(self):
return self.mutagen.info.length
def translateKey(self, key):
return self.translation.get(key, None)
def detranslateKey(self, key):
for k, v in self.translation.items():
if v == key:
return k
return None
def __getitem__(self, key):
return self.tags[key]
def __setitem__(self, key, value):
self.tags[key] = value
def __contains__(self, data):
return data in self.tags
def save(self):
if self.mutagen.tags is None:
self.mutagen.tags = self.mutagen.__class__._Tags()
# print(repr(self.mutagen.tags))
for tag_name in self.tags:
mutatag = self.detranslateKey(tag_name)
self.mutagen.tags[tag_name] = [self.tags[tag_name]]
# print(repr(self.mutagen.tags))
self.mutagen.save()
class RyeGeneric(RyeBase):
def __init__(self,filename):
RyeBase.__init__(self,filename,mutagen.File(filename, easy=True))
self.translation={
'artist': 'artist',
'album':'album',
'title':'title',
'albumartist':'albumartist'
}
self.load()
\ No newline at end of file
def __init__(self, filename):
RyeBase.__init__(self, filename, mutagen.File(filename, easy=True))
self.translation = {
'artist': 'artist',
'album': 'album',
'title': 'title',
'albumartist': 'albumartist'
}
self.load()
import mutagen
from .ryebase import RyeBase
class RyeVorbis(RyeBase):
def __init__(self,filename):
RyeBase.__init__(self,filename,mutagen.File(filename))
self.translation={
u'ALBUM' : 'album',
u'TITLE' : 'title',
u'ARTIST' : 'artist',
u'ALBUMARTIST' : 'albumartist'
}
self.load()
\ No newline at end of file
def __init__(self, filename):
RyeBase.__init__(self, filename, mutagen.File(filename))
self.translation = {
u'ALBUM': 'album',
u'TITLE': 'title',
u'ARTIST': 'artist',
u'ALBUMARTIST': 'albumartist'
}
self.load()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment