]> _ Git - songbook.git/commitdiff
.
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 17 Nov 2022 10:15:57 +0000 (11:15 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 17 Nov 2022 10:15:57 +0000 (11:15 +0100)
app/Field/CollectionList.php
app/Http/Controllers/FrontController.php
app/Jobs/DownloadAudioTracks.php
app/Jobs/OptimizeMP3.php [new file with mode: 0644]
app/Jobs/PitchShiftAudio.php
app/Models/Collection.php
app/Models/CollectionList.php
app/Models/Song.php
config/backpack/base.php
resources/views/song.blade.php
resources/views/vendor/backpack/base/dashboard.blade.php

index 68312fc5616fbe36740040038947718a318dc5a5..47216b7d3c367261f8e4bf7699c417939cac7af3 100644 (file)
@@ -22,11 +22,11 @@ class CollectionList extends SelectFromArrayMultiple
                     }
                 }
                 self::$___options[$item->id] = $item->name;
+
                 if (count($thisLists)) {
                     self::$___options[$item->id] .= ' - ' . __('Liste principale');
-                    self::$___options = array_merge(self::$___options, $thisLists);
+                    self::$___options += $thisLists;
                 }
-
             }
         }
         return self::$___options;
index f8bb936985f2bea7429db21530436f96eff2c0b5..39a7413fa01ea025113bdbe00948e000901d5077 100644 (file)
@@ -67,10 +67,10 @@ class FrontController extends Controller
             return $p;
         }
         $lists = CollectionList::withoutGlobalScope('ownerclause')->where('collection', $collection->id)->get();
-        $partition=false;
-        $lyrics_html='';
+        $partition = false;
+        $lyrics_html = '';
 
-        if($song->chorale) {
+        if ($song->chorale) {
             try {
                 $partition = $song->getFirstMediaInField('partition');
                 if ($partition) {
index 4d1c08c3d7844a238fb7e6bb035fb6948e0ac16d..6fcf7453794eddf2fb669b0d6b687924176d7b0f 100644 (file)
@@ -20,7 +20,7 @@ class DownloadAudioTracks implements ShouldQueue
     public function handle()
     {
         PHP::neverStop();
-        foreach (Song::all() as $song) {
+        foreach (Song::withoutGlobalScope('ownerclause')->all() as $song) {
             $data = $song->getPageData();
             $tracks = $data->audio;
             if (null === $tracks) {
diff --git a/app/Jobs/OptimizeMP3.php b/app/Jobs/OptimizeMP3.php
new file mode 100644 (file)
index 0000000..ee56e9e
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Models\Song;
+use Cubist\Backpack\Jobs\Base;
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Cubist\Util\PHP;
+use YoutubeDl\Options;
+use YoutubeDl\YoutubeDl;
+
+class OptimizeMP3 extends Base
+{
+    public function handle()
+    {
+        PHP::neverStop();
+        foreach (Song::withoutGlobalScope('ownerclause')->inRandomOrder()->get() as $song) {
+            $tracks = $song->getAudioTracks();
+            foreach ($tracks as $track) {
+                $mp3 = $track['path'];
+                if (!file_exists($mp3)) {
+                    continue;
+                }
+                $opt = str_replace('.mp3', '.opt.mp3', $mp3);
+
+                if (!file_exists($opt)) {
+                    $ff = new CommandLine('ffmpeg');
+                    $ff->setTimeout(300);
+                    $ff->setArg('y');
+                    $ff->setManualArg('-nostdin');
+                    $ff->setArg('i', $mp3);
+                    $ff->setManualArg('-ab 320k');
+                    $ff->setArg(null, $opt);
+                    $ff->execute();
+                }
+
+            }
+        }
+    }
+}
index 61d4cfd43269c4a1ff8c029cae185450bc0f1d28..748818668368c7b19f43f34fb1fc7a435b6028c1 100644 (file)
@@ -23,7 +23,7 @@ class PitchShiftAudio implements ShouldQueue
 
         DownloadAudioTracks::dispatchSync();
 
-        foreach (Song::inRandomOrder()->get() as $song) {
+        foreach (Song::withoutGlobalScope('ownerclause')->inRandomOrder()->get() as $song) {
             $tracks = $song->getAudioTracks();
             foreach ($tracks as $track) {
                 $mp3 = $track['path'];
index a552b87ed65cf601a93301750d7977b87680c8aa..ee5960dae1fc0a3fc566e070044b6f9ed3e23a45 100644 (file)
@@ -30,17 +30,7 @@ class Collection extends CubistMagicAbstractModel
         if (Auth::user()->hasPermissionTo('song:admin')) {
             return;
         }
-
-        //$builder->whereIn('id', Auth::user()->getOwnedCollections());
-
-//        $cols=backpack_user()->collections;
-//        if(!$cols){
-
-//            $cols=[];
-//        }
-//        $builder->whereIn('id', $cols);
-
-
+        $builder->whereIn('id', Auth::user()->getOwnedCollections());
     }
 
     public function setfields()
index 0ad996e3f0ec45deb2400370c5626ae935af00ff..fa2d433adc3d62408eb63082817353e3601c41d7 100644 (file)
@@ -7,6 +7,8 @@ use Cubist\Backpack\Magic\Fields\Integer;
 use Cubist\Backpack\Magic\Fields\SelectFromModel;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Facades\Auth;
 
 class CollectionList extends CubistMagicAbstractModel
 {
@@ -15,6 +17,17 @@ class CollectionList extends CubistMagicAbstractModel
         'singular' => 'list',
         'plural' => 'lists'];
 
+    public static function addOwnerClause(Builder $builder)
+    {
+        if (backpack_user() === null || Auth::guest()) {
+            return;
+        }
+        if (Auth::user()->hasPermissionTo('song:admin')) {
+            return;
+        }
+        $builder->whereIn('collection', Auth::user()->getOwnedCollections());
+    }
+
     public function setFields()
     {
         parent::setFields();
index 850cf5f9c09836c1e44bbd05aeaef33a7879a268..36049f9666be1dac381392cb5a0999be9460f605 100644 (file)
@@ -7,6 +7,7 @@ use App\Field\Tempo;
 use App\Field\Tone;
 use App\Http\Controllers\Admin\Operations\Song\ImportOperation;
 use App\Jobs\DownloadAudioTracks;
+use App\Jobs\OptimizeMP3;
 use App\SubForm\AudioTrack;
 use App\SubForm\SongPortion;
 use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
@@ -54,8 +55,8 @@ class Song extends CubistMagicAbstractModel
         parent::setFields();
 
         // $this->addField('slug', 'Slug', 'Slug', ['column' => true]);
-        $this->addField('title', 'Text', __('Titre de la chanson'), ['column' => true]);
-        $this->addField('artist', 'Text', __('Artiste'), ['column' => true]);
+        $this->addField('title', 'Text', __('Titre de la chanson'), ['column' => true, 'tab' => __('Paramètres')]);
+        $this->addField('artist', 'Text', __('Artiste'), ['column' => true, 'tab' => __('Paramètres')]);
         $this->addField([
             'name' => 'owner',
             'label' => __('Ajouté par'),
@@ -67,17 +68,22 @@ class Song extends CubistMagicAbstractModel
             'attribute' => 'companyWithName',
             'default' => Auth::id(),
             'non_default_tracking' => false,
+            'tab' => __('Paramètres')
         ]);
-        $this->addField('key', Tone::class, __('Key'), ['column' => true]);
-        $this->addField('mode', Mode::class, __('Mode'), ['column' => true]);
-        $this->addField('chorale', Checkbox::class, __('Chorale'), ['default' => false, 'database_default' => false]);
-        $this->addField('collections', \App\Field\CollectionList::class, 'Collections');
-        $this->addField('tempo', Tempo::class, __('Suggested tempo'), ['column' => true, 'default' => 80]);
-        $this->addField('partition', Files::class, __('Partition'), ['acceptedFiles' => 'application/pdf', 'when' => ['chorale' => 1]]);
-        $this->addField('lyrics_doc', Files::class, __('Paroles'), ['acceptedFiles' => 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain,text/html', 'when' => ['chorale' => 1]]);
-        $this->addField('audio', BunchOfFieldsMultiple::class, __('Audio tracks'), ['bunch' => AudioTrack::class, 'new_label' => 'New audio track']);
-        $this->addField('lyrics', BunchOfFieldsMultiple::class, __('Song Parts'), ['bunch' => SongPortion::class, 'new_label' => 'New song part', 'when' => ['chorale' => 0]]);
-        $this->addField('credits', 'Textarea', __('Credits'));
+
+        $this->addField('collections', \App\Field\CollectionList::class, 'Collections', ['tab' => __('Paramètres')]);
+
+        $this->addField('chorale', Checkbox::class, __('Chorale'), ['default' => false, 'database_default' => false, 'tab' => __('Paramètres')]);
+
+        $this->addField('key', Tone::class, __('Key'), ['column' => true, 'tab' => __('Paroles et accords')]);
+        $this->addField('mode', Mode::class, __('Mode'), ['column' => true, 'tab' => __('Paroles et accords')]);
+        $this->addField('tempo', Tempo::class, __('Suggested tempo'), ['column' => true, 'default' => 80, 'tab' => __('Paroles et accords')]);
+        $this->addField('partition', Files::class, __('Partition'), ['acceptedFiles' => 'application/pdf', 'when' => ['chorale' => 1], 'tab' => __('Paroles et accords')]);
+        $this->addField('lyrics', BunchOfFieldsMultiple::class, __('Song Parts'), ['bunch' => SongPortion::class, 'add_label' => 'Nouvelle partie', 'when' => ['chorale' => 0], 'tab' => __('Paroles et accords')]);
+        $this->addField('lyrics_doc', Files::class, __('Paroles'), ['acceptedFiles' => 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain,text/html', 'when' => ['chorale' => 1], 'tab' => __('Paroles et accords')]);
+        $this->addField('audio', BunchOfFieldsMultiple::class, __('Audio tracks'), ['bunch' => AudioTrack::class, 'add_label' => 'Ajouter un audio', 'tab' => __('Audios')]);
+        $this->addField('credits', 'Textarea', __('Credits'), ['tab' => __('Autres informations')]);
+
     }
 
     public function preSave()
@@ -91,6 +97,7 @@ class Song extends CubistMagicAbstractModel
     public function postSave()
     {
         DownloadAudioTracks::dispatch();
+        OptimizeMP3::dispatch();
 
         parent::postSave();
     }
@@ -236,7 +243,10 @@ class Song extends CubistMagicAbstractModel
             if (!$url) {
                 continue;
             }
-            $res[$i] = ['i' => $i, 'name' => $audio['name'], 'url' => $url, 'path' => $path];
+
+            $opt_path = str_replace('.mp3', '.opt.mp3', $path);
+
+            $res[$i] = ['i' => $i, 'name' => $audio['name'], 'url' => $url, 'path' => $path, 'opturl' => file_exists($opt_path) ? str_replace('.mp3', '.opt.mp3', $url) : $url];
             if (isset($audio['tone'])) {
                 $res[$i]['tone'] = $audio['tone'];
             }
index af6f628c436d2283c67831079186574f78615be0..bd963404434cdfbef3ea4c5b2f1ebd1659177775 100644 (file)
@@ -32,7 +32,7 @@ return [
     // The string below will be passed through the url() helper.
     // - default: '' (project root)
     // - alternative: 'admin' (the admin's dashboard)
-    'home_link' => '',
+    'home_link' => 'admin',
 
     // Content of the HTML meta robots tag to prevent indexing and link following
     'meta_robots_content' => 'noindex, nofollow',
index eec7f34e8f968a753649a38bf0433ebfd1e4f994..93db950aca5b3fc131b5de7f523c81df2b0a2702 100644 (file)
@@ -45,7 +45,7 @@
         <div id="audioplayers">
             @foreach($audioTracks as $audio)
                 <audio id="player_{{$audio['i']}}_0" controls loop>
-                    <source src="{{$audio['url']}}" type="audio/mp3"/>
+                    <source src="{{$audio['opturl']}}" type="audio/mp3"/>
                 </audio>
                 @if($collection->transpose)
                     @for($i=1;$i<=11;$i++)
index 782d0927b9c8ba07e623c64a21bee315c7d0832c..5d18fdb01f49d0143b7b7f3fbe222b4409700acc 100644 (file)
@@ -1,14 +1,2 @@
 @extends(backpack_view('blank'))
-
-@php
-    $widgets['before_content'][] = [
-        'type'        => 'jumbotron',
-        'heading'     => trans('backpack::base.welcome'),
-        'content'     => trans('backpack::base.use_sidebar'),
-        'button_link' => backpack_url('logout'),
-        'button_text' => trans('backpack::base.logout'),
-    ];
-@endphp
-
-@section('content')
-@endsection
\ No newline at end of file
+<script>window.location = "/admin/song";</script>