server-side support for adding to local playlists

This commit is contained in:
James Taylor 2018-07-08 01:06:54 -07:00
parent f36c1d26a4
commit 6ad09eb53a
4 changed files with 17 additions and 15 deletions

2
.gitignore vendored
View File

@ -3,8 +3,8 @@ __pycache__/
*$py.class
youtube_dl/
debug/
data/
banned_addresses.txt
youtube/common_old.py
youtube/common_older.py
youtube/watch_old.py
youtube/watch_later.txt

13
youtube/local_playlist.py Normal file
View File

@ -0,0 +1,13 @@
import os.path
import json
playlists_directory = os.path.normpath("data/playlists")
def add_to_playlist(name, video_info_list):
with open(os.path.join(playlists_directory, name), "a", encoding='utf-8') as file:
for info in video_info_list:
file.write(info + "\n")
def get_playlist_page(name):
pass

View File

@ -1,11 +0,0 @@
import os.path
import json
watch_later_file = os.path.normpath("youtube/watch_later.txt")
def add_to_watch_later(video_info_list):
with open(watch_later_file, "a", encoding='utf-8') as file:
for info in video_info_list:
file.write(info + "\n")
def get_watch_later_page():
pass

View File

@ -1,6 +1,6 @@
import mimetypes
import urllib.parse
from youtube import watch_later, watch, search, playlist, channel, comments
from youtube import local_playlist, watch, search, playlist, channel, comments
YOUTUBE_FILES = (
"/shared.css",
"/opensearch.xml",
@ -47,8 +47,8 @@ def youtube(env, start_response):
elif method == "POST":
if path == "/edit_playlist":
fields = urllib.parse.parse_qs(env['wsgi.input'].read().decode())
if fields['action'][0] == 'add' and fields['playlist_name'][0] == 'watch_later':
watch_later.add_to_watch_later(fields['video_info_list'])
if fields['action'][0] == 'add':
local_playlist.add_to_playlist(fields['playlist_name'][0], fields['video_info_list'])
start_response('204 No Content', ())
else: