/usr/bin/mbfind is in ears 1.0.1-2.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #!/usr/bin/python
import sys
import getopt
try:
import musicbrainz
except ImportError, e:
print >>sys.stderr, 'import: %s' % e
sys.exit(1)
def print_selected_album(mb):
id = mb.GetIDFromURL(mb.GetResultData(musicbrainz.MBE_AlbumGetAlbumId))
album = mb.GetResultData(musicbrainz.MBE_AlbumGetAlbumName)
n = mb.GetResultInt(musicbrainz.MBE_AlbumGetNumTracks)
artistid = mb.GetIDFromURL(
mb.GetResultData(musicbrainz.MBE_AlbumGetAlbumArtistId))
if artistid == musicbrainz.MBI_VARIOUS_ARTIST_ID:
artist = '[Various Artists]'
else:
try:
artist = mb.GetResultData1(musicbrainz.MBE_AlbumGetArtistName, 1)
except musicbrainz.MusicBrainzError:
artist = '[Unknown]'
dur = 0
for i in range(1, n+1):
dur += mb.GetResultInt1(musicbrainz.MBE_AlbumGetTrackDuration, i)
m, s = divmod(dur/1000, 60)
print '%s %s - %s [%d:%02d, %d tracks]' % (id, artist, album, m, s, n)
if __name__ == '__main__':
shortopts = 'a:b:v'
longopts = ['artist=', 'album=', 'verbose']
mb = musicbrainz.mb()
mb.SetDepth(4)
try:
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
except getopt.GetoptError, e:
print >>sys.stderr, 'getopt: %s' % e
sys.exit(1)
artistspec = None
albumspec = None
verbose = False
for opt, arg in opts:
if opt in ('--artist', '-a'):
artistspec = arg
if opt in ('--album', '-b'):
albumspec = arg
if opt in ('--verbose', '-v'):
verbose = True
if albumspec:
try:
mb.QueryWithArgs(musicbrainz.MBQ_FindAlbumByName, [albumspec])
except musicbrainz.MusicBrainzError, e:
print >>sys.stderr, 'musicbrainz: %s' % e
sys.exit(1)
if verbose:
print mb.GetResultRDF()
n = mb.GetResultInt(musicbrainz.MBE_GetNumAlbums)
for i in range(1, n+1):
mb.Select1(musicbrainz.MBS_SelectAlbum, i)
print_selected_album(mb)
mb.Select(musicbrainz.MBS_Rewind)
elif artistspec:
try:
mb.QueryWithArgs(musicbrainz.MBQ_FindArtistByName, [artistspec])
except musicbrainz.MusicBrainzError, e:
print >>sys.stderr, 'musicbrainz: %s' % e
sys.exit(1)
if verbose:
print mb.GetResultRDF()
n = mb.GetResultInt(musicbrainz.MBE_GetNumArtists)
for i in range(1, n+1):
mb.Select1(musicbrainz.MBS_SelectArtist, i)
m = mb.GetResultInt(musicbrainz.MBE_GetNumAlbums)
for j in range(1, m+1):
mb.Select1(musicbrainz.MBS_SelectAlbum, j)
print_selected_album(mb)
mb.Select(musicbrainz.MBS_Back)
mb.Select(musicbrainz.MBS_Rewind)
else:
print >>sys.stderr, 'args: must specify an album or artist name'
sys.exit(1)
|