songs2slides

A tool that automatically finds song lyrics and creates lyric slideshows
git clone https://git.ashermorgan.net/songs2slides/
Log | Files | Refs | README

commit 1bffdbeb86deb0bd2e1baf81bac1a8969daf5bf9
parent b9ec2f6c72b71caa190886b298b72dccbbf90779
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date:   Mon, 25 May 2020 09:32:12 -0700

Merge pull request #7 from AsherMorgan/feature-pptx-upload

Implement PowerPoint uploading in the web app.
Diffstat:
MREADME.md | 1-
MSongs2Slides/routes.py | 20++++++++++++--------
MSongs2Slides/static/index.css | 9+++++++--
MSongs2Slides/static/index.js | 24++++++++----------------
MSongs2Slides/templates/index.html | 17++++++++++++-----
5 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/README.md b/README.md @@ -2,7 +2,6 @@ Creates a lyrics powerpoint from a list of songs. This program does NOT add any copyright information to the powerpoint. The user must do this manually. ## Features -Not all features are currently available in the web interface. - Can parse any song given the artist and title. - New slides are automatically started at the beginning of verses, bridges, choruses, etc. - The user can easily review and edit the slides. diff --git a/Songs2Slides/routes.py b/Songs2Slides/routes.py @@ -26,18 +26,22 @@ def settings(): # Get Powerpoint @app.route("/pptx", methods=["POST"]) def pptx(): - # Get settings - if "settings" in request.json: - settings = request.json["settings"] - else: - settings = defaultSettings - try: - # Create powerpoint + # Get settings and lyrics + settings = json.loads(request.form["settings"]) + lyrics = json.loads(request.form["lyrics"]) + + # Get temp temp = tempfile.NamedTemporaryFile(mode="w+t", suffix=".pptx", delete=False) - models.CreatePptx(request.json["lyrics"], temp.name, settings, False) temp.close() + # Save uploaded powerpoint + if (request.files["pptxFile"].filename != ""): + request.files["pptxFile"].save(temp.name) + + # Create powerpoint + models.CreatePptx(lyrics, temp.name, settings, True) + # Read file into stream with open(temp.name, 'rb') as f: pptx = io.BytesIO(f.read()) diff --git a/Songs2Slides/static/index.css b/Songs2Slides/static/index.css @@ -75,7 +75,7 @@ button { text-align: left; } -#lyrics { +#rawLyrics { width: 100%; resize: none; -webkit-box-sizing: border-box; @@ -83,8 +83,13 @@ button { box-sizing: border-box; } +#fileUpload { + text-align: left; + margin-top: 5px; +} + #errors { - margin-top: 10px; + margin-top: 15px; color: #E00000; font-weight: bold; } diff --git a/Songs2Slides/static/index.js b/Songs2Slides/static/index.js @@ -165,8 +165,8 @@ function getSongs() { // Get the parsed lyrics for the user to review async function ReviewLyrics() { // Show and hide elements - document.getElementById("lyrics").value = "Loading lyrics..."; - document.getElementById("lyrics").readOnly = true; + document.getElementById("rawLyrics").value = "Loading lyrics..."; + document.getElementById("rawLyrics").readOnly = true; document.getElementById("errors").textContent = ""; document.getElementById("songsContainer").hidden = true; document.getElementById("lyricsContainer").hidden = false; @@ -185,8 +185,8 @@ async function ReviewLyrics() { const json = await rawResponse.json(); // Set lyrics - document.getElementById("lyrics").value = json["lyrics"].join("\n\n") - document.getElementById("lyrics").readOnly = false; + document.getElementById("rawLyrics").value = json["lyrics"].join("\n\n") + document.getElementById("rawLyrics").readOnly = false; // Set errors if (json["errors"].length != 0) @@ -205,19 +205,11 @@ async function ReviewLyrics() { // Gets the powerpoint by submitting lyrics async function SubmitLyrics() { // Get lyrics - lyrics = document.getElementById("lyrics").value.split('\n\n'); + lyrics = document.getElementById("rawLyrics").value.split('\n\n'); - // Send POST request - const rawResponse = await fetch("/pptx", { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, body: JSON.stringify({"lyrics":lyrics,"settings":JSON.parse(localStorage.getItem("settings"))}) - }); - - // Download powerpoint - download(await rawResponse.blob()); + // Set hidden form values + document.getElementById("pptxSettingsField").value = localStorage.getItem("settings"); + document.getElementById("lyricsField").value = JSON.stringify(lyrics); // Show and hide elements document.getElementById("lyricsContainer").hidden = true; diff --git a/Songs2Slides/templates/index.html b/Songs2Slides/templates/index.html @@ -5,7 +5,6 @@ <meta name="viewport" content="width=device-width, user-scalable=no"/> <link rel="stylesheet" href="{{ url_for('static', filename='index.css') }}"></link> <script src="{{ url_for('static', filename='index.js') }}"></script> - <script src="https://cdnjs.cloudflare.com/ajax/libs/downloadjs/1.4.8/download.min.js"></script> </head> <body onload="onLoad();"> <h1>Songs2Slides</h1> @@ -32,21 +31,29 @@ </div> </div> - <div id="lyricsContainer" class="container" hidden> + <form id="lyricsContainer" class="container" hidden action="/pptx" method="POST" enctype="multipart/form-data"> + <input type="text" id="pptxSettingsField" name="settings" hidden> + <input type="text" id="lyricsField" name="lyrics" hidden> + <h3>Review your PowerPoint</h3> <p>Review and edit the parsed lyrics below and then click the create PowerPoint button.</p> <p>One blank line represents the start of a new slide and three blank lines represent a blank slide.</p> - <textarea rows="15" id="lyrics"></textarea> + <textarea rows="15" id="rawLyrics"></textarea> + + <div id="fileUpload"> + <label>Starting PowerPoint (optional): </label> + <input type="file" name="pptxFile" accept="application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.ms-powerpoint"> + </div> <p id="errors"></p> <div id="lyricsButtons"> <a id="lyricsBack" href="javascript:Back()">Back</a> - <button id="submitLyricsButton" onclick="SubmitLyrics();">Create Powerpoint</button> + <button id="submitLyricsButton" onclick="SubmitLyrics()">Create Powerpoint</button> </div> - </div> + </form> <div id="thankyou" hidden> <p>Thankyou for using Songs2Slides</p>