try: dj.skipToNextSegment() except Exception as e: logger.error(e) elif cmd == 'stop': logger.info('Stopping playback!') dj.stop() elif cmd == 'save': logger.info('Saving the next new mix!') elif cmd == 'showannotated': logger.info('Number of annotated songs ' + str(len(sc.get_annotated()))) logger.info('Number of unannotated songs ' + str(len(sc.get_unannotated()))) elif cmd == 'annotate': logger.info('Started annotating!') sc.annotate() logger.info('Done annotating!') elif cmd == 'debug': LOG_LEVEL = logging.DEBUG logging.root.setLevel(LOG_LEVEL) stream.setLevel(LOG_LEVEL) logger.setLevel(LOG_LEVEL) logger.debug( 'Enabled debug info. Use this command before playing, or it will have no effect.' ) elif cmd == 'mark': dj.markCurrentMaster() else: logger.info('The command ' + cmd + ' does not exist!')
def index_dj(request): template = get_template("Index.html") LOG_LEVEL = logging.DEBUG LOGFORMAT = "%(log_color)s%(message)s%(reset)s" logging.root.setLevel(LOG_LEVEL) formatter = ColoredFormatter(LOGFORMAT) stream = logging.StreamHandler() stream.setLevel(LOG_LEVEL) stream.setFormatter(formatter) logger = logging.getLogger('colorlogger') logger.setLevel(LOG_LEVEL) logger.addHandler(stream) sc = SongCollection() tl = TrackLister(sc) dj = DjController(tl) essentia.log.infoActive = False essentia.log.warningActive = False if request.method == "POST": cmd = request.POST.get("cmd", None) cmd = str(cmd) # cmd_split = str(cmd).split # cmd = cmd_split[0] while (True): # try: # cmd_split = str.split(input('> : '), ' ') # except KeyboardInterrupt: # logger.info('Goodbye!') # break # cmd = cmd_split[0] # if cmd == 'loaddir': # if len(cmd_split) == 1: # return HttpResponse('Please provide a directory name to load!') # continue # elif not os.path.isdir(cmd_split[1]): # return HttpResponse(cmd_split[1] + ' is not a valid directory!') # continue message = "abc" sc.load_directory("/home/ddman/音樂/upload") message = str(len(sc.songs)) + ' songs loaded [annotated: ' + str( len(sc.get_annotated())) + ']' if cmd == 'play': if len(sc.get_annotated()) == 0: message = 'Use the loaddir command to load some songs before playing!' continue # if len(cmd_split) > 1 and cmd_split[1] == 'save': # message = 'Saving this new mix to disk!' # save_mix = True # else: # save_mix = False message = 'Starting playback!' try: dj.play(save_mix=False) except Exception as e: logger.error(e) return render(request, "Index.html", locals()) elif cmd == 'pause': message = 'Pausing playback!' try: dj.pause() except Exception as e: logger.error(e) return render(request, "Index.html", locals()) elif cmd == 'skip' or cmd == 's': message = 'Skipping to next segment...' try: dj.skipToNextSegment() except Exception as e: logger.error(e) return render(request, "Index.html", locals()) elif cmd == 'stop': message = 'Stopping playback!' dj.stop() return render(request, "Index.html", locals()) elif cmd == 'save': message = 'Saving the next new mix!' return render(request, "Index.html", locals()) elif cmd == 'showannotated': message = 'Number of annotated songs ' + str( len(sc.get_annotated())) message = 'Number of unannotated songs ' + str( len(sc.get_unannotated())) return render(request, "Index.html", locals()) elif cmd == 'annotate': message = 'Started annotating!' sc.annotate() message = 'Done annotating!' return render(request, "Index.html", locals()) elif cmd == 'debug': LOG_LEVEL = logging.DEBUG logging.root.setLevel(LOG_LEVEL) stream.setLevel(LOG_LEVEL) logger.setLevel(LOG_LEVEL) message = 'Enabled debug info. Use this command before playing, or it will have no effect.' return render(request, "Index.html", locals()) elif cmd == 'mark': dj.markCurrentMaster() return render(request, "Index.html", locals()) elif cmd == "quit": break return render(request, "Index.html", locals()) else: message = 'The command ' + str(cmd) + ' does not exist!' return render(request, "Index.html", locals()) return render(request, "Index.html", locals())