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:
parent
a07a1edcc0
commit
66a6a8f985
1 changed files with 19 additions and 0 deletions
|
@ -4,6 +4,8 @@ import mutagen
|
||||||
import magic
|
import magic
|
||||||
import wave
|
import wave
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import hashlib
|
||||||
from analyzer import Analyzer
|
from analyzer import Analyzer
|
||||||
|
|
||||||
class MetadataAnalyzer(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...
|
#If we couldn't figure out the track_number or track_total, just ignore it...
|
||||||
pass
|
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 normalize the mutagen tags slightly here, so in case mutagen changes,
|
||||||
#we find the
|
#we find the
|
||||||
mutagen_to_airtime_mapping = {
|
mutagen_to_airtime_mapping = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue