Metadata.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashMap.h>
  8. #include <AK/LexicalPath.h>
  9. #include <AK/Optional.h>
  10. #include <AK/String.h>
  11. #include <AK/Time.h>
  12. #include <AK/Variant.h>
  13. namespace Audio {
  14. struct Person {
  15. enum class Role {
  16. Artist,
  17. Performer,
  18. Lyricist,
  19. Conductor,
  20. Publisher,
  21. Engineer,
  22. Composer,
  23. };
  24. Role role;
  25. String name;
  26. // Whether this person has creative involvement with the song (so not only Role::Artist!).
  27. // This list is subjective and is intended to keep the artist display text in applications relevant.
  28. // It is used for first_artist and all_artists in Metadata.
  29. bool is_artist() const;
  30. Optional<StringView> name_for_role() const;
  31. };
  32. // Audio metadata of the original format must be equivalently reconstructible from this struct.
  33. // That means, (if the format allows it) fields can appear in a different order, but all fields must be present with the original values,
  34. // including duplicate fields where allowed by the format.
  35. struct Metadata {
  36. using Year = unsigned;
  37. void replace_encoder_with_serenity();
  38. ErrorOr<void> add_miscellaneous(String const& field, String value);
  39. ErrorOr<void> add_person(Person::Role role, String name);
  40. Optional<String> first_artist() const;
  41. ErrorOr<Optional<String>> all_artists(StringView concatenate_with = ", "sv) const;
  42. Optional<String> title;
  43. Optional<String> subtitle;
  44. Optional<unsigned> track_number;
  45. Optional<String> album;
  46. Optional<String> genre;
  47. Optional<String> comment;
  48. Optional<String> isrc;
  49. Optional<String> encoder;
  50. Optional<String> copyright;
  51. Optional<float> bpm;
  52. // FIXME: Until the time data structure situation is solved in a good way, we don't parse ISO 8601 time specifications.
  53. Optional<String> unparsed_time;
  54. Vector<Person> people;
  55. // Any other metadata, using the format-specific field names. This ensures reproducibility.
  56. HashMap<String, Vector<String>> miscellaneous;
  57. };
  58. }