Skip to content

Commit

Permalink
feat: add default song
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfromyeg committed Dec 29, 2023
1 parent 740746c commit 58c4a6f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
24 changes: 19 additions & 5 deletions bereal/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
from .bereal import memories, send_code, verify_code
from .images import cleanup_images, create_images
from .logger import logger
from .utils import CONTENT_PATH, EXPORTS_PATH, FLASK_ENV, GIT_COMMIT_HASH, HOST, PORT, SECRET_KEY, str2mode, year2dates
from .utils import (
CONTENT_PATH,
DEFAULT_SONG_PATH,
EXPORTS_PATH,
FLASK_ENV,
GIT_COMMIT_HASH,
HOST,
PORT,
SECRET_KEY,
str2mode,
year2dates,
)
from .videos import build_slideshow

app = Flask(__name__)
Expand Down Expand Up @@ -122,10 +133,13 @@ def create_video() -> tuple[Response, int]:
os.makedirs(song_folder, exist_ok=True)
song_path = os.path.join(song_folder, "song.wav")

try:
wav_file.save(song_path)
except Exception as error:
logger.warning("Could not save music file, received: %s", error)
if wav_file:
try:
wav_file.save(song_path)
except Exception as error:
logger.warning("Could not save music file, received: %s", error)
else:
song_path = DEFAULT_SONG_PATH

logger.debug("Downloading images locally...")
result = memories(phone, year, token, sdate, edate)
Expand Down
Binary file added bereal/static/songs/midnight-city.wav
Binary file not shown.
Empty file removed bereal/static/videos/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions bereal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def str2mode(s: str | None) -> Mode:

IMAGES_PATH = os.path.join(STATIC_PATH, "images")

SONGS_PATH = os.path.join(STATIC_PATH, "songs")
DEFAULT_SONG_PATH = os.path.join(SONGS_PATH, "midnight-city.wav")

ENDCARD_TEMPLATE_IMAGE_PATH = os.path.join(IMAGES_PATH, "endCard_template.jpg")
ENDCARD_IMAGE_PATH = os.path.join(IMAGES_PATH, "endCard.jpg")
OUTLINE_PATH = os.path.join(IMAGES_PATH, "secondary_image_outline.png")
Expand Down
9 changes: 6 additions & 3 deletions bereal/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ def build_slideshow(image_folder: str, song_path: str, filename: str, mode: Mode

output_file = os.path.join(EXPORTS_PATH, filename)

if os.path.isfile(output_file):
logger.info("Skipping 'build_slideshow' stage; already created!")
return None
# Always create the slideshow, because song or mode may have changed!
# (...this next line is sometimes helpful for debugging, though)

# if os.path.isfile(output_file):
# logger.info("Skipping 'build_slideshow' stage; already created!")
# return None

create_slideshow(
input_folder=image_folder,
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const Footer: React.FC = () => {

formData.append("year", year);
formData.append("mode", mode);

// if left blank, a default song is used
if (file) {
formData.append("file", file);
}
Expand Down Expand Up @@ -176,7 +178,7 @@ const Footer: React.FC = () => {
htmlFor="song"
className="block text-sm font-medium text-gray-700"
>
Song
Song (if blank, there's a default song!)
</label>
<input
type="file"
Expand Down

0 comments on commit 58c4a6f

Please sign in to comment.