Merge branch 'cc-5709-airtime-analyzer-store-file-size-and-hash-in-db' into saas-store-file-size-and-hash-in-db

Conflicts:
	airtime_mvc/application/Bootstrap.php

airtime_mvc/application/modules/rest/controllers/MediaController.php
This commit is contained in:
drigato 2015-02-17 16:19:58 -05:00
commit c1086842d3
6 changed files with 54 additions and 4 deletions

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 = {