diff options
author | Jesús <heckyel@hyperbola.info> | 2021-05-06 15:18:19 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-05-06 15:18:19 -0500 |
commit | 7feea3f839b4e78b865937e74689486a54ba0b92 (patch) | |
tree | a002d834ef98552b45d20c90c08823459b0d016f /youtube/subscriptions.py | |
parent | f9d1bfe05f57c13a66453a69a509f170b4027e5f (diff) | |
download | yt-local-7feea3f839b4e78b865937e74689486a54ba0b92.tar.lz yt-local-7feea3f839b4e78b865937e74689486a54ba0b92.tar.xz yt-local-7feea3f839b4e78b865937e74689486a54ba0b92.zip |
Add subscriptions export
plus design by heckyel
Diffstat (limited to 'youtube/subscriptions.py')
-rw-r--r-- | youtube/subscriptions.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py index c18f822..f540e35 100644 --- a/youtube/subscriptions.py +++ b/youtube/subscriptions.py @@ -732,6 +732,50 @@ def import_subscriptions(): return flask.redirect(util.URL_ORIGIN + '/subscription_manager', 303) +@yt_app.route('/export_subscriptions', methods=['POST']) +def export_subscriptions(): + include_muted = request.values.get('include_muted') == 'on' + with open_database() as connection: + with connection as cursor: + sub_list = [] + for channel_name, channel_id, muted in ( + _get_subscribed_channels(cursor)): + if muted and not include_muted: + continue + if request.values['export_format'] == 'json': + sub_list.append({ + 'kind': 'youtube#subscription', + 'snippet': { + 'muted': bool(muted), + 'resourceId': { + 'channelId': channel_id, + 'kind': 'youtube#channel', + }, + 'tags': _get_tags(cursor, channel_id), + 'title': channel_name, + }, + }) + elif request.values['export_format'] == 'opml': + sub_list.append({ + 'channel_name': channel_name, + 'channel_id': channel_id, + }) + if request.values['export_format'] == 'json': + r = flask.Response(json.dumps(sub_list), mimetype='text/json') + cd = 'attachment; filename="subscriptions.json"' + r.headers['Content-Disposition'] = cd + return r + elif request.values['export_format'] == 'opml': + r = flask.Response( + flask.render_template('subscriptions.xml', sub_list=sub_list), + mimetype='text/xml') + cd = 'attachment; filename="subscriptions.xml"' + r.headers['Content-Disposition'] = cd + return r + else: + return '400 Bad Request', 400 + + @yt_app.route('/subscription_manager', methods=['GET']) def get_subscription_manager_page(): group_by_tags = request.args.get('group_by_tags', '0') == '1' |