Skip to content

Commit

Permalink
media/playlist custom metadata support (playlist loading broken?), db…
Browse files Browse the repository at this point in the history
… query fix
  • Loading branch information
hinanaya committed Jul 2, 2024
1 parent 60eeb04 commit 317c195
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
16 changes: 16 additions & 0 deletions html/media/addedit_metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@
<button class="copy_to_all" data-field="metadata_name_field" onclick="OB.Media.copyField(this);" title="Copy To All"><i class="far fa-copy"></i></button>
</div>
</div>

<div id="media_metadata_template_media" class="hidden">
<div class="fieldrow">
<label></label>
<ob-field-media data-edit data-single data-record class="metadata_name_field"></ob-field-media>
<button class="copy_to_all" data-field="metadata_name_field" onclick="OB.Media.copyField(this);" title="Copy To All"><i class="far fa-copy"></i></button>
</div>
</div>

<div id="media_metadata_template_playlist" class="hidden">
<div class="fieldrow">
<label></label>
<ob-field-playlist data-edit data-single class="metadata_name_field"></ob-field-playlist>
<button class="copy_to_all" data-field="metadata_name_field" onclick="OB.Media.copyField(this);" title="Copy To All"><i class="far fa-copy"></i></button>
</div>
</div>
4 changes: 4 additions & 0 deletions html/media/metadata_addedit.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<ob-option value="bool">Yes/No</ob-option>
<ob-option value="select">Drop-Down Selection</ob-option>
<ob-option value="tags">Tags</ob-option>
<ob-option value="media">Media</ob-option>
<ob-option value="playlist">Playlist</ob-option>
</ob-field-select>
</div>

Expand Down Expand Up @@ -64,6 +66,8 @@
></ob-field-select>
<ob-field-select data-edit class="hidden metadata_default metadata_default_select"></ob-field-select>
<ob-tag-input data-suggestions="false" class="hidden metadata_default metadata_default_tags"></ob-tag-input>
<ob-field-media data-edit data-single class="hidden metadata_default metadata_default_media"></ob-field-media>
<ob-field-playlist data-edit data-single class="hidden metadata_default metadata_default_playlist"></ob-field-playlist>
</div>

<div class="fieldrow">
Expand Down
9 changes: 8 additions & 1 deletion js/media/addedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,14 @@ OB.Media.save = function()

$.each(OB.Settings.media_metadata, function(index,metadata)
{
item['metadata_'+metadata.name] = $(element).find('.metadata_'+metadata.name+'_field').val();
let metaItem = $(element).find('.metadata_'+metadata.name+'_field').val();

// media and playlist metadata fields return arrays, but will be a single item, so convert:
if (Array.isArray(metaItem) && (metadata.type == 'media' || metadata.type == 'playlist')) {
metaItem = metaItem[0];
}

item['metadata_'+metadata.name] = metaItem;
});

// add permissions if fields visible
Expand Down
9 changes: 8 additions & 1 deletion js/media/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,14 @@ OB.Media.recordingDefaultsGet = function () {
case "bool":
metaElem = document.createElement('ob-field-bool');
break;
case "media":
metaElem = document.createElement('ob-field-media');
metaElem.dataset.single = "";
break;
case "playlist":
metaElem = document.createElement('ob-field-playlist');
metaElem.dataset.single = "";
break;
}

if (! metaElem) {
Expand Down Expand Up @@ -695,7 +703,6 @@ OB.Media.recordingDefaultsGet = function () {
// Set custom metadata according to saved settings, and if none can be found, use the default
// settings for that field (if any).
OB.Settings.media_metadata.forEach((meta) => {
console.log(meta);
const metaFieldElem = document.querySelector('#recording_custom_metadata [data-name="' + meta.name + '"]');

if (defaults.custom_metadata && meta.name in defaults.custom_metadata) {
Expand Down
15 changes: 13 additions & 2 deletions models/mediametadata_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function validate($data, $id)
}

//T The field type is not valid.
if (array_search($data['type'], ['select','bool','text','textarea','integer','date','time','datetime','tags','hidden']) === false) {
if (array_search($data['type'], ['select','bool','text','textarea','integer','date','time','datetime','tags','hidden','media','playlist']) === false) {
return [false,'The field type is not valid.'];
}

Expand Down Expand Up @@ -248,6 +248,12 @@ public function save($data, $id)
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD ' . $this->db->format_backticks('metadata_' . $data['name']) . ' TIME NULL DEFAULT NULL');
} elseif ($save['type'] === 'datetime') {
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD ' . $this->db->format_backticks('metadata_' . $data['name']) . ' DATETIME NULL DEFAULT NULL');
} elseif ($save['type'] === 'media') {
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD ' . $this->db->format_backticks('metadata_' . $data['name']) . ' INT UNSIGNED NULL DEFAULT NULL');
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD CONSTRAINT ' . $this->db->format_backticks('fk_media_metadata_' . $data['name']) . ' FOREIGN KEY (' . $this->db->format_backticks('metadata_' . $data['name']) . ') REFERENCES ' . $this->db->format_backticks('media') . ' (' . $this->db->format_backticks('id') . ') ON UPDATE CASCADE ON DELETE SET NULL');
} elseif ($save['type'] === 'playlist') {
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD ' . $this->db->format_backticks('metadata_' . $data['name']) . ' INT UNSIGNED NULL DEFAULT NULL');
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD CONSTRAINT ' . $this->db->format_backticks('fk_media_metadata_' . $data['name']) . ' FOREIGN KEY (' . $this->db->format_backticks('metadata_' . $data['name']) . ') REFERENCES ' . $this->db->format_backticks('playlists') . ' (' . $this->db->format_backticks('id') . ') ON UPDATE CASCADE ON DELETE SET NULL');
}

return $id;
Expand All @@ -270,7 +276,12 @@ public function delete($id)

$this->db->where('id', $id);
$this->db->delete('media_metadata');
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' DROP COLUMN metadata_' . $this->db->format_backticks($field['name']));

if ($field['type'] === 'media' || $field['type'] === 'playlist') {
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' DROP FOREIGN KEY ' . $this->db->format_backticks('fk_media_metadata_' . $field['name']));
}

$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' DROP COLUMN ' . $this->db->format_backticks('metadata_' . $field['name']));

return true;
}
Expand Down

0 comments on commit 317c195

Please sign in to comment.