Skip to content

Commit

Permalink
feat: add support for importing songs from the cifraclub.com.br
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Chodur <[email protected]>
  • Loading branch information
FUSAKLA committed Apr 6, 2024
1 parent 4f351fc commit 4b0b086
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"https://api.qrserver.com/",
"https://acordes.lacuerda.net/",
"https://velky-zpevnik.cz/",
"https://www.songbook.fun/"
"https://www.songbook.fun/",
"https://cifraclub.com.br/",
"https://www.cifraclub.com.br/"
]
}
5 changes: 5 additions & 0 deletions src/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function getSupportedChordsImportSites() {
regexp: /acordes\.lacuerda\.net/,
processor: getLacuerdaChords,
},
{
domain: "cifraclub.com.br",
regexp: /cifraclub\.com\.br/,
processor: getCifraclubChords,
},
{
domain: "pisnicky-akordy.cz",
regexp: /pisnicky-akordy\.cz/,
Expand Down
27 changes: 27 additions & 0 deletions src/import/sites/cifraclub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function getCifraclubChords(url: string) {
const html = UrlFetchApp.fetch(url).getContentText();
const chordsDivRegexp = /<pre>\s*(\S[\s\S]*)<\/pre>/g;
const chordsDivMatch = html.match(chordsDivRegexp);
if (chordsDivMatch === null) {
throw Error("failed to find the <pre> chords part.");
}
const chordsText = chordsDivMatch[0].replace(/<[^>]+>/g, "");
const metadataRegexp = /<title>(.+) - (.+) -.*<\/title>/;
const metadataMatch = html.match(metadataRegexp);
if (metadataMatch === null || metadataMatch.length !== 3) {
throw Error("failed to find the chords metadata.");
}
let youtubeLink = "";
// Not sure where to find the link to the youtube video.
// const youtubeLinkRegexp = /href="([^"]+)".*title="YouTube"/;
// const youtubeMatch = html.match(youtubeLinkRegexp);
// if (youtubeMatch && youtubeMatch.length === 2) {
// youtubeLink = youtubeMatch[1];
// }
return {
artist: metadataMatch[2],
songName: metadataMatch[1],
videoLink: youtubeLink,
rows: chordsText.split("\n"),
};
}

0 comments on commit 4b0b086

Please sign in to comment.