Beispiel #1
0
def add_song_to_db(session, song_data):

    patterns = song_data["patterns"]
    patterns_json = json.dumps(patterns)

    sections = song_data["sections"]
    sections_json = json.dumps(sections)

    track = model.Track()

    track.song_id = song_data["song_id"]
    track.key = song_data["key"]
    track.title = song_data["title"]
    track.tempo = song_data["tempo"]
    track.energy = song_data["energy"]
    track.artist_name = song_data["artist_name"]
    track.mode = song_data["mode"]
    track.time_signature = song_data["time_signature"]
    track.duration = song_data["duration"]
    track.loudness = song_data["loudness"]
    track.artist_id = song_data["artist_id"]
    track.valence = song_data["valence"]    
    track.audio_md5 = song_data["audio_md5"]
    track.spotify_track_uri = song_data["spotify_track_uri"]
    track.patterns = patterns_json
    track.sections = sections_json
    track.rotation_duration = song_data["rotation_duration"]

    db_session.add(track)
    db_session.commit()
Beispiel #2
0
def track_create():
    form = TrackUpdateForm()
    if form.validate_on_submit():
        track_db = model.Track()

        form.populate_obj(track_db)
        track_db.put()
        return flask.redirect('/track/%i' % track_db.key.id())
    return flask.render_template(
        'track/track_update.html',
        html_class='track-create',
        title='Create Track',
        form=form,
    )
    def startElement(self, name, attrs):
        if name not in self.knownTags:
            if not self.ignore_missing_tags:
                print("Error: Unknown Release element '%s'." % name)
                sys.exit()
            elif name not in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'].replace(
                " ", ""))  # omit whitespaces in id to avoid conversion errors
            self.release.status = attrs['status']

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == "image":
            img = model.ImageInfo()
            img.height = attrs["height"]
            img.imageType = attrs["type"]
            img.uri = attrs["uri"]
            img.uri150 = attrs["uri150"]
            img.width = attrs["width"]
            self.release.images.append(img)
            if len(attrs) != 5:
                print("ATTR ERROR")
                print(attrs)
                sys.exit()

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            fmt.qty = attrs['qty']
            fmt.text = attrs['text']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        elif name == 'company' and 'companies' in self.stack:
            self.release.companies.append(model.Company())

        # Barcode
        elif name == 'identifier' and attrs['type'] == 'Barcode':
            self.release.barcode = attrs['value']
    def startElement(self, name, attrs):
        if not name in self.knownTags:
            if not self.ignore_missing_tags:
                print "Error: Unknown Release element '%s'." % name
                sys.exit()
            elif not name in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'])

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        elif name == 'company':
            cmp = model.ReleaseCompany()
            self.release.companies.append(cmp)

        elif name == 'artist' and 'track' not in self.stack and 'extraartists' not in self.stack:
            aj = model.ReleaseArtist()
            self.release.artists.append(aj)

        elif name == 'artist' and 'track' in self.stack and 'sub_track' not in self.stack and 'extraartists' not in self.stack:
            taj = model.ReleaseArtist()
            self.release.tracklist[-1].artists.append(taj)

        elif name == 'artist' and 'track' not in self.stack and 'extraartists' in self.stack:
            eaj = model.ExtraArtist()
            self.release.extraartists.append(eaj)

        elif name == 'artist' and 'track' in self.stack and 'sub_track' not in self.stack and 'extraartists' in self.stack:
            teaj = model.ExtraArtist()
            self.release.tracklist[-1].extraartists.append(teaj)
    def startElement(self, name, attrs):
        if not name in self.knownTags:
            if not self.ignore_missing_tags:
                print "Error: Unknown Release element '%s'." % name
                sys.exit()
            elif not name in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'])
            self.release.status = attrs['status']

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == "image":
            img = model.ImageInfo()
            img.height = attrs["height"]
            img.imageType = attrs["type"]
            img.uri = attrs["uri"]
            img.uri150 = attrs["uri150"]
            img.width = attrs["width"]
            self.release.images.append(img)
            if len(attrs) != 5:
                print "ATTR ERROR"
                print attrs
                sys.exit()

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            fmt.qty = attrs['qty']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        # Barcode
        elif name == 'identifier' and attrs['type'] == 'Barcode':
            self.release.barcode = attrs['value']
def izdaja_post(id):
    gumb = bottle.request.forms.getunicode("gumb")
    print("WE HERE")
    if gumb == 'Dodaj skladbo':
        naslov = bottle.request.forms.getunicode("naslov")
        dolzina = bottle.request.forms.getunicode("dolzina")
        model.Track(naslov, pf.pretvori_v_sekunde(dolzina), id).dodaj_v_bazo()
        model.Izdaja.nastavi_dolzino(id)
        podatki = model.Izdaja.poisciID(id)
        zalozba = model.Zalozba.dummy().vrni_zalozbo(podatki.idZalozbe)
        return bottle.template("izdaja.html",
                               iskaniID=id,
                               podatki=podatki,
                               artisti=model.Artist.dummy(),
                               zalozba=zalozba)
    elif gumb == 'Dodaj zvrst':
        izbraniZanr = bottle.request.forms.getunicode("izbraniZanr")
        model.Izdaja.poisciID(id).dodaj_zanr(int(izbraniZanr))
        podatki = model.Izdaja.poisciID(id)
        zalozba = model.Zalozba.dummy().vrni_zalozbo(podatki.idZalozbe)
        return bottle.template("izdaja.html",
                               iskaniID=id,
                               podatki=podatki,
                               artisti=model.Artist.dummy(),
                               zalozba=zalozba)
    elif gumb == "Dodaj avtorja":
        izbran = bottle.request.forms.getunicode("izbraniArtist")
        model.Izdaja.poisciID(id).dodaj_avtorje([izbran])
        bottle.redirect("/izdaja/" + str(id))
        #return bottle.template("izdaja.html", iskaniID=id , podatki=model.Izdaja.poisciID(id), artisti=model.Artist.dummy())
    elif gumb == 'briši':
        model.Izdaja.brisiID(id)
        bottle.redirect("/")
    else:
        brisanID = bottle.request.forms.getunicode("brisanID")
        model.Track.izbrisi_ID(int(brisanID))
        model.Izdaja.nastavi_dolzino(id)
        bottle.redirect("/izdaja/" + str(id))
Beispiel #7
0
 def post(self):
     """
 name = ndb.StringProperty(required=True)
 courses = ndb.TextProperty()
 topics = ndb.KeyProperty(kind='Topic', repeated=True)
 contributors = ndb.KeyProperty(kind='User', repeated=True)
 approved = ndb.BooleanProperty(default=False)
 color = ndb.StringProperty()
 vote = ndb.KeyProperty(kind='Vote')
 """
     if util.param('name') and util.param('courses'):
         b_name = util.param('name')
         b_description = util.param('description')
         b_topics = [
             ndb.Key(urlsafe=topic_key_url)
             for topic_key_url in util.param('topics', list)
         ]
         b_courses = helpers.connected_entities_constructor(
             util.param('courses', list))
         b_contributor = auth.current_user_key()
         b_track = model.Track(name=b_name,
                               description=b_description,
                               topics=b_topics,
                               contributors=[b_contributor],
                               courses=b_courses).put()
         response = {
             'status': 'success',
             'count': 1,
             'now': helpers.time_now(),
             'result': {
                 'message': 'track was successfuly created!!',
                 'view_url': flask.url_for('track',
                                           track_key=b_track.urlsafe())
             },
         }
         return response
     return helpers.make_bad_request_exception("Unsifificient parameters")
Beispiel #8
0
 def startElement(self, name, attrs):
     if not name in self.knownTags:
         if not self.ignore_missing_tags:
             print "Error: Unknown Release element '%s'." % name
             sys.exit()
         elif not name in self.unknown_tags:
             self.unknown_tags.append(name)
     self.stack.append(name)
     if name == 'release':
         self.release = model.Release()
         self.release.id = int(attrs['id'])
         self.release.status = attrs['status']
     elif name == 'track':
         self.release.tracklist.append(model.Track())
     elif name == "image":
         img = model.ImageInfo()
         img.height = attrs["height"]
         img.imageType = attrs["type"]
         img.uri = attrs["uri"]
         img.uri150 = attrs["uri150"]
         img.width = attrs["width"]
         self.release.images.append(img)
         if len(attrs) != 5:
             print "ATTR ERROR"
             print attrs
             sys.exit()
     elif name == 'format':
         fmt = model.Format()
         fmt.name = attrs['name']
         if attrs.has_key('text'):
             fmt.text = attrs['text']
         fmt.qty = attrs['qty']
         if not fmt.qty: fmt.qty = 0
         self.release.formats.append(fmt)
         #global formats
         #if not formats.has_key(attrs["name"]):
         #  formats[attrs["name"]] = True
     elif name == 'label':
         lbl = model.ReleaseLabel()
         lbl.name = attrs['name']
         lbl.catno = attrs['catno']
         self.release.labels.append(lbl)
     elif name == 'identifier':
         identifier = model.Identifier()
         identifier.type = attrs['type']
         identifier.value = attrs['value']
         if attrs.has_key('description'):
             identifier.description = attrs['description']
         self.release.identifiers.append(identifier)
     elif name == "video":
         vid = model.Video()
         vid.duration = attrs["duration"]
         vid.embed = attrs["embed"]
         vid.uri = attrs["src"]
         self.release.videos.append(vid)
     elif name == "artist":
         if 'track' in self.stack:
             if 'extraartists' in self.stack:
                 self.release.tracklist[-1].extraartists.append(
                     model.ArtistCredit())
             else:
                 self.release.tracklist[-1].artists.append(
                     model.ArtistCredit())
         else:
             if 'extraartists' in self.stack:
                 self.release.extraartists.append(model.ArtistCredit())
             else:
                 self.release.artists.append(model.ArtistCredit())
    def startElement(self, name, attrs):
        if not name in self.knownTags:
            if not self.ignore_missing_tags:
                print "Error: Unknown Release element '%s'." % name
                sys.exit()
            elif not name in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'])
            self.release.status = attrs['status']

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == "image":
            img = model.ImageInfo()
            img.height = attrs["height"]
            img.imageType = attrs["type"]
            img.uri = attrs["uri"]
            img.uri150 = attrs["uri150"]
            img.width = attrs["width"]
            self.release.images.append(img)
            if len(attrs) != 5:
                print "ATTR ERROR"
                print attrs
                sys.exit()

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            fmt.qty = attrs['qty']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        # Barcode
        elif name == 'identifier' and attrs['type'] == 'Barcode':
            self.release.barcode = attrs['value']

        elif name == 'company':
            comp = model.Company()
            self.release.companies.append(comp)

        elif name == 'video':
            vid = model.Video()
            vid.duration = attrs['duration']
            vid.embed = attrs['embed']
            vid.src = attrs['src']
            self.release.videos.append(vid)

        ## not in the elif, will lose the barcode
        if name == 'identifier':
            ident = model.Identifier()
            if 'description' in attrs:
                ident.description = attrs['description']
            ident.type = attrs['type']
            ident.value = attrs['value']
            self.release.identifiers.append(ident)
Beispiel #10
0
def index():
    # video1 = model.session.query(model.Track).get(55)
    # video2 = model.session.query(model.Track).get(56)
    video1 = model.session.query(model.Track).get(11)
    video2 = model.session.query(model.Track).get(12)
    groups = model.session.query(model.Group).all()

    if request.method == 'POST':

        # if (request.files['file1'] and request.files['file2']):
        #     print "in if statement"
        #     file1 = request.files['file1']
        #     file2 = request.files['file2']
        file1 = None
        file2 = None

        new_title = request.form.get("title")
        new_artist = request.form.get("artist")
        new_event = request.form.get("event")
        new_path = UPLOAD_FOLDER

        # file upload
        if (file1 and allowed_file(
                file1.filename)) and (file2 and allowed_file(file2.filename)):
            new_filename1 = secure_filename(file1.filename)
            new_filename2 = secure_filename(file2.filename)

            file1.save(os.path.join(app.config['UPLOAD_FOLDER'],
                                    new_filename1))
            file2.save(os.path.join(app.config['UPLOAD_FOLDER'],
                                    new_filename2))

        # youtube link upload
        elif (request.form.get("url1") and request.form.get("url2")):
            url1 = request.form.get("url1")
            url2 = request.form.get("url2")
            new_filename1 = convert.youtube_to_mp4(url1, new_title,
                                                   UPLOAD_FOLDER)
            new_filename2 = convert.youtube_to_mp4(url2, new_title,
                                                   UPLOAD_FOLDER)
            new_youtube_url1 = "http://www.youtube.com/embed/" + url1[-11:]
            new_youtube_url2 = "http://www.youtube.com/embed/" + url2[-11:]
            new_thumbnail1 = convert.youtube_thumbnail(url1)
            new_thumbnail2 = convert.youtube_thumbnail(url2)

        # save file 1
        # new_filename_webm1 = convert.convert_video(filename1, UPLOAD_FOLDER)  # convert file to webm
        new_filename_webm1 = "webmfilename"
        new_file1 = model.Track(title=new_title,
                                filename=new_filename1,
                                artist=new_artist,
                                event=new_event,
                                path=new_path,
                                filename_webm=new_filename_webm1,
                                youtube_url=new_youtube_url1,
                                thumbnail_url=new_thumbnail1)
        model.session.add(new_file1)

        # save file 2
        # new_filename_webm2 = convert.convert_video(filename2, UPLOAD_FOLDER)  # convert file to webm
        new_filename_webm2 = "webmfilename"
        new_file2 = model.Track(title=new_title,
                                filename=new_filename2,
                                artist=new_artist,
                                event=new_event,
                                path=new_path,
                                filename_webm=new_filename_webm2,
                                youtube_url=new_youtube_url2,
                                thumbnail_url=new_thumbnail2)
        model.session.add(new_file2)

        # save group info into db
        new_timestamp = datetime.datetime.now()
        new_group = model.Group(timestamp=new_timestamp)
        model.session.add(new_group)

        model.session.flush()

        # analyze delay
        delay = alignment_by_row_channels.align(new_filename1, new_filename2,
                                                UPLOAD_FOLDER)
        # delay = (0, 5)

        # save analysis into db
        new_group_id = new_group.id
        new_track_id1 = new_file1.id
        new_sync_point1 = delay[0]
        new_analysis1 = model.Analysis(group_id=new_group_id,
                                       track_id=new_track_id1,
                                       sync_point=new_sync_point1)
        model.session.add(new_analysis1)

        new_track_id2 = new_file2.id
        new_sync_point2 = delay[1]
        new_analysis2 = model.Analysis(group_id=new_group_id,
                                       track_id=new_track_id2,
                                       sync_point=new_sync_point2)
        model.session.add(new_analysis2)

        model.session.commit()

        return redirect('/watch?group_id=' + str(new_group.id))

    return render_template("index.html",
                           video1=video1,
                           video2=video2,
                           groups=groups)