PK!kppamalgama/__init__.pyfrom .amalgama import get_url, get_html, get_all_translates_lines, get_all_translates, get_first_translate_text PK!醔 amalgama/amalgama.pyfrom typing import List, Callable, Iterable from pyquery import PyQuery as pq def build_url(s: str) -> str: s = s.lower() chars_to_underscore = [" ", "-", "/", "'", "__"] for char in chars_to_underscore: s = s.replace(char, "_") s = s.replace("$", "s") s = s.replace("&", "and") s = s.replace("+", "and") s = s.replace("é", 'e') s = s.replace(".", "") return s def get_url(artist: str, title: str) -> str: artist, title = map(build_url, [artist, title]) if artist.startswith("the"): artist = artist[4:] amalgama_url = f"https://www.amalgama-lab.com/songs/{artist[0]}/{artist}/{title}.html" return amalgama_url def get_html(html: str) -> str: d = pq(html) d("script").remove() text = d(".texts.col") text("div#quality").remove() text("div.noprint").remove() return text.html() def get_all_translates_lines(html: str) -> List[str]: d = pq(html) lines = [f"{d('h2.translate').text()}\n\n"] for i in d("div.translate"): t = pq(i).text() if t: if t[0].isdigit(): lines.append(t) else: lines.append(f"{t}\n") else: lines.append("\n") return lines def get_all_original_lines(html: str) -> List[str]: d = pq(html) lines = [f"{d('h2.original').text()}\n\n"] for i in d("div.original"): t = pq(i).text() if t: lines.append(f"{t}\n") else: lines.append("\n") return lines def split_before(iterable: Iterable[str], pred: Callable[[str], bool]) -> Iterable[List[str]]: buf: List[str] = [] for item in iterable: if pred(item) and buf: yield buf buf = [] buf.append(item) yield buf def get_all_translates(html: str) -> List[List[str]]: lines = get_all_translates_lines(html) translations = list(split_before(lines, lambda s: "(перевод" in s)) return translations def get_all_originals(html: str, song: str) -> List[List[str]]: lines = get_all_original_lines(html) translations = list(split_before(lines, lambda s: song in s)) return translations def get_first_translate_text(html: str) -> str: translations = get_all_translates(html) return "".join(translations[0]) def get_first_original_text(html: str, song: str) -> str: translations = get_all_originals(html, song) return "".join(translations[0]) if __name__ == "__main__": import requests artist, song = "Pink Floyd", "Time" url = get_url(artist, song) try: response = requests.get(url) response.raise_for_status() lyrics = get_first_original_text(response.text, song) lyrics_translate = get_first_translate_text(response.text) print(lyrics) print(lyrics_translate) except requests.exceptions.HTTPError: print(f"{artist}-{song} not found in amalgama {url}") PK!.. amalgama-0.1.4.dist-info/LICENSEMIT License Copyright (c) 2018 Andriy Orehov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HnHTUamalgama-0.1.4.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Hv !amalgama-0.1.4.dist-info/METADATAV}kG>SR] Mb֣-%8N^\$jA  bj&~oKRj<' w]/Ҕr@&<]V<867}ߏ^Rgo+2[)ltVMEFiO\& XqGEN挳ŭBjazڸ٥sgBC)`zG>]J+yHnLAZE"³Ner}o's/Jc K_FVΝNtE\"] *"2G|m}m3T[c 2e :4L,EO*?/sf(Εݩt#?;N?y9j G tr[9j>ȷcY/Xo@渉yo-R{ ~sk|^׸zY"Pޡ,:yp:;1xsԏ`~H`߅=#Dacz5▨}j\٭wTM]v7F }w; L(\YSAN"Bg_X}~k\R0;vj n2rD۹&c2ّ#TF<;]t|C:½^(FJ`vy5' ^gF،EF1'(̭Ou.;fJݓSi` PK!H$%amalgama-0.1.4.dist-info/RECORDu̹r@oYC+B±Yq7ק"Uִ5]7QA?SuxelgB:­,Š.ׂSGؕżFb)2.KfJ:qӆ @Pe/c8gEw&ov}tpmpARP$M!E蟯yojgH}0ڭj6ml> _P%NVz:0 -ҖқbCy I;2C".%]|N^`PK!kppamalgama/__init__.pyPK!醔 amalgama/amalgama.pyPK!.. h amalgama-0.1.4.dist-info/LICENSEPK!HnHTUamalgama-0.1.4.dist-info/WHEELPK!Hv !damalgama-0.1.4.dist-info/METADATAPK!H$%amalgama-0.1.4.dist-info/RECORDPK"