ironss / musicxml2chordpro

Extract chord charts from MusicXML files
5 stars 3 forks source link

work-title missing #3

Open YogieAnamCara opened 3 years ago

YogieAnamCara commented 3 years ago

Hi,

if there is no

<work>
    <work-title>Songtitle</work-title>
</work>

in the musicXML the script is not running.

File "xml2pro.py", line 165, in x1.process_file() File "xml2pro.py", line 64, in process_file self.process_root() File "xml2pro.py", line 69, in process_root self.title = title_element.text

My musicXML is just having a

<movement-title>Songtitle</movement-title>

as it was produced by:

        <software>SmartScore 64 Songbook Edition</software>

can this script be adjusted to take both titles into account?

Many thanks!

Cheers Yogie

YogieAnamCara commented 3 years ago

To be honest I'm not a programmer, but I played a little and changed the code for myself to work and replaced the "Get the song name" part to:

def process_root(self):
    # Get the song name
    try:
        title_element = self.root.find('work/work-title')
        self.title = title_element.text
    except AttributeError: 
        title_element = self.root.find('movement-title')
        self.title = title_element.text
    except AttributeError:
        title_element = 'None'        
        self.title = title_element.text
    finally:    
        self.write('{{title:{title}}}\n'.format(title=self.title))