first commit

This commit is contained in:
Lasse Studion 2023-03-12 08:21:17 +01:00
commit b5a01e831b
3 changed files with 147 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*
!app.py
!requirements.txt
!.gitignore

92
app.py Normal file
View File

@ -0,0 +1,92 @@
from io import StringIO
from time import sleep
import streamlit as st
from bs4 import BeautifulSoup
st.title("Colorize your Hindenburg project")
st.markdown(
"""
- Set colors for a few clips on your timeline, idealy at least one clip from
each recording.
- Upload your Hindenburg projet file (ending with *nhsx*) to add the same color
to other clips origination from the same recording.
- Download the modified file *and put it in the same folder as your original project file*.
"""
)
# Ask for file.
uploaded_file = st.file_uploader(
"*Upload your project file*", label_visibility="hidden", type="nhsx", accept_multiple_files=False
)
if uploaded_file:
# Make soup.
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
soup = BeautifulSoup(stringio.read(), "xml")
project_name = soup.find("AudioPool")["Path"].replace(" Files", "")
new_clipboard_tag = soup.new_tag("Clipboard")
# Get colors from clips on timeline.
colors = {}
timline = soup.find("Tracks")
n_regions = len(timline.find_all("Region"))
for region in timline.find_all("Region"):
try:
colors[str(region["Ref"])] = int(region["Colour"])
except:
pass
# Area to print things.
s = st.empty()
# Give colors to clips in clipboard
for group in soup.find_all("Group"):
new_group_tag = group
for region in group.find_all("Region"):
try:
s.markdown(f':green[{region["Name"]}]')
sleep(1/n_regions)
except KeyError:
pass
new_region_tag = region
try:
new_region_tag["Colour"] = colors[region["Ref"]]
except KeyError:
new_region_tag["Colour"] = "0"
new_group_tag.append(new_region_tag)
new_clipboard_tag.append(new_group_tag)
soup.Session.Clipboard.replace_with(new_clipboard_tag)
# Give colors to clips on timeline.
new_tracks_tag = soup.find("Tracks")
tracks = soup.find("Tracks")
for track in tracks.find_all("Track"):
try:
s.markdown(f':green[{region["Name"]}]')
sleep(1/n_regions)
except KeyError:
pass
new_track_tag = track
for region in track.find_all("Region"):
new_region_tag = region
try:
new_region_tag["Colour"] = colors[region["Ref"]]
except KeyError:
new_region_tag["Colour"] = "0"
new_track_tag.append(new_region_tag)
new_tracks_tag.append(new_track_tag)
soup.Session.Tracks.replace_with(new_tracks_tag)
# Allow the user to download file.
with s:
st.markdown(":green[Exporting...]")
sleep(0.7)
st.download_button(
"Download file",
soup.encode("utf-8"),
file_name=f"{project_name}_colors.nhsx",
)

51
requirements.txt Normal file
View File

@ -0,0 +1,51 @@
altair==4.2.2
attrs==22.2.0
backports.zoneinfo==0.2.1
beautifulsoup4==4.11.2
blinker==1.5
cachetools==5.3.0
certifi==2022.12.7
charset-normalizer==3.1.0
click==8.1.3
decorator==5.1.1
entrypoints==0.4
gitdb==4.0.10
GitPython==3.1.31
idna==3.4
importlib-metadata==6.0.0
importlib-resources==5.12.0
Jinja2==3.1.2
jsonschema==4.17.3
markdown-it-py==2.2.0
MarkupSafe==2.1.2
mdurl==0.1.2
numpy==1.24.2
packaging==23.0
pandas==1.5.3
Pillow==9.4.0
pkgutil_resolve_name==1.3.10
protobuf==3.20.3
pyarrow==11.0.0
pydeck==0.8.0
Pygments==2.14.0
Pympler==1.0.1
pyrsistent==0.19.3
python-dateutil==2.8.2
pytz==2022.7.1
pytz-deprecation-shim==0.1.0.post0
requests==2.28.2
rich==13.3.2
semver==2.13.0
six==1.16.0
smmap==5.0.0
soupsieve==2.4
streamlit==1.20.0
toml==0.10.2
toolz==0.12.0
tornado==6.2
typing_extensions==4.5.0
tzdata==2022.7
tzlocal==4.2
urllib3==1.26.15
validators==0.20.0
zipp==3.15.0