forked from vdr-projects/vdr-plugin-tvscraper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimages.c
164 lines (149 loc) · 5.23 KB
/
images.c
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "images.h"
// cImageLevelsInt *********************
cImageLevelsInt::cImageLevelsInt():
m_pop(0),
m_push(0)
{
m_imageLevels = 0;
}
cImageLevelsInt::cImageLevelsInt(cImageLevels parent):
m_pop(0),
m_push(-1)
{
m_imageLevels = parent.m_imageLevels;
}
cImageLevelsInt::cImageLevelsInt(eImageLevel first, eImageLevel second, eImageLevel third, eImageLevel forth):
m_pop(0),
m_push(0)
{
if (first != eImageLevel::none) push(first);
if (second != eImageLevel::none) push(second);
if (third != eImageLevel::none) push(third );
if (forth != eImageLevel::none) push(forth );
}
void cImageLevelsInt::findTopElement() {
int t = m_imageLevels;
for (m_push = 0; m_push < s_max_levels; m_push++) {
if ((t & 7) == 0) return;
t = t >> 3;
}
}
void cImageLevelsInt::push(eImageLevel lv) {
if (m_push < 0) findTopElement();
m_imageLevels |= ((int)lv) << (m_push * 3);
m_push++;
}
eImageLevel cImageLevelsInt::popFirst() {
m_pop = 0;
return pop();
}
eImageLevel cImageLevelsInt::pop() {
return (eImageLevel)((m_imageLevels >> (m_pop++ * 3)) & 7);
}
bool cImageLevelsInt::inList(eImageLevel lv, bool (*equal)(eImageLevel lv1, eImageLevel lv2)) {
// return true if lv is in this list (or level equal to lv)
for (eImageLevel lvInList = popFirst(); lvInList != eImageLevel::none; lvInList = pop() )
if (equal(lvInList, lv) ) return true;
return false;
}
cImageLevelsInt cImageLevelsInt::removeDuplicates(bool (*equal)(eImageLevel lv1, eImageLevel lv2)){
// out: list of levels, remove duplicate
cImageLevelsInt lv_out;
for (eImageLevel lv_to_add = popFirst(); lv_to_add != eImageLevel::none; lv_to_add = pop() ) {
// add this level to the list, if it was not found (not already in list)
if (!lv_out.inList(lv_to_add, equal)) lv_out.push(lv_to_add);
}
return lv_out;
}
bool cImageLevelsInt::equalTvShows(eImageLevel lv1, eImageLevel lv2) {
return lv1 == lv2;
}
bool cImageLevelsInt::equalMovies(eImageLevel level1, eImageLevel level2) {
if (level1 == level2) return true;
switch (level1) {
case eImageLevel::episodeMovie: return level2 == eImageLevel::seasonMovie;
case eImageLevel::seasonMovie: return level2 == eImageLevel::episodeMovie;
case eImageLevel::tvShowCollection: return level2 == eImageLevel::anySeasonCollection;
case eImageLevel::anySeasonCollection: return level2 == eImageLevel::tvShowCollection;
default: return false;
}
}
// cOrientationsInt *********************
cOrientationsInt::cOrientationsInt():
m_pop(0),
m_push(0)
{
m_orientations = 0;
}
cOrientationsInt::cOrientationsInt(cOrientations parent):
m_pop(0),
m_push(-1)
{
m_orientations = parent.m_orientations;
}
cOrientationsInt::cOrientationsInt(eOrientation first, eOrientation second, eOrientation third):
m_pop(0),
m_push(0)
{
if (first != eOrientation::none) push(first);
if (second != eOrientation::none) push(second);
if (third != eOrientation::none) push(third );
}
void cOrientationsInt::findTopElement() {
int t = m_orientations;
for (m_push = 0; m_push < s_max_orientations; m_push++) {
if ((t & 7) == 0) return;
t = t >> 3;
}
}
void cOrientationsInt::push(eOrientation o) {
if (m_push < 0) findTopElement();
m_orientations |= ((int)o) << (m_push * 3);
m_push++;
}
eOrientation cOrientationsInt::popFirst() {
m_pop = 0;
return pop();
}
eOrientation cOrientationsInt::pop() {
return (eOrientation)((m_orientations >> (m_pop++ * 3)) & 7);
}
std::string getRecordingImagePath(const cRecording *recording) {
if (!recording || !recording->Info()) return "";
const cEvent *event = recording->Info()->GetEvent();
if (!event) return "";
return std::string(cToSvConcat(config.GetBaseDirRecordings(), event->StartTime(), "_", recording->Info()->ChannelID(), "_", event->EventID(), ".jpg"));
}
inline std::string getExistingEpgImagePath(tEventID eventID, time_t eventStartTime, const tChannelID &channelID) {
return std::string(cToSvConcat(config.GetBaseDirEpg(), eventStartTime, "/", channelID, "/", eventID, ".jpg"));
}
template<class T>
std::string getEpgImagePath(const T *event, bool createPaths) {
if (!event) return "";
if (!createPaths) return getExistingEpgImagePath(event->EventID(), event->StartTime(), event->ChannelID() );
std::string path;
path.reserve(200);
stringAppend(path, config.GetBaseDirEpg(), event->StartTime());
CreateDirectory(path);
stringAppend(path, "/", event->ChannelID());
CreateDirectory(path);
stringAppend(path, "/", event->EventID(), ".jpg");
return path;
}
template std::string getEpgImagePath<cEvent>(const cEvent *event, bool createPaths);
template std::string getEpgImagePath<cStaticEvent>(const cStaticEvent *event, bool createPaths);
extern "C" std::string getCreateEpgImagePath(const cEvent *event) {
return getEpgImagePath(event, true);
}
cTvMedia getEpgImage(const cEvent *event, const cRecording *recording, bool fullPath) {
cTvMedia result;
if (!event && !recording) return result;
if (event && recording) return result;
result.path = event?getEpgImagePath(event, false):getRecordingImagePath(recording);
if (FileExistsImg(result.path)) {
if (!fullPath) result.path.erase(0, config.GetBaseDirLen());
result.width = 952;
result.height = 714;
} else result.path = "";
return result;
}