def add_links_to_playlist(playlist_id, link, site): dao = MusicDao() if site == 'youtube': videos = youtube_service.get_videos(link) else: raise Exception('Invalid site id %s' % site) error, existing_video_links = get_links_in_playlist(playlist_id) existing_video_urls = [link.get('url') for link in existing_video_links] links = [] for video in videos: if not video.get('url') in existing_video_urls: links.append(video) last_sync = time.time() links_count = len(existing_video_urls) + len(links) dao.add_links_to_playlist(playlist_id, links) dao.update_playlist(playlist_id, links_count=links_count, updated_at=last_sync) return None, { 'id': playlist_id, 'links_count': links_count, 'updated_at': readable.from_ts(last_sync) }
def delete_playlist(playlist_id): """ Deletes a Todo with id = id """ dao = MusicDao() error, is_deleted = dao.delete_playlist(playlist_id) return error, is_deleted
def create_playlist(name): name = name.strip() playlist_id = name.lower().replace(' ', '-') initial_data = { 'name': name, 'updated_at': time.time(), 'links': [], 'links_count': 0, 'is_active': True } dao = MusicDao() error, playlist_obj = dao.create_playlist(playlist_id, initial_data) return error, playlist_obj
def get_playlists_meta_info(): dao = MusicDao() playlists_meta = dao.get_all_playlists_meta_info() return playlists_meta
def get_links_in_playlist(playlist_id): dao = MusicDao() links = dao.get_link_in_playlist(playlist_id) return None, links