Backend for songs.zachdecook.com
misc gemini additions
Zach DeCook 2021-09-28
parent 0586163 · commit 753593f
m---------chordsdata0
-rwxr-xr-xlaravel/applyedit.php13
-rwxr-xr-xlaravel/public/playlist.gmi3
-rwxr-xr-xlaravel/public/song.gmi.php2
4 files changed, 14 insertions, 4 deletions
diff --git a/chordsdata b/chordsdata
-Subproject 8f767cef5ccd8754d6c4b86d08bc8f76a3a0e0d
+Subproject e0426e668ca5b34f551e697166bc32f5d3c2776
diff --git a/laravel/applyedit.php b/laravel/applyedit.php
index b9aa619..bd9f296 100755
--- a/laravel/applyedit.php
+++ b/laravel/applyedit.php
@@ -8,12 +8,20 @@ $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
use App\Song;
$imap = imap_open($mailbox, $username, $password);
+if (!$imap){
+ printf("no imap :(");
+ exit(1);
+}
$check = imap_check($imap); $number = $check->Nmsgs;
+if (!$check){
+ printf("no check :(");
+ exit(1);
+}
// Just check the newest 10 messages.
-for($i = 0; $i < 10; $i++) {
+for($i = 0; $i < 30; $i++) {
// TODO: Process these in order?
$header = imap_header($imap, $number - $i);
- if (strpos($header->to[0]->mailbox, "+songs")){
+ if (isset($header->to[0]) && strpos($header->to[0]->mailbox, "+songs")){
$json = json_decode($header->subject);
$song = Song::findOrFail($json->id);
$body = quoted_printable_decode(imap_body($imap, $number - $i));
@@ -25,7 +33,6 @@ for($i = 0; $i < 10; $i++) {
$song->save();
imap_delete($imap, $number - $i);
printf("updated song {$song->id}");
- exit(0);
}
}
exit(0);
diff --git a/laravel/public/playlist.gmi b/laravel/public/playlist.gmi
index d384b6d..95d5c30 100755
--- a/laravel/public/playlist.gmi
+++ b/laravel/public/playlist.gmi
@@ -18,10 +18,11 @@ if($playlist){
return;
}
$playlist->songs()->toggle([$song->id]);
+ printf("30 " . $playlist->name . "\r\n");return;
}
printf("20 text/gemini\r\n");
} else {
-printf("30 " . Playlist::inRandomOrder()->first()->name . "\r\n");return;
+ printf("30 " . Playlist::inRandomOrder()->first()->name . "\r\n");return;
}
$songs = $playlist->songs()->pluck('title','songs.id');
?>
diff --git a/laravel/public/song.gmi.php b/laravel/public/song.gmi.php
index edf9b2a..7da3606 100755
--- a/laravel/public/song.gmi.php
+++ b/laravel/public/song.gmi.php
@@ -25,6 +25,8 @@ printf("30 " . Song::inRandomOrder()->first()->id . "\r\n");return;
=> <?= $song->id ?>?q Transpose from <?= $song->plain_key ?>
+<?= $song->audio ? "=> {$song->audio} Listen to this song" : "" ?>
+
```chord sheet
<?= $txt = $song->textTranspose(getenv('QUERY_STRING')??'') ?>