~aleteoryx/muditaos

ref: 58c8f7b79527f74539f2b57d4d38b9fbf4fa4e4c muditaos/module-db/Tables/MultimediaFilesTable.hpp -rw-r--r-- 3.4 KiB
58c8f7b7 — Maciej Gibowicz [BH-1756] Fix "turn off" window display time 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Record.hpp"
#include "Table.hpp"
#include <Database/Database.hpp>

#include <string>

namespace db::multimedia_files
{
    using Artist = std::string;
    struct Album
    {
        Artist artist{};
        std::string title{};
    };

    struct Tags
    {
        std::string title{};
        Album album{};
        std::string comment{};
        std::string genre{};
        std::uint32_t year{};
        std::uint32_t track{};
    };

    struct AudioProperties
    {
        std::uint32_t songLength{}; /// in seconds
        std::uint32_t bitrate{};    /// in kb/s
        std::uint32_t sampleRate{}; /// in Hz
        std::uint32_t channels{};   /// 1 - mono, 2 - stereo
    };

    struct FileInfo
    {
        std::string path{};
        std::string mediaType{}; /// mime type e.g. "audio/mp3"
        std::size_t size{};      /// in bytes
    };

    struct TableRow : public Record
    {
        FileInfo fileInfo{};
        Tags tags{};
        AudioProperties audioProperties{};

        auto isValid() const -> bool;
    };

    enum class TableFields
    {
        path,
        media_type,
        size,
        title,
        artist,
        album,
        comment,
        genre,
        year,
        track,
        song_length,
        bitrate,
        sample_rate,
        channels
    };

    class MultimediaFilesTable : public Table<TableRow, TableFields>
    {
      public:
        explicit MultimediaFilesTable(Database *db);
        virtual ~MultimediaFilesTable() = default;

        auto create() -> bool override;
        auto add(TableRow entry) -> bool override;
        auto removeById(uint32_t id) -> bool override;
        auto removeByField(TableFields field, const char *str) -> bool override;
        bool removeAll() override final;
        auto update(TableRow entry) -> bool override;
        auto getById(uint32_t id) -> TableRow override;
        auto getLimitOffset(uint32_t offset, uint32_t limit) -> std::vector<TableRow> override;
        auto getLimitOffsetByField(uint32_t offset, uint32_t limit, TableFields field, const char *str)
            -> std::vector<TableRow> override;
        auto count() -> uint32_t override;
        auto countByFieldId(const char *field, uint32_t id) -> uint32_t override;

        auto getArtistsLimitOffset(uint32_t offset, uint32_t limit) -> std::vector<Artist>;
        auto countArtists() -> uint32_t;

        auto getAlbumsLimitOffset(uint32_t offset, uint32_t limit) -> std::vector<Album>;
        auto countAlbums() -> uint32_t;

        auto getLimitOffset(const Artist &artist, uint32_t offset, uint32_t limit) -> std::vector<TableRow>;
        auto count(const Artist &artist) -> uint32_t;

        auto getLimitOffset(const Album &album, uint32_t offset, uint32_t limit) -> std::vector<TableRow>;
        auto count(const Album &album) -> uint32_t;

        auto getLimitOffsetByPaths(const std::vector<std::string> &paths, uint32_t offset, uint32_t limit)
            -> std::vector<TableRow>;
        auto count(const std::vector<std::string> &paths) -> uint32_t;
        TableRow getByPath(std::string path);

        /// @note entry.ID is skipped
        bool addOrUpdate(TableRow entry, std::string oldPath = "");

      private:
        auto getFieldName(TableFields field) -> std::string;
    };
} // namespace db::multimedia_files