FileMetaAudio.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Setting\ComponentFactory\Media; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\FormatterCollection; |
| 9 | use AC\Setting\ComponentFactory\BaseComponentFactory; |
| 10 | use AC\Setting\Config; |
| 11 | use AC\Setting\Control\Input; |
| 12 | use AC\Setting\Control\Input\OptionFactory; |
| 13 | use AC\Setting\Control\OptionCollection; |
| 14 | |
| 15 | final class FileMetaAudio extends BaseComponentFactory |
| 16 | { |
| 17 | protected function get_label(Config $config): ?string |
| 18 | { |
| 19 | return __('Audio Meta'); |
| 20 | } |
| 21 | |
| 22 | protected function get_input(Config $config): ?Input |
| 23 | { |
| 24 | $options = $this->get_meta_options(); |
| 25 | $option = $options->first(); |
| 26 | |
| 27 | return OptionFactory::create_select( |
| 28 | 'media_meta_key', |
| 29 | $options, |
| 30 | $config->get('media_meta_key', $option ? $option->get_value() : '') |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | protected function get_meta_options(): OptionCollection |
| 35 | { |
| 36 | $types = [ |
| 37 | 'bitrate' => __('Bitrate', 'codepress-admin-columns'), |
| 38 | 'bitrate_mode' => __('Bitrate Mode', 'codepress-admin-columns'), |
| 39 | 'channelmode' => __('Channelmode', 'codepress-admin-columns'), |
| 40 | 'channels' => __('Channels', 'codepress-admin-columns'), |
| 41 | 'compression_ratio' => __('Compression Ratio', 'codepress-admin-columns'), |
| 42 | 'created_timestamp' => __('Created Timestamp', 'codepress-admin-columns'), |
| 43 | 'dataformat' => __('Data Format', 'codepress-admin-columns'), |
| 44 | 'encoder_options' => __('Encoder Options', 'codepress-admin-columns'), |
| 45 | 'fileformat' => __('Fileformat', 'codepress-admin-columns'), |
| 46 | 'filesize' => __('Filesize', 'codepress-admin-columns'), |
| 47 | 'length' => __('Length', 'codepress-admin-columns'), |
| 48 | 'length_formatted' => __('Length Formatted', 'codepress-admin-columns'), |
| 49 | 'lossless' => __('Losless', 'codepress-admin-columns'), |
| 50 | 'mime_type' => __('Mime Type', 'codepress-admin-columns'), |
| 51 | 'sample_rate' => __('Sample Rate', 'codepress-admin-columns'), |
| 52 | ]; |
| 53 | |
| 54 | natcasesort($types); |
| 55 | |
| 56 | return OptionCollection::from_array($types); |
| 57 | } |
| 58 | |
| 59 | protected function add_formatters(Config $config, FormatterCollection $formatters): void |
| 60 | { |
| 61 | switch ($config->get('media_meta_key', '')) { |
| 62 | case 'bitrate': |
| 63 | $formatters->add(new AC\Formatter\Media\Audio\Bitrate()); |
| 64 | break; |
| 65 | case 'channels': |
| 66 | $formatters->add(new AC\Formatter\Media\Audio\Channels()); |
| 67 | break; |
| 68 | |
| 69 | case 'compression_ratio': |
| 70 | $formatters->add(new AC\Formatter\Media\NumberFormat(4)); |
| 71 | break; |
| 72 | case 'created_timestamp': |
| 73 | $formatters->add( |
| 74 | new AC\Formatter\Date\LocalizedDateFormat( |
| 75 | AC\Helper\WpDateFormat::date_time(), |
| 76 | 'U' |
| 77 | ) |
| 78 | ); |
| 79 | break; |
| 80 | case 'filesize': |
| 81 | $formatters->add(new AC\Formatter\FileSizeReadable()); |
| 82 | break; |
| 83 | |
| 84 | case 'length': |
| 85 | $formatters->add(new AC\Formatter\Media\NumberFormat(0, '', ' sec')); |
| 86 | break; |
| 87 | case 'sample_rate': |
| 88 | $formatters->add(new AC\Formatter\Media\NumberFormat(0, '', ' Hz')); |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | } |
| 94 |