Created
June 8, 2024 18:26
-
-
Save bemxio/427af3eeb67ce7123f7979ae45a8f2d4 to your computer and use it in GitHub Desktop.
A little Python script to generate a loop of the Homebrew Channel theme. Uses standard libraries, so no need for installing any with `pip`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <https://unlicense.org> | |
""" | |
import urllib.request | |
import os.path | |
import wave | |
# constants | |
INTRO_PART = "wiibrew-banner-intro-part.wav" | |
LOOP_PART = "wiibrew-banner-loop-part.wav" | |
OUTPUT_FILE = "wiibrew-banner.wav" | |
LENGTH = 80 * 60 # 80 minutes * 60 seconds = 4800 seconds | |
# download the parts if they don't exist | |
if not os.path.exists(INTRO_PART): | |
print("Intro part not found, downloading...") | |
urllib.request.urlretrieve( | |
"https://github.com/fail0verflow/hbc/raw/master/channel/banner/sound/wiibrew-banner-intro-part.wav", | |
INTRO_PART | |
) | |
print("Intro part downloaded successfully!") | |
if not os.path.exists(LOOP_PART): | |
print("Loop part not found, downloading...") | |
urllib.request.urlretrieve( | |
"https://github.com/fail0verflow/hbc/raw/master/channel/banner/sound/wiibrew-banner-loop-part.wav", | |
LOOP_PART | |
) | |
print("Loop part downloaded successfully!") | |
# initialize WAV objects | |
intro = wave.open(INTRO_PART, "rb") | |
loop = wave.open(LOOP_PART, "rb") | |
theme = wave.open(OUTPUT_FILE, "wb") | |
# get frame amount for each part | |
intro_frame_amount = intro.getnframes() | |
loop_frame_amount = loop.getnframes() | |
# set audio parameters | |
theme.setnchannels(loop.getnchannels()) | |
theme.setsampwidth(loop.getsampwidth()) | |
theme.setframerate(loop.getframerate()) | |
# write intro part | |
theme.writeframes(intro.readframes(intro_frame_amount)) | |
# write loop part until the end | |
count = (LENGTH * theme.getframerate() - intro_frame_amount) // loop_frame_amount | |
for _ in range(count): | |
theme.writeframes(loop.readframes(loop_frame_amount)) | |
loop.rewind() | |
# close files | |
intro.close() | |
loop.close() | |
theme.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment