-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for importing songs from the cifraclub.com.br
Signed-off-by: Martin Chodur <[email protected]>
- Loading branch information
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
}; | ||
} |