def submit_automation_track(): if 'password' not in request.form or \ request.form['password'] != app.config['AUTOMATION_PASSWORD']: abort(403) automation = redis_conn.get('automation_enabled') == "true" if not automation: return Response("Automation is off\n", mimetype="text/plain") if 'title' in request.form and len(request.form['title']) > 0: title = request.form['title'].strip() else: title = "Not Available" if 'artist' in request.form and len(request.form['artist']) > 0: artist = request.form['artist'].strip() else: artist = "Not Available" if 'album' in request.form and len(request.form['album']) > 0: album = request.form['album'].strip() else: album = "Not Available" if artist.lower() in ("wuvt", "pro", "soo", "psa", "lnr", "ua"): # ignore PSAs and other traffic return Response("Will not log traffic\n", mimetype="text/plain") if 'label' in request.form and len(request.form['label']) > 0: label = request.form['label'].strip() tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album).filter(Track.label == label) if len(tracks.all()) == 0: track = Track(title, artist, album, label) db.session.add(track) db.session.commit() else: track = tracks.one() else: # Handle automation not providing a label label = "Not Available" tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album) if len(tracks.all()) == 0: track = Track(title, artist, album, label) db.session.add(track) db.session.commit() else: notauto = tracks.filter(Track.label != "Not Available") if len(notauto.all()) == 0: # The only option is "not available label" track = tracks.one() else: track = notauto.one() log_track(track.id, None) return Response("Logged\n", mimetype="text/plain")
def play_tracklog(): track_id = int(request.form['track_id']) djset_id = int(request.form['djset_id']) is_request = request.form.get('request', 'false') != 'false' vinyl = request.form.get('vinyl', 'false') != 'false' new = request.form.get('new', 'false') != 'false' rotation = request.form.get('rotation', None) if rotation is not None: rotation = Rotation.query.get(int(rotation)) # check to be sure the track and DJSet exist track = Track.query.get(track_id) djset = DJSet.query.get(djset_id) if not track or not djset: return jsonify(success=False, error="Track or DJSet do not exist") if djset.dtend is not None: return jsonify(success=False, error="Session expired, please login again") tracklog = log_track(track_id, djset_id, request=is_request, vinyl=vinyl, new=new, rotation=rotation) return jsonify(success=True, tracklog_id=tracklog.id)
def automation_log(): if 'password' not in request.form or \ request.form['password'] != app.config['AUTOMATION_PASSWORD']: return jsonify(success=False, error="Invalid password") automation = redis_conn.get('automation_enabled') == "true" if not automation: return jsonify(success=False, error="Automation not enabled") if 'title' in request.form and len(request.form['title']) > 0: title = request.form['title'].strip() else: title = "Not Available" if 'artist' in request.form and len(request.form['artist']) > 0: artist = request.form['artist'].strip() else: artist = "Not Available" if 'album' in request.form and len(request.form['album']) > 0: album = request.form['album'].strip() else: album = "Not Available" if artist.lower() in ("wuvt", "pro", "soo", "psa", "lnr", "ua"): # TODO: implement airlog logging return jsonify(success=False, error='AirLog logging not yet implemented') if 'label' in request.form and len(request.form['label']) > 0: label = request.form['label'].strip() tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album).filter(Track.label == label) if len(tracks.all()) == 0: track = Track(title, artist, album, label) db.session.add(track) db.session.commit() else: track = tracks.first() else: # Handle automation not providing a label label = "Not Available" tracks = Track.query.filter(Track.title == title).filter(Track.artist == artist).filter(Track.album == album) if len(tracks.all()) == 0: track = Track(title, artist, album, label) db.session.add(track) db.session.commit() else: notauto = tracks.filter(Track.label != "Not Available") if len(notauto.all()) == 0: # The only option is "not available label" track = tracks.first() else: track = notauto.first() djset_id = redis_conn.get('automation_set') if djset_id != None: djset_id = int(djset_id) log_track(track.id, djset_id) return jsonify(success=True)