aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/local_playlist.py
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2020-12-15 21:52:04 -0500
committerJesús <heckyel@hyperbola.info>2020-12-15 21:52:04 -0500
commitb9a3082e7c654d97cecc5410c086e13a7b046909 (patch)
treedc093ccb2246e7df0beaca5deb8b7467620b74a2 /youtube/local_playlist.py
parentf4b36a220d085080a881dbe2f63e51b2fb28a003 (diff)
downloadyt-local-b9a3082e7c654d97cecc5410c086e13a7b046909.tar.lz
yt-local-b9a3082e7c654d97cecc5410c086e13a7b046909.tar.xz
yt-local-b9a3082e7c654d97cecc5410c086e13a7b046909.zip
pep8
Diffstat (limited to 'youtube/local_playlist.py')
-rw-r--r--youtube/local_playlist.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py
index 891bb76..776e992 100644
--- a/youtube/local_playlist.py
+++ b/youtube/local_playlist.py
@@ -15,6 +15,7 @@ from flask import request
playlists_directory = os.path.join(settings.data_dir, "playlists")
thumbnails_directory = os.path.join(settings.data_dir, "playlist_thumbnails")
+
def video_ids_in_playlist(name):
try:
with open(os.path.join(playlists_directory, name + ".txt"), 'r', encoding='utf-8') as file:
@@ -23,6 +24,7 @@ def video_ids_in_playlist(name):
except FileNotFoundError:
return set()
+
def add_to_playlist(name, video_info_list):
if not os.path.exists(playlists_directory):
os.makedirs(playlists_directory)
@@ -65,6 +67,7 @@ def get_local_playlist_videos(name, offset=0, amount=50):
gevent.spawn(util.download_thumbnails, os.path.join(thumbnails_directory, name), missing_thumbnails)
return videos[offset:offset+amount], len(videos)
+
def get_playlist_names():
try:
items = os.listdir(playlists_directory)
@@ -75,6 +78,7 @@ def get_playlist_names():
if ext == '.txt':
yield name
+
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:
@@ -109,14 +113,16 @@ def get_local_playlist_page(playlist_name=None):
page = int(request.args.get('page', 1))
offset = 50*(page - 1)
videos, num_videos = get_local_playlist_videos(playlist_name, offset=offset, amount=50)
- return flask.render_template('local_playlist.html',
- header_playlist_names = get_playlist_names(),
- playlist_name = playlist_name,
- videos = videos,
- num_pages = math.ceil(num_videos/50),
- parameters_dictionary = request.args,
+ return flask.render_template(
+ 'local_playlist.html',
+ header_playlist_names=get_playlist_names(),
+ playlist_name=playlist_name,
+ videos=videos,
+ num_pages=math.ceil(num_videos/50),
+ parameters_dictionary=request.args,
)
+
@yt_app.route('/playlists/<playlist_name>', methods=['POST'])
def path_edit_playlist(playlist_name):
'''Called when making changes to the playlist from that playlist's page'''
@@ -128,6 +134,7 @@ def path_edit_playlist(playlist_name):
else:
flask.abort(400)
+
@yt_app.route('/edit_playlist', methods=['POST'])
def edit_playlist():
'''Called when adding videos to a playlist from elsewhere'''
@@ -137,7 +144,9 @@ def edit_playlist():
else:
flask.abort(400)
+
@yt_app.route('/data/playlist_thumbnails/<playlist_name>/<thumbnail>')
def serve_thumbnail(playlist_name, thumbnail):
# .. is necessary because flask always uses the application directory at ./youtube, not the working directory
- return flask.send_from_directory(os.path.join('..', thumbnails_directory, playlist_name), thumbnail)
+ return flask.send_from_directory(
+ os.path.join('..', thumbnails_directory, playlist_name), thumbnail)