2
* This file is part of the Ubuntu TV Media Scanner
3
* Copyright (C) 2012-2013 Canonical Ltd.
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU Lesser General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Contact: Jim Hodapp <jim.hodapp@canonical.com>
18
* Authored by: Mathias Hasselmann <mathias@openismus.com>
20
#ifndef MEDIASCANNER_MEDIAUTILS_H
21
#define MEDIASCANNER_MEDIAUTILS_H
23
// C++ Standard Library
27
// Media Scanner Library
28
#include "mediascanner/property.h"
30
typedef struct _GList GList;
31
typedef struct _GrlMedia GrlMedia;
33
namespace mediascanner {
37
static const MimeType kApplicationOgg;
38
static const MimeType kAudioPrefix;
39
static const MimeType kImagePrefix;
40
static const MimeType kVideoPrefix;
42
explicit MimeType(const std::string &str)
43
: str_(str.begin(), str.end()) {
46
explicit MimeType(const std::wstring &str)
50
const std::wstring& str() const {
54
bool is_audio() const;
55
bool is_image() const;
56
bool is_video() const;
58
GrlMedia* make_media() const;
66
typedef std::vector<Property::ValueMap> PropertyVector;
69
typedef PropertyVector::const_iterator const_iterator;
70
typedef PropertyVector::value_type value_type;
74
void add_related(const Property::ValueMap &properties);
75
void add_single(const Property::BoundValue &value);
77
Property::Value first(Property key) const;
78
size_t count(Property key) const;
80
template<typename PropertyType, typename ValueType>
81
ValueType first(const GenericProperty<PropertyType, ValueType> &key) const;
83
std::wstring first(StringProperty key) const {
84
return first<StringProperty, std::wstring>(key);
87
std::wstring first(TextProperty key) const {
88
return first<TextProperty, std::wstring>(key);
92
GrlMedia* make_media(GList *const requested_keys) const;
93
GrlMedia* make_media(GList *const requested_keys,
94
const std::string &url) const;
96
void copy_to_media(GList *const requested_keys,
97
GrlMedia *const media) const;
98
bool fill_from_media(GrlMedia *media, const GList *const requested_keys,
99
GList **failed_keys, std::string *error_message);
101
const_iterator begin() const {
102
return related_properties_.begin();
105
const_iterator end() const {
106
return related_properties_.end();
111
bool operator==(const MediaInfo &other) const {
112
return related_properties_ == other.related_properties_;
115
bool operator!=(const MediaInfo &other) const {
116
return not operator==(other);
120
std::vector<Property::ValueMap> related_properties_;
123
template<typename P, typename V>
124
inline V MediaInfo::first(const GenericProperty<P, V> &key) const {
125
const Property::Value value = first(static_cast<Property>(key));
126
return value.which() ? boost::get<V>(value) : V();
129
} // namespace mediascanner
131
#endif // MEDIASCANNER_MEDIAUTILS_H