def directory(request, dirid): """ A directory that wasn't matched to a release in the collection. This could be because it has no release tags, or the release isn't in the collection. We want to group together as much common information as possible, and link to musicbrainz if we can. """ directory = get_object_or_404(models.CollectionDirectory, pk=dirid) rematch = request.GET.get("rematch") if rematch is not None: # TODO: Change to celery jobs.rematch_unknown_directory(dirid) get_object_or_404(models.CollectionDirectory, pk=dirid) return redirect('dashboard-directory', dirid) full_path = directory.full_path files = os.listdir(full_path) releaseids = set() releasename = set() artistids = set() artistname = set() for f in files: fname = os.path.join(full_path, f) if compmusic.is_mp3_file(fname): data = compmusic.file_metadata(fname) relid = data["meta"]["releaseid"] relname = data["meta"]["release"] aname = data["meta"]["artist"] aid = data["meta"]["artistid"] if relid and relname: releaseids.add(relid) releasename.add(relname) if aname and aid: artistids.add(aid) artistname.add(aname) got_release_id = len(releaseids) == 1 # TODO: This won't work if there are more than 1 lead artist? got_artist = len(artistids) == 1 if directory.musicbrainzrelease: matched_release = directory.musicbrainzrelease else: matched_release = None ret = { "files": sorted(files), "directory": directory, "got_release_id": got_release_id, "got_artist": got_artist, "matched_release": matched_release } if got_release_id: ret["releasename"] = list(releasename)[0] ret["releaseid"] = list(releaseids)[0] if got_artist: ret["artistname"] = list(artistname)[0] ret["artistid"] = list(artistids)[0] return render(request, 'dashboard/directory.html', ret)
def directory(request, dirid): """ A directory that wasn't matched to a release in the collection. This could be because it has no release tags, or the release isn't in the collection. We want to group together as much common information as possible, and link to musicbrainz if we can. """ directory = get_object_or_404(models.CollectionDirectory, pk=dirid) rematch = request.GET.get("rematch") if rematch is not None: # TODO: Change to celery jobs.rematch_unknown_directory(dirid) directory = get_object_or_404(models.CollectionDirectory, pk=dirid) return HttpResponseRedirect(reverse('dashboard.views.directory', args=[dirid])) collection = directory.collection full_path = os.path.join(collection.root_directory, directory.path) files = os.listdir(full_path) meta = {} releaseids = set() releasename = set() artistids = set() artistname = set() for f in files: fname = os.path.join(full_path, f) if compmusic.is_mp3_file(fname): data = compmusic.file_metadata(fname) relid = data["meta"]["releaseid"] relname = data["meta"]["release"] aname = data["meta"]["artist"] aid = data["meta"]["artistid"] if relid and relname: releaseids.add(relid) releasename.add(relname) if aname and aid: artistids.add(aid) artistname.add(aname) got_release_id = len(releaseids) == 1 # TODO: This won't work if there are more than 1 lead artist? got_artist = len(artistids) == 1 print "releaseids", releaseids print "artistids", artistids if directory.musicbrainzrelease: matched_release = directory.musicbrainzrelease else: matched_release = None ret = {"files": sorted(files), "directory": directory, "got_release_id": got_release_id, "got_artist": got_artist, "matched_release": matched_release} if got_release_id: ret["releasename"] = list(releasename)[0] ret["releaseid"] = list(releaseids)[0] if got_artist: ret["artistname"] = list(artistname)[0] ret["artistid"] = list(artistids)[0] return render(request, 'dashboard/directory.html', ret)
def get_coverart_from_directories(directories=[]): """Find some coverart in the files that are part of a directory""" for d in directories: files = [os.path.join(d, f) for f in os.listdir(d)] files = [f for f in files if compmusic.is_mp3_file(f)] for f in files: coverart = compmusic.get_coverart(f) if coverart: return coverart return None