Skip to content
Snippets Groups Projects
Commit 1fe85e7e authored by ale's avatar ale
Browse files

store size in the mp3 table

parent 1d8b11d4
No related branches found
No related tags found
No related merge requests found
...@@ -83,9 +83,7 @@ def song_info_json(sha1): ...@@ -83,9 +83,7 @@ def song_info_json(sha1):
if not mp3: if not mp3:
abort(404) abort(404)
# Use the mp3.to_dict() data, but add some more things... # Use the mp3.to_dict() data, but add some more things...
data = mp3.to_dict() return jsonify(mp3.to_dict())
data['size'] = os.path.getsize(mp3.path)
return jsonify(data)
@app.route('/json/playing', methods=['POST']) @app.route('/json/playing', methods=['POST'])
......
...@@ -15,6 +15,7 @@ class MP3(Base): ...@@ -15,6 +15,7 @@ class MP3(Base):
ready = Column(Boolean, default=False, index=True) ready = Column(Boolean, default=False, index=True)
error = Column(Boolean, default=False, index=True) error = Column(Boolean, default=False, index=True)
path = Column(String(1024)) path = Column(String(1024))
size = Column(Integer())
artist = Column(Unicode(256)) artist = Column(Unicode(256))
title = Column(Unicode(256)) title = Column(Unicode(256))
album = Column(Unicode(256)) album = Column(Unicode(256))
...@@ -32,6 +33,7 @@ class MP3(Base): ...@@ -32,6 +33,7 @@ class MP3(Base):
'album': self.album, 'album': self.album,
'genre': self.genre, 'genre': self.genre,
'sha1': self.sha1, 'sha1': self.sha1,
'size': self.size,
'uploaded_at': self.uploaded_at} 'uploaded_at': self.uploaded_at}
......
...@@ -39,6 +39,7 @@ def _upload_mp3(incoming_fd, sha1): ...@@ -39,6 +39,7 @@ def _upload_mp3(incoming_fd, sha1):
if utils.sha1_of_file(mp3.path) != sha1: if utils.sha1_of_file(mp3.path) != sha1:
log.error('sha1 mismatch') log.error('sha1 mismatch')
raise Error('SHA1 mismatch') raise Error('SHA1 mismatch')
mp3.size = os.path.getsize(mp3.path)
Session.add(mp3) Session.add(mp3)
Session.commit() Session.commit()
log.info('successfully stored %s' % (sha1,)) log.info('successfully stored %s' % (sha1,))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment