File size: 3,376 Bytes
a1de66d
 
fbfdf9e
00a404f
a1de66d
 
 
 
 
 
 
00a404f
a1de66d
 
 
 
 
 
 
00a404f
fbfdf9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1de66d
 
 
00a404f
fbfdf9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1de66d
 
00a404f
fbfdf9e
 
 
 
 
a1de66d
 
 
 
 
 
 
 
00a404f
fbfdf9e
 
 
 
 
 
a1de66d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import streamlit as st
import re
import os

# Function to process each line of the chord sheet
def process_line(line):
    # Check if the line is a chord line (contains chord symbols)
    if re.search(r'\b[A-G][#b]?m?\b', line):
        # Replace chord symbols with image tags
        line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
    return line

# Function to process the entire chord sheet
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)

# Functions to create search URLs
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'

# Streamlit app
def main():
    st.title('Chord Sheet Processor')

    # Song name and artist input
    song_name_artist = st.text_input("Song Name by Music Artist", value="Hold On, Hold On by Neko Case")

    # File operations
    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.")

    # Text area for user to input the chord sheet
    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:
            # Processing the chord sheet
            processed_sheet = process_chord_sheet(chord_sheet_input)
            # Displaying the processed chord sheet
            st.markdown(processed_sheet, unsafe_allow_html=True)
        else:
            st.error("Please input a chord sheet to process.")

    # Displaying links
    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()