From d170a75a93e7d722345e328235d62e41cbcd6ae0 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Fri, 20 Jul 2018 01:41:12 -0700 Subject: ability to remove videos from playlist --- youtube/common.py | 9 ++++----- youtube/local_playlist.py | 34 +++++++++++----------------------- youtube/shared.css | 2 +- youtube/youtube.py | 16 ++++++++++++++-- 4 files changed, 30 insertions(+), 31 deletions(-) (limited to 'youtube') diff --git a/youtube/common.py b/youtube/common.py index e4ab39a..46dfc8d 100644 --- a/youtube/common.py +++ b/youtube/common.py @@ -82,7 +82,7 @@ medium_video_item_template = Template(''' $description $badges - + ''') @@ -99,7 +99,7 @@ small_video_item_template = Template(''' $views - + ''') @@ -298,13 +298,12 @@ header_template = Template('''
-
- + $playlists - +
Local playlists diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py index 926c93f..5da3b4d 100644 --- a/youtube/local_playlist.py +++ b/youtube/local_playlist.py @@ -40,30 +40,18 @@ def get_playlist_names(): if ext == '.txt': yield name -''' - main{ - display:grid; - grid-template-columns: 3fr 1fr; - } - - header{ - grid-template-columns: 3fr 1fr; - } - - #left{ - grid-column: 1; - grid-row: 1; - - display: grid; - grid-template-columns: 1fr 800px; - grid-template-rows: 0fr 1fr 0fr; - } +def remove_from_playlist(name, video_info_list): + ids = [json.loads(video)['id'] for video in video_info_list] + with open(os.path.join(playlists_directory, name + ".txt"), 'r', encoding='utf-8') as file: + videos = file.read() + videos_in = videos.splitlines() + videos_out = [] + for video in videos_in: + if json.loads(video)['id'] not in ids: + videos_out.append(video) + with open(os.path.join(playlists_directory, name + ".txt"), 'w', encoding='utf-8') as file: + file.write("\n".join(videos_out) + "\n") - #right{ - grid-column: 2; - grid-row: 1; - } -''' def get_playlists_list_page(): page = '''