gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
73.78k stars 7.4k forks source link

Extracting metadata from audio resources #10151

Open jsilland opened 1 year ago

jsilland commented 1 year ago

I would like to extend Hugo's resource handling to add first-class support for audio files (mp3 / aac / flac), including the ability to extract text metadata (artist / album / etc…) as well as cover art. Hugo currently special-cases image resources and provides APIs to operate on the content of an image and to extract EXIF data; I would like to add an equivalent resource type to similarly allow extracting metadata from audio files.

My primary use case is to embed audio content on my website without having to duplicate the files' existing metadata in the declaration of a page resource — this would greatly reduce the toil associated with publishing new audio content over time. I don't foresee a need to manipulate or access the audio content itself, just the metadata which is accessible as part of those file formats.

I am happy to put work into making this happen — I am comfortable writing Go and there are existing native libraries to perform the tag parsing, e.g. https://github.com/dhowden/tag. I have seen the recent addition to the contribution guide mentioning not wanting to accept patches for additional features; I'd be happy to trade one or few bugfixes in order to land this one. Either way, please let me know if this seems like a reasonable addition to Hugo, either now or in the future.

jsilland commented 1 year ago

FYI I now have a working prototype of this at https://github.com/gohugoio/hugo/commit/9513ea2129cbffb9d198e664f1db938b41d26b09 — it's very early but it seems to work okay, and includes support for turning cover art into proper Hugo image resources. The following template gets rendered as expected:

<ul>
  {{ $audioResources := $.Page.Resources.ByType "audio" }} 
  {{ range $index, $audioFile := $audioResources }}
    <li>
      {{ with $audioFile.AudioTags }}
        <a href="{{ $audioFile.RelPermalink }}">
          {{ .Artist }}
          {{ with .Art }}
            <img src="{{ .RelPermalink }}" />
          {{ end }}
        </a>
      {{ end }}
    </li>
  {{ end }}
</ul>

My next step is to clean up the code and write tests — this is not ready for review at this time but I wanted to share the progress

rthinkel commented 1 year ago

This is awesome, has there been any further progress with it? I'd love to be able to implement this feature on my site. Thank you for your work!

github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.