From 1c85df8ba1d04975e61acad1a50b4c1d8a9583d1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 21 May 2017 13:51:15 -0700 Subject: [PATCH] Add /videos to get overall list of videos. --- ycdl_site.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ycdl_site.py b/ycdl_site.py index 4a3e003..05bdf38 100644 --- a/ycdl_site.py +++ b/ycdl_site.py @@ -122,14 +122,34 @@ def get_channels(): channel['has_pending'] = youtube.channel_has_pending(channel['id']) return flask.render_template('channels.html', channels=channels) +@site.route('/videos') +@site.route('/videos/') @site.route('/channel/') @site.route('/channel//') -def get_channel(channel_id, download_filter=None): - channel = youtube.get_channel(channel_id) - if channel is None: - flask.abort(404) +def get_channel(channel_id=None, download_filter=None): + if channel_id is not None: + youtube.add_channel(channel_id) + channel = youtube.get_channel(channel_id) + if channel is None: + flask.abort(404) + else: + channel = None + videos = youtube.get_videos(channel_id=channel_id, download_filter=download_filter) + search_term = request.args.get('q', None) + if search_term is not None: + search_term = search_term.lower() + videos = [v for v in videos if search_term in v['title'].lower()] + + limit = request.args.get('limit', None) + if limit is not None: + try: + limit = int(limit) + videos = videos[:limit] + except ValueError: + pass + for video in videos: published = video['published'] published = datetime.datetime.utcfromtimestamp(published)