def playlist_rename(request,playlist_id): try: playlist = db.playlist.find_one(ObjectId(playlist_id)) name = request.POST['name'] playlist.name = name playlist.save() return JsonResponse({'success': True, 'playlist': playlist}) except Exception as e: return JsonResponse({'success': False, 'error': str(e)})
def playlist_delete_song(request,playlist_id): try: playlist = db.playlist.find_one(ObjectId(playlist_id)) song_id = request.POST['song_id'] song = get_song(song_id) playlist.songs.remove(song) playlist.save() return JsonResponse({'success': True, 'playlist': playlist}) except Exception as e: return JsonResponse({'success': False, 'error': str(e)})
def playlist_enqueue(request,playlist_id): playlist = db.playlist.find_one(ObjectId(playlist_id)) if playlist != None: player = get_player(player_name) songs = playlist.songs for song in songs: player.enqueue(ObjectId(song.id)) save_player(player) return JsonResponse({'success': True, 'playlist': playlist}) else: return JsonResponse({'success': False})
def playlist_to_player(request, playlist_name, player_name): playlist = get_playlist(playlist_name) player = get_player(player_name) for song in playlist.songs: player.enqueue(song) save_player(player) return JsonResponse({'success': True})
def summary(request, playlist_name): playlist = get_playlist(playlist_name) return JsonResponse({ 'length': len(playlist.songs), 'names': [db.songs.Song.find_one(song).title for song in playlist.songs], })
def list_playlists(request): return JsonResponse({ 'playlists': [pl.name for pl in db.playlists.Playlist.find()], })
def playlist_from_player(request, playlist_name, player_name): playlist = get_or_create_playlist(playlist_name) player = get_player(player_name) playlist.songs = player.queue playlist.save() return JsonResponse({'success': True})
def view_all(request): # user = User(request).user # playlists = db.playlists.find({'$or' : [{'creator': user}, {'public': True}]}) playlists = db.playlists.find({'public': True}) return JsonResponse({'success': True, 'playlists': list(playlists)})
def playlist_reorder(request,playlist_id): return JsonResponse({"success": True})