|
import streamlit as st |
|
import re |
|
import os |
|
|
|
|
|
def process_line(line): |
|
|
|
if re.search(r'\b[A-G][#b]?m?\b', line): |
|
|
|
line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line) |
|
return line |
|
|
|
|
|
def process_chord_sheet(chord_sheet): |
|
processed_lines = [] |
|
for line in chord_sheet.split('\n'): |
|
processed_line = process_line(line) |
|
processed_lines.append(processed_line) |
|
return '<br>'.join(processed_lines) |
|
|
|
|
|
def create_search_url_wikipedia(artist_song): |
|
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search=" |
|
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') |
|
|
|
def create_search_url_youtube(artist_song): |
|
base_url = "https://www.youtube.com/results?search_query=" |
|
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') |
|
|
|
def create_search_url_chords(artist_song): |
|
base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value=" |
|
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') |
|
|
|
def create_search_url_lyrics(artist_song): |
|
base_url = "https://www.google.com/search?q=" |
|
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') + '+lyrics' |
|
|
|
|
|
def main(): |
|
st.title('Chord Sheet Processor') |
|
|
|
|
|
song_name_artist = st.text_input("Song Name by Music Artist", value="Hold On, Hold On by Neko Case") |
|
|
|
|
|
filename = song_name_artist.replace(", ", "_").replace(" ", "_").lower() + ".txt" |
|
if st.button('Open Chord Sheet'): |
|
if os.path.exists(filename): |
|
with open(filename, "r") as file: |
|
chord_sheet = file.read() |
|
st.text_area("Chord Sheet", chord_sheet, height=300) |
|
processed_sheet = process_chord_sheet(chord_sheet) |
|
st.markdown(processed_sheet, unsafe_allow_html=True) |
|
else: |
|
st.error("File not found.") |
|
|
|
|
|
chord_sheet_input = st.text_area("Enter your chord sheet here:", height=300) |
|
|
|
if st.button('Save Chord Sheet'): |
|
with open(filename, "w") as file: |
|
file.write(chord_sheet_input) |
|
st.success("Chord sheet saved.") |
|
|
|
if st.button('Process Chord Sheet'): |
|
if chord_sheet_input: |
|
|
|
processed_sheet = process_chord_sheet(chord_sheet_input) |
|
|
|
st.markdown(processed_sheet, unsafe_allow_html=True) |
|
else: |
|
st.error("Please input a chord sheet to process.") |
|
|
|
|
|
st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_name_artist)})") |
|
st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_name_artist)})") |
|
st.markdown(f"[🎸Chords]({create_search_url_chords(song_name_artist)})") |
|
st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_name_artist)})") |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|