diff --git a/appsscript.json b/appsscript.json index 46ecd2a6..295eded9 100644 --- a/appsscript.json +++ b/appsscript.json @@ -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/" ] } diff --git a/src/import/import.ts b/src/import/import.ts index b4f11c2e..0c4bc905 100644 --- a/src/import/import.ts +++ b/src/import/import.ts @@ -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/, diff --git a/src/import/sites/cifraclub.ts b/src/import/sites/cifraclub.ts new file mode 100644 index 00000000..878b3cb1 --- /dev/null +++ b/src/import/sites/cifraclub.ts @@ -0,0 +1,27 @@ +function getCifraclubChords(url: string) { + const html = UrlFetchApp.fetch(url).getContentText(); + const chordsDivRegexp = /
\s*(\S[\s\S]*)<\/pre>/g; + const chordsDivMatch = html.match(chordsDivRegexp); + if (chordsDivMatch === null) { + throw Error("failed to find thechords part."); + } + const chordsText = chordsDivMatch[0].replace(/<[^>]+>/g, ""); + const metadataRegexp = /(.+) - (.+) -.*<\/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"), + }; +}