diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..65cf5ff4d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "appService.defaultWebAppToDeploy": "undefined/subscriptions/234d56d2-1ea1-41f6-ad2d-3a4fd4c17e9b/resourceGroups/appsvc_linux_centralus_basic/providers/Microsoft.Web/sites/jeff-flask", + "appService.deploySubpath": "." +} \ No newline at end of file diff --git a/app.py b/app.py index 3d1808cf6..705ab0c98 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,8 @@ import os +import requests +from flask import Flask, redirect +from urllib.parse import urlparse, parse_qs from flask import (Flask, redirect, render_template, request, send_from_directory, url_for) @@ -11,21 +14,36 @@ def index(): print('Request for index page received') return render_template('index.html') -@app.route('/favicon.ico') -def favicon(): - return send_from_directory(os.path.join(app.root_path, 'static'), - 'favicon.ico', mimetype='image/vnd.microsoft.icon') - -@app.route('/hello', methods=['POST']) -def hello(): - name = request.form.get('name') - - if name: - print('Request for hello page received with name=%s' % name) - return render_template('hello.html', name = name) - else: - print('Request for hello page received with no name or blank name -- redirecting') - return redirect(url_for('index')) +@app.route('/') +def get_playlist_page(video_ids): + url = f"https://www.youtube.com/watch_videos?video_ids={video_ids}" + response = requests.get(url) + redirected_url = response.url + + parsed_url = urlparse(redirected_url) + query_params = parse_qs(parsed_url.query) + + if 'list' in query_params: + [playlist_id] = query_params['list'] + return redirect(f"https://www.youtube.com/playlist?list={playlist_id}") + else: + return "No playlist ID found." + +# @app.route('/favicon.ico') +# def favicon(): +# return send_from_directory(os.path.join(app.root_path, 'static'), +# 'favicon.ico', mimetype='image/vnd.microsoft.icon') +# +# @app.route('/hello', methods=['POST']) +# def hello(): +# name = request.form.get('name') +# +# if name: +# print('Request for hello page received with name=%s' % name) +# return render_template('hello.html', name = name) +# else: +# print('Request for hello page received with no name or blank name -- redirecting') +# return redirect(url_for('index')) if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt index a3c7c6ad6..8a3bed3ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Flask==2.0.2 gunicorn +requests