SAAS-596: Store file size and hash in database

Added file size and hash to the metadata dict in the analyzer
This commit is contained in:
drigato 2015-02-17 16:02:49 -05:00
parent a07a1edcc0
commit 66a6a8f985

View file

@ -4,6 +4,8 @@ import mutagen
import magic
import wave
import logging
import os
import hashlib
from analyzer import Analyzer
class MetadataAnalyzer(Analyzer):
@ -96,6 +98,23 @@ class MetadataAnalyzer(Analyzer):
#If we couldn't figure out the track_number or track_total, just ignore it...
pass
# Get file size and md5 hash of the file
try:
metadata["filesize"] = os.path.getsize(filename)
with open(filename, 'rb') as fh:
m = hashlib.md5()
while True:
data = fh.read(8192)
if not data:
break
m.update(data)
metadata["md5_hash"] = m.hexdigest()
except (OSError, IOError) as e:
raise e
#We normalize the mutagen tags slightly here, so in case mutagen changes,
#we find the
mutagen_to_airtime_mapping = {