Skip to content

Commit

Permalink
Update hdf5_getters.py to use new 'tables' api.
Browse files Browse the repository at this point in the history
Add descriptive error when failing to download song.
  • Loading branch information
Matan Lachmish committed Dec 19, 2016
1 parent b89e3b2 commit 437a039
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
14 changes: 3 additions & 11 deletions mel-spec/code/lib/hdf5_getters.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
"""
Thierry Bertin-Mahieux (2010) Columbia University
tb2332@columbia.edu
This code contains a set of getters functions to access the fields
from an HDF5 song file (regular file with one song or
aggregate / summary file with many songs)
This is part of the Million Song Dataset project from
LabROSA (Columbia University) and The Echo Nest.
Copyright 2010, Thierry Bertin-Mahieux
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Expand All @@ -36,7 +28,7 @@ def open_h5_file_read(h5filename):
Open an existing H5 in read mode.
Same function as in hdf5_utils, here so we avoid one import
"""
return tables.openFile(h5filename, mode='r')
return tables.open_file(h5filename, mode='r')


def get_num_songs(h5):
Expand Down Expand Up @@ -292,7 +284,7 @@ def get_segments_start(h5,songidx=0):
return h5.root.analysis.segments_start[h5.root.analysis.songs.cols.idx_segments_start[songidx]:]
return h5.root.analysis.segments_start[h5.root.analysis.songs.cols.idx_segments_start[songidx]:
h5.root.analysis.songs.cols.idx_segments_start[songidx+1]]

def get_segments_confidence(h5,songidx=0):
"""
Get segments confidence array. Takes care of the proper indexing if we are in aggregate
Expand Down Expand Up @@ -473,4 +465,4 @@ def get_year(h5,songidx=0):
"""
Get release year from a HDF5 song file, by default the first song in it
"""
return h5.root.musicbrainz.songs.cols.year[songidx]
return h5.root.musicbrainz.songs.cols.year[songidx]
4 changes: 2 additions & 2 deletions mel-spec/code/lib/previewDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def update_progress(progress):

url = py7D.preview_url(id7Digital)
urlretrieve = urllib.urlretrieve(url, previewFilePath)
except Exception:
print "Error accured"
except Exception as e:
print "Error accured: " + str(e)

if file.endswith('h5'):
# update_progress(int(i/7620 * 100))
Expand Down

0 comments on commit 437a039

Please sign in to comment.