def info(request): CANNEN_BACKEND = backend.get() enable_library = getattr(settings, 'CANNEN_ENABLE_LIBRARY', False) try: now_playing = GlobalSong.objects.filter(is_playing=True)[0] now_playing = CANNEN_BACKEND.get_info(now_playing) except IndexError: now_playing = None playlist = GlobalSong.objects.filter(is_playing=False) playlist = [CANNEN_BACKEND.get_info(m) for m in playlist] userqueue = UserSong.objects.filter(owner=request.user) userqueue = [CANNEN_BACKEND.get_info(m) for m in userqueue] #return the default values without library data = dict(current=now_playing, playlist=playlist, queue=userqueue, enable_library=enable_library) #if the library is enabled, then prepare the data and pass it to the template if enable_library: songfiles = SongFile.objects.filter(owner=request.user) userlibrary = [CANNEN_BACKEND.get_info(Song) for Song in songfiles] userlibrary.sort(key=lambda x: (x.artist.lower().lstrip('the ') if x.artist else x.artist, x.title)) data = dict(current=now_playing, playlist=playlist, queue=userqueue, library=userlibrary, enable_library=enable_library) return render_to_response('cannen/info.html', data, context_instance=RequestContext(request))
def info(request): CANNEN_BACKEND = backend.get() try: now_playing = GlobalSong.objects.filter(is_playing=True)[0] now_playing = CANNEN_BACKEND.get_info(now_playing) except IndexError: now_playing = None playlist = GlobalSong.objects.filter(is_playing=False) userqueue = UserSong.objects.filter(owner=request.user) playlist = [CANNEN_BACKEND.get_info(m) for m in playlist] userqueue = [CANNEN_BACKEND.get_info(m) for m in userqueue] data = dict(current=now_playing, playlist=playlist, queue=userqueue) return render_to_response('cannen/info.html', data, context_instance=RequestContext(request))
def library(request): title = getattr(settings, "CANNEN_TITLE", None) listen_urls = getattr(settings, "CANNEN_LISTEN_URLS", []) enable_library = getattr(settings, 'CANNEN_ENABLE_LIBRARY', False) CANNEN_BACKEND = backend.get() Songs = SongFile.objects.all() userqueue = UserSong.objects.filter(owner=request.user) userqueue = [CANNEN_BACKEND.get_info(m) for m in userqueue] #return data without library info in it... as default data = dict(title=title, listen_urls=listen_urls, queue=userqueue, enable_library=enable_library) #if the library is enabled, prepare and pass the data if enable_library: library = [CANNEN_BACKEND.get_info(Song) for Song in Songs] library.sort(key=lambda x: (x.artist.lower().lstrip('the ') if x.artist else x.artist, x.title)) data = dict(title=title, listen_urls=listen_urls, queue=userqueue, library=library, enable_library=enable_library) return render_to_response('cannen/library.html', data, context_instance=RequestContext(request))
def unregister_uploaded(sender, **kwargs): instance = kwargs['instance'] url = instance.file.url instance.file.delete(save=False) backend.get().unregister_uploaded(unquote(url))
def register_uploaded(sender, **kwargs): if kwargs['created']: instance = kwargs['instance'] backend.get().register_uploaded(unquote(instance.file.url))
#-!- coding=utf-8 -!- import backend import sys backend.load( "../data/formated" ) print "done" while True : code = sys.stdin.readline()[:-1] for c in code : backend.append( c ) i = 0 r = backend.getPinyin( i ) while r : print r i = i + 1 r = backend.getPinyin( i ) i = 0 r = backend.get( i ) while r and i < 3 : #while r : print r[0], r[1] print type(r[0]), type(r[1]) i = i + 1 r = backend.get( i ) backend.clear()