Backend for songs.zachdecook.com
* Song: Detect chords
Zach DeCook 2021-01-05
parent bb67d22 · commit 4492535
m---------chordsdata0
-rw-r--r--laravel/app/Song.php8
2 files changed, 8 insertions, 0 deletions
diff --git a/chordsdata b/chordsdata
-Subproject 0fdbc6604dd6dc4ea84e72f7670de35b55c1066
+Subproject 15fac73c2d51857ff0b95055187f14b6ff4c040
diff --git a/laravel/app/Song.php b/laravel/app/Song.php
index 4ae3920..102a0ca 100644
--- a/laravel/app/Song.php
+++ b/laravel/app/Song.php
@@ -36,4 +36,12 @@ class Song extends Model
// TODO: Validate that this is plain.
return trim($this->key, "m");
}
+ public function getChordsAttribute()
+ {
+ $txt = str_replace(['(',')',"\n"]," ",$this->text);
+ $words = array_flip(explode(' ', $txt));
+ $allChords = json_decode(file_get_contents("public/js/chordsdata/chords.json"), TRUE);
+ $chords = array_intersect_key($allChords, $words);
+ return $chords;
+ }
}