Beispiel #1
0
    def _apply_tags(self, recording, works, tags):
        if len(works):
            w = works[0]
            if self.overwrite:
                w.raaga.clear()
                w.taala.clear()

            raagas = self._get_raaga_tags(tags)
            taalas = self._get_taala_tags(tags)

            for seq, rname in raagas:
                r = self._get_raaga(rname)
                if r:
                    carnatic.models.WorkRaaga.objects.create(work=w, raaga=r, sequence=seq)
                else:
                    logger.warn("Cannot find raaga: %s" % rname)

            for seq, tname in taalas:
                t = self._get_taala(tname)
                if t:
                    carnatic.models.WorkTaala.objects.create(work=w, taala=t, sequence=seq)
                else:
                    logger.warn("Cannot find taala: %s" % tname)
        else:
            # If we have no works, we don't need to do this
            return
Beispiel #2
0
def _save_file(root_directory, recordingid, version, slug, partslug, partnumber, extension, data):
    recordingstub = recordingid[:2]
    reldir = os.path.join(recordingstub, recordingid, slug, version)
    fdir = os.path.join(root_directory, settings.DERIVED_FOLDER, reldir)
    try:
        os.makedirs(fdir)
    except OSError:
        logger.warn("Error making directory %s" % fdir)
        pass
    fname = "%s-%s-%s-%s-%s.%s" % (recordingid, slug, version, partslug, partnumber, extension)

    fullname = os.path.join(fdir, fname)
    fullrelname = os.path.join(reldir, fname)
    try:
        fp = open(fullname, "wb")
        if extension == "json":
            json.dump(data, fp, cls=NumPyArangeEncoder)
        else:
            if not isinstance(data, basestring):
                logger.warn("Data is not a string-ish thing. instead it's %s" % type(data))
            fp.write(data)
        fp.close()
    except OSError:
        logger.warn("Error writing to file %s" % fullname)
        logger.warn("Probably a permissions error")
        return None, None, None
    if not isinstance(data, basestring):
        data = str(data)
    return fullname, fullrelname, len(data)
Beispiel #3
0
    def add_and_get_work(self, workid, raagas, taalas):
        mbwork = compmusic.mb.get_work_by_id(workid, includes=["artist-rels"])["work"]
        work, created = carnatic.models.Work.objects.get_or_create(mbid=workid,
                defaults={"title": mbwork["title"]})

        if created or self.overwrite:
            source = self.make_mb_source("http://musicbrainz.org/work/%s" % workid)
            work.source = source
            work.title = mbwork["title"]
            work.save()

            if self.overwrite:
                work.raaga.clear()
                work.taala.clear()
                work.composer = None

            for seq, rname in raagas:
                r = self.get_raaga(rname)
                if r:
                    carnatic.models.WorkRaaga.objects.create(work=work, raaga=r, sequence=seq)
                else:
                    logger.warn("Cannot find raaga: %s" % rname)

            for seq, tname in taalas:
                t = self.get_taala(tname)
                if t:
                    carnatic.models.WorkTaala.objects.create(work=work, taala=t, sequence=seq)
                else:
                    logger.warn("Cannot find taala: %s" % tname)

            for artist in mbwork.get("artist-relation-list", []):
                if artist["type"] == "composer":
                    composer = self.add_and_get_composer(artist["target"])
                    work.composer = composer
                    work.save()
                elif artist["type"] == "lyricist":
                    # TODO: Lyricist
                    pass

        return work
Beispiel #4
0
def _save_file(derivedfile, partnumber, extension, data):
    fdir = derivedfile.directory()
    try:
        os.makedirs(fdir)
    except OSError:
        logger.warn("Error making directory %s" % fdir)
        pass

    fname = derivedfile.filename_for_part(partnumber)

    fullname = os.path.join(fdir, fname)
    try:
        fp = open(fullname, "wb")
        if extension == "json":
            json.dump(data, fp, cls=NumPyArangeEncoder)
        else:
            if not isinstance(data, six.string_types):
                logger.warn("Data is not a string-ish thing. instead it's %s" % type(data))
            fp.write(data)
        fp.close()
    except OSError:
        logger.warn("Error writing to file %s" % fullname)
        logger.warn("Probably a permissions error")
Beispiel #5
0
 def _get_taala(self, taalaname):
     try:
         return carnatic.models.Taala.objects.fuzzy(taalaname)
     except carnatic.models.Taala.DoesNotExist:
         logger.warn("Cannot find taala: %s" % taalaname)
         return None
Beispiel #6
0
 def _get_raaga(self, raaganame):
     try:
         return carnatic.models.Raaga.objects.fuzzy(raaganame)
     except carnatic.models.Raaga.DoesNotExist:
         logger.warn("Cannot find raaga: %s" % raaganame)
         return None
Beispiel #7
0
 def _get_form(self, form):
     try:
         return carnatic.models.Form.objects.fuzzy(form)
     except carnatic.models.Form.DoesNotExist:
         logger.warn("Cannot find form: %s" % form)
         return None
Beispiel #8
0
 def _get_taala(self, taalaname):
     try:
         return carnatic.models.Taala.objects.fuzzy(taalaname)
     except carnatic.models.Taala.DoesNotExist:
         logger.warn("Cannot find taala: %s" % taalaname)
         return None
Beispiel #9
0
 def _get_raaga(self, raaganame):
     try:
         return carnatic.models.Raaga.objects.fuzzy(raaganame)
     except carnatic.models.Raaga.DoesNotExist:
         logger.warn("Cannot find raaga: %s" % raaganame)
         return None
Beispiel #10
0
 def _get_form(self, form):
     try:
         return carnatic.models.Form.objects.fuzzy(form)
     except carnatic.models.Form.DoesNotExist:
         logger.warn("Cannot find form: %s" % form)
         return None