def get_strumming_content(self): begin = "Tempo: %s, Time signature: %s\n" % (self.tempo, self.timesig) content = self.strummings if content is None: return HtmlFormatter.pre("No strumming content") for t in content.find_all('h3'): t.decompose() for t in content.find_all('span', class_="tab_help"): t.decompose() for t in content.find_all("br"): t.replace_with("\n") for t in content.find_all(): t.unwrap() return HtmlFormatter.pre(begin + "".join(content.contents).strip())
def get_chord_content(self): sorted_chords = sorted(self.chords, key=chords.Chord.by_name) if not sorted_chords: return "" alignment = max(len(c.name) for c in sorted_chords) return HtmlFormatter.pre("\n".join( c.get_short_html_content(alignment) for c in sorted_chords))
def get_tab_content(self): # It is a bit tricky, chords are described on the same lines are lyrics content = self.tab_content for t in content.find_all("div", class_="pLgn"): t.insert_after('\n') for t in content.find_all(): t.unwrap() content = "".join(str(t) for t in content.contents) return HtmlFormatter.pre(clean_whitespace(content))
def pretty_format_chords_variations(cls, fret_details): """Format variations of a same chords: handle indices and alignment.""" idx_width = len(str(len(fret_details))) fret_width = max(len(f) for frets in fret_details for f in frets) return HtmlFormatter.pre( "\n".join("%s:%s" % ( str(i).rjust(idx_width), "".join(f.rjust(1 + fret_width) for f in frets) ) for i, frets in enumerate(fret_details, start=1)))
def get_tab_content(self): dict_chord = { c.name: str(c.get_link(display_type=False)) for c in self.chords } if self.tab_content is None: return HtmlFormatter.pre("No tab content") content = self.tab_content.find('pre', class_="small-12 column") for t in content.find_all('span'): t.unwrap() for t in content.find_all('a'): v = dict_chord.get(list(t.strings)[0], None) if v is not None: t.replace_with(BeautifulSoup(v, "html.parser")) else: t.unwrap() for t in content.find_all('img'): t.unwrap() return HtmlFormatter.pre(clean_whitespace(str(content)))
def get_html_content(self): strum_values = { 1: (' ', '↓'), 101: (' ', '↑'), 202: (' ', ' '), 3: ('>', '↓'), # arrow with a small > 103: ('>', '↑'), # arrow with a small > 2: ('x', '↓'), # arrow with a small x 102: ('x', '↑'), # arrow with a small x 201: (' ', 'x'), 203: (' ', '𝄥'), # the pause symbol } width = 2 values = [strum_values[m['measure']] for m in self.measures] numbers = list(range(len(values))) if self.is_triplet: assert self.denuminator in ( 8, 16 ), "denuminator=%d is not handled for triplet" % self.denuminator if self.denuminator == 8: coef, beg, mid, end, fill = 3, "└", "┴", "┘", "─" else: coef, beg, mid, end, fill = 6, "╘", "╧", "╛", "═" beg2, mid2, end2, fill2 = "└", "3", "┘", "─" symbols = [[beg.ljust(width, fill), mid.ljust(width, fill), end], [ beg2.ljust(width, fill2), mid2.ljust(width, fill2), end2 ]] else: assert self.denuminator in ( 4, 8, 16), "denuminator=%d is not handled" % self.denuminator if self.denuminator == 4: coef, beg, end, fill = 1, "│", "│", " " elif self.denuminator == 8: coef, beg, end, fill = 2, "└", "┘", "─" else: coef, beg, end, fill = 4, "╘", "╛", "═" symbols = [beg.ljust(width, fill), end], patterns = [(s[0] for s in values), (s[1] for s in values), ((str(1 + i // coef) if i % coef == 0 else '&' if (2 * i % coef == 0) else '') for i in numbers)] for symbol in symbols: patterns.append(s for s, _ in zip(itertools.cycle(symbol), numbers)) patterns = [ "".join(v.ljust(width) for v in p).rstrip() for p in patterns ] lines = "\n".join(p for p in patterns if p) part = self.part if self.part else "All" return HtmlFormatter.pre( "%s: %d bpm, triplet:%d, denuminator:%d, %d measures\n%s" % (part, self.bpm, self.is_triplet, self.denuminator, len(self.measures), lines))
def get_tab_content(self): dict_chord = { c.name: str(c.get_link(display_type=False)) for c in self.chords } content = (self.tab_content.replace('\r\n', '\n').replace( '[tab]', '').replace('[/tab]', '').replace('>', '>').replace('<', '<')) for chord, link in dict_chord.items(): content = content.replace("[ch]%s[/ch]" % chord, link) return HtmlFormatter.pre(clean_whitespace(content))
def get_tab_content(self): dict_chord = { c.name: str(c.get_link(display_type=False)) for c in self.chords } content = self.tab_content for t in content.find_all(): if t.name == 'u': v = dict_chord.get(t.string, None) if v is not None: t.replace_with(BeautifulSoup(v, "html.parser")) else: t.unwrap() else: t.unwrap() return HtmlFormatter.pre("".join(str(t) for t in content.contents))
def get_tab_content(self): dict_chord = { c.name: str(c.get_link(display_type=False)) for c in self.chords } content = self.tab_content for t in content.find_all('span'): t.decompose() for t in content.find_all(): if t.name == 'a': t.replace_with( BeautifulSoup(dict_chord[t.string], "html.parser")) else: t.unwrap() content = "".join(str(t) for t in content.contents) return HtmlFormatter.pre(clean_whitespace(content))
def get_tab_content(self): content = self.tab_content for t in content.find_all('img'): t.decompose() for t in content.find_all('h2'): t.decompose() for t in content.find_all("div", class_="gptslot"): t.decompose() for t in content.find_all(class_="hide-for-print"): t.decompose() for t in content.find_all("span", class_="dropt"): for t2 in t.find_all("span"): t2.decompose() for t in content.find_all(): t.unwrap() content = "".join(str(t) for t in content.contents) return HtmlFormatter.pre(clean_whitespace(content))
def get_tab_content(self): dict_chord = { c.name: str(c.get_link(display_type=False)) for c in self.chords } content = self.tab_content for t in content.find_all('span', class_="js-tab-row js-empty-tab-row"): t.decompose() for t in content.find_all(style="display: block"): t.insert_after('\n') for t in content.find_all(): if " ".join(t.attrs.get('class', [])) != "gt-chord js-tab-ch js-tapped": t.unwrap() else: t.replace_with( BeautifulSoup(dict_chord[t.string], "html.parser")) content = "".join(str(t) for t in content.contents) return HtmlFormatter.pre(clean_whitespace(content))
def format_fingering_detail(cls, fingering): show_finger_number_on_tab = False show_finger_number_below_tab = True show_capo = True handle_fret_offset = True frets = list(reversed(fingering['frets'])) fingers = list(reversed(fingering['fingers'])) nb_strings = len(frets) # Display as many frets as needed and at least 5 for cosmetic reasons fret_offset = fingering['fret'] if handle_fret_offset else 0 if fret_offset: assert fret_offset > 1 fret_offset -= 1 nb_frets = max(max(frets) - fret_offset, 5) width = 2 height = 1 # Drawing: (beg, mid, end, fill) empty = ("", "", " ", " ") top = ("┍", "┯", "┑", "━") mid = ("├", "┼", "┤", "─") bottom = ("└", "┴", "┘", "─") vert_lines = ("│", "│", "│", " ") cap, cap_fill = "┿", "━" # Or: "╪", "═" symbols = [] symbols.append(empty) symbols.append(top) for i in range(nb_frets - 1): symbols.extend([vert_lines] * height + [mid]) symbols.extend([vert_lines] * height + [bottom]) if show_finger_number_below_tab: symbols.append(empty) fretboard = [([beg.ljust(width, fill)] + [mid.ljust(width, fill)] * (nb_strings - 2) + [end] + [" "]) for beg, mid, end, fill in symbols] row_start_index = 2 def set_fretboard_content_by_abs_position(s, i, j): fretboard[i][j] = s + fretboard[i][j][len(s):] def set_fretboard_content_by_fret_position(s, fr, j): fr -= fret_offset i = row_start_index + ((fr - 1) * (height + 1)) + (height // 2) set_fretboard_content_by_abs_position(s, i, j) for j, (fr, fi) in enumerate(zip(frets, fingers)): if fr > 0: assert fi in [0, 1, 2, 3, 4] fi_str = str(fi) if show_finger_number_on_tab else "O" set_fretboard_content_by_fret_position(fi_str, fr, j) if show_finger_number_below_tab: set_fretboard_content_by_abs_position(str(fi), -1, j) elif fr == 0: assert fi == 0 elif fr == -1: assert fi == 0 set_fretboard_content_by_abs_position("x", 0, j) else: assert False capos = fingering['listCapos'] if show_capo else [] for capo in capos: first_string = nb_strings - capo['lastString'] - 1 last_string = nb_strings - capo['startString'] - 1 capo_str = str(capo['finger']) if show_finger_number_on_tab else cap fr = capo['fret'] for j in range(first_string, last_string + 1): is_last = (j == last_string) capo_ = capo_str if is_last else capo_str.ljust(width, cap_fill) set_fretboard_content_by_fret_position(capo_, fr, j) if fret_offset: set_fretboard_content_by_abs_position(" fret " + str(fret_offset + 1), row_start_index, -1) pre_fretboard = HtmlFormatter.pre("\n".join("".join(line).rstrip() for line in fretboard)) # pre_debug = HtmlFormatter.pre(str(fingering)) return pre_fretboard
def get_tab_content(self): content = self.tab_content return HtmlFormatter.pre( clean_whitespace("".join(str(t) for t in content.contents)))