MythTV master
videoutils.cpp
Go to the documentation of this file.
1
2#include "videoutils.h"
3
4#include <QtGlobal>
5#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
6#include <QtSystemDetection>
7#endif
8#include <QDir>
9#include <QCoreApplication>
10
11// mythtv
21
22// libmythmetadata
23#include "globals.h"
25
26namespace
27{
29 QCoreApplication::translate("(VideoUtils)", "None", "No cover");
31 QCoreApplication::translate("(VideoUtils)", "No Cover");
32
33 template <typename T>
34 void CopySecond(const T &src, QStringList &dest)
35 {
36 for (auto p = src.cbegin(); p != src.cend(); ++p)
37 {
38 dest.push_back((*p).second);
39 }
40 }
41}
42
43template <>
44void CheckedSet(MythUIStateType *uiItem, const QString &value)
45{
46 if (uiItem)
47 {
48 uiItem->Reset();
49 uiItem->DisplayState(value);
50 }
51}
52
53void CheckedSet(MythUIType *container, const QString &itemName,
54 const QString &value)
55{
56 if (container)
57 {
58 MythUIType *uit = container->GetChild(itemName);
59 auto *tt = dynamic_cast<MythUIText *>(uit);
60 if (tt)
61 {
62 CheckedSet(tt, value);
63 }
64 else
65 {
66 auto *st = dynamic_cast<MythUIStateType *>(uit);
67 CheckedSet(st, value);
68 }
69 }
70}
71
72void CheckedSet(MythUIImage *uiItem, const QString &filename)
73{
74 if (uiItem)
75 {
76 uiItem->Reset();
77 uiItem->SetFilename(filename);
78 uiItem->Load();
79 }
80}
81
82QStringList GetVideoDirsByHost(const QString& host)
83{
84 QStringList tmp;
85
86 QStringList tmp2 = StorageGroup::getGroupDirs("Videos", host);
87 tmp.reserve(tmp2.size());
88 for (const auto& dir : std::as_const(tmp2))
89 tmp.append(dir);
90
91 if (host.isEmpty())
92 {
93#ifdef Q_OS_WINDOWS
94 QString seperator = ";";
95#else
96 QString seperator = ":";
97#endif
98 QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
99 DEFAULT_VIDEOSTARTUP_DIR).split(seperator, Qt::SkipEmptyParts);
100 tmp.reserve(tmp.size() + tmp3.size());
101 for (const auto& dir : std::as_const(tmp3))
102 {
103 bool matches = false;
104 QString newpath = dir;
105 if (!newpath.endsWith("/"))
106 newpath.append("/");
107
108 for (const auto& comp : std::as_const(tmp2))
109 {
110 if (comp.endsWith(newpath))
111 {
112 matches = true;
113 break;
114 }
115 }
116 if (!matches)
117 tmp.append(QDir::cleanPath(dir));
118 }
119 }
120
121 return tmp;
122}
123
124QStringList GetVideoDirs()
125{
126 return GetVideoDirsByHost("");
127}
128
129bool IsDefaultCoverFile(const QString &coverfile)
130{
131 return coverfile == VIDEO_COVERFILE_DEFAULT ||
132 coverfile == VIDEO_COVERFILE_DEFAULT_OLD ||
133 coverfile == VIDEO_COVERFILE_DEFAULT_OLD2 ||
134 coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD) ||
135 coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD2);
136}
137
138bool IsDefaultScreenshot(const QString &screenshot)
139{
140 return screenshot == VIDEO_SCREENSHOT_DEFAULT;
141}
142
143bool IsDefaultBanner(const QString &banner)
144{
145 return banner == VIDEO_BANNER_DEFAULT;
146}
147
148bool IsDefaultFanart(const QString &fanart)
149{
150 return fanart == VIDEO_FANART_DEFAULT;
151}
152
153QString GetDisplayUserRating(float userrating)
154{
155 return QString::number(userrating, 'f', 1);
156}
157
158QString GetDisplayLength(std::chrono::minutes length)
159{
160 // The disambiguation string must be an empty string and not a
161 // nullptr to get extracted by the Qt tools.
162 return QCoreApplication::translate("(Common)", "%n minute(s)", "",
163 length.count());
164}
165
166QString GetDisplayBrowse(bool browse)
167{
168 QString ret;
169
170 if (browse)
171 ret = QCoreApplication::translate("(Common)", "Yes");
172 else
173 ret = QCoreApplication::translate("(Common)", "No");
174
175 return ret;
176}
177
178QString GetDisplayWatched(bool watched)
179{
180 QString ret;
181
182 if (watched)
183 ret = QCoreApplication::translate("(Common)", "Yes");
184 else
185 ret = QCoreApplication::translate("(Common)", "No");
186
187 return ret;
188}
189
190QString GetDisplayProcessed(bool processed)
191{
192 QString ret;
193
194 if (processed)
195 {
196 ret = QCoreApplication::translate("(VideoUtils)",
197 "Details Downloaded");
198 }
199 else
200 {
201 ret = QCoreApplication::translate("(VideoUtils)",
202 "Waiting for Detail Download");
203 }
204
205 return ret;
206}
207
208QString GetDisplayYear(int year)
209{
210 return year == VIDEO_YEAR_DEFAULT ? "?" : QString::number(year);
211}
212
213QString GetDisplayRating(const QString &rating)
214{
215 if (rating == "<NULL>")
216 return QCoreApplication::translate("(VideoUtils)", "No rating available.");
217 return rating;
218}
219
220QString GetDisplayGenres(const VideoMetadata &item)
221{
222 QStringList ret;
223 CopySecond(item.GetGenres(), ret);
224 return ret.join(", ");
225}
226
228{
229 QStringList ret;
230 CopySecond(item.GetCountries(), ret);
231 return ret.join(", ");
232}
233
234QStringList GetDisplayCast(const VideoMetadata &item)
235{
236 QStringList ret;
237 CopySecond(item.GetCast(), ret);
238 return ret;
239}
240
242{
243 QString ret;
244 switch (level.GetLevel())
245 {
247 ret = "Lowest";
248 break;
250 ret = "Low";
251 break;
253 ret = "Medium";
254 break;
256 ret = "High";
257 break;
258 default:
259 ret = "None";
260 }
261
262 return ret;
263}
264
265QString TrailerToState(const QString &trailerFile)
266{
267 QString ret;
268 if (!trailerFile.isEmpty())
269 ret = "hasTrailer";
270 else
271 ret = "None";
272 return ret;
273}
274
275QString WatchedToState(bool watched)
276{
277 QString ret;
278 if (watched)
279 ret = "yes";
280 else
281 ret = "no";
282 return ret;
283}
284
286{
288
289 if (type == "MOVIE")
290 ret = kContentMovie;
291 else if (type == "TELEVISION")
292 ret = kContentTelevision;
293 else if (type == "ADULT")
294 ret = kContentAdult;
295 else if (type == "MUSICVIDEO")
296 ret = kContentMusicVideo;
297 else if (type == "HOMEVIDEO")
298 ret = kContentHomeMovie;
299
300 return ret;
301}
302
304{
305 QString ret = "UNKNOWN";
306
307 if (type == kContentMovie)
308 ret = "MOVIE";
309 else if (type == kContentTelevision)
310 ret = "TELEVISION";
311 else if (type == kContentAdult)
312 ret = "ADULT";
313 else if (type == kContentMusicVideo)
314 ret = "MUSICVIDEO";
315 else if (type == kContentHomeMovie)
316 ret = "HOMEVIDEO";
317
318 return ret;
319}
320
QString GetSetting(const QString &key, const QString &defaultval="")
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:99
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
void Reset(void) override
Reset the image back to the default defined in the theme.
This widget is used for grouping other widgets for display when a particular named state is called.
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
bool DisplayState(const QString &name)
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
The base class on which all widgets and screens are based.
Definition: mythuitype.h:97
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
Level GetLevel() const
static QStringList getGroupDirs(const QString &groupname, const QString &host)
const country_list & GetCountries() const
const cast_list & GetCast() const
const genre_list & GetGenres() const
const QString VIDEO_BANNER_DEFAULT
Definition: globals.cpp:28
const QString VIDEO_SCREENSHOT_DEFAULT
Definition: globals.cpp:27
const QString VIDEO_FANART_DEFAULT
Definition: globals.cpp:29
const QString DEFAULT_VIDEOSTARTUP_DIR
Definition: globals.cpp:47
const QString VIDEO_COVERFILE_DEFAULT
Definition: globals.cpp:25
VideoContentType
@ kContentMusicVideo
@ kContentTelevision
@ kContentAdult
@ kContentUnknown
@ kContentHomeMovie
@ kContentMovie
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void CopySecond(const T &src, QStringList &dest)
Definition: videoutils.cpp:34
def rating(profile, smoonURL, gate)
Definition: scan.py:36
static constexpr uint16_t VIDEO_YEAR_DEFAULT
Definition: videometadata.h:18
bool IsDefaultScreenshot(const QString &screenshot)
Definition: videoutils.cpp:138
QString ParentalLevelToState(const ParentalLevel &level)
Definition: videoutils.cpp:241
bool IsDefaultFanart(const QString &fanart)
Definition: videoutils.cpp:148
QString GetDisplayUserRating(float userrating)
Definition: videoutils.cpp:153
QString WatchedToState(bool watched)
Definition: videoutils.cpp:275
QStringList GetVideoDirsByHost(const QString &host)
Definition: videoutils.cpp:82
QString GetDisplayProcessed(bool processed)
Definition: videoutils.cpp:190
QString TrailerToState(const QString &trailerFile)
Definition: videoutils.cpp:265
QString GetDisplayRating(const QString &rating)
Definition: videoutils.cpp:213
QString GetDisplayWatched(bool watched)
Definition: videoutils.cpp:178
VideoContentType ContentTypeFromString(const QString &type)
Definition: videoutils.cpp:285
QString ContentTypeToString(VideoContentType type)
Definition: videoutils.cpp:303
void CheckedSet(MythUIStateType *uiItem, const QString &value)
Definition: videoutils.cpp:44
bool IsDefaultCoverFile(const QString &coverfile)
Definition: videoutils.cpp:129
QString GetDisplayCountries(const VideoMetadata &item)
Definition: videoutils.cpp:227
QStringList GetDisplayCast(const VideoMetadata &item)
Definition: videoutils.cpp:234
QString GetDisplayLength(std::chrono::minutes length)
Definition: videoutils.cpp:158
QString GetDisplayYear(int year)
Definition: videoutils.cpp:208
QString GetDisplayGenres(const VideoMetadata &item)
Definition: videoutils.cpp:220
bool IsDefaultBanner(const QString &banner)
Definition: videoutils.cpp:143
QString GetDisplayBrowse(bool browse)
Definition: videoutils.cpp:166
QStringList GetVideoDirs()
Definition: videoutils.cpp:124