Skip to content

Commit 190fc55

Browse files
authored
Merge pull request #26 from rbuehlma/genres
Correctly load genres
2 parents a367d03 + 9d2c0d5 commit 190fc55

5 files changed

Lines changed: 47 additions & 8 deletions

File tree

pvr.teleboy/addon.xml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<addon id="pvr.teleboy"
3-
version="18.0.24"
3+
version="18.0.25"
44
name="Teleboy PVR Client"
55
provider-name="rbuehlma">
66
<requires>@ADDON_DEPENDS@</requires>

pvr.teleboy/changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
v18.0.25
2+
- Correctly load genres
13
v18.0.24
24
- Fix loading more than 100 recordings
35
v18.0.23

src/TeleBoy.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,40 @@ void TeleBoy::GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities)
217217
pCapabilities->bSupportsTimers = true;
218218
}
219219

220+
void TeleBoy::LoadGenres()
221+
{
222+
Document json;
223+
if (!ApiGet("/epg/genres", json))
224+
{
225+
XBMC->Log(LOG_ERROR, "Error loading genres.");
226+
return;
227+
}
228+
Value& genres = json["data"]["items"];
229+
for (Value::ConstValueIterator itr1 = genres.Begin();
230+
itr1 != genres.End(); ++itr1)
231+
{
232+
const Value &genre = (*itr1);
233+
TeleboyGenre teleboyGenre;
234+
int id = genre["id"].GetInt();
235+
teleboyGenre.name = GetStringOrEmpty(genre, "name");
236+
genresById[id] = teleboyGenre;
237+
238+
if (genre.HasMember("sub_genres")) {
239+
const Value& subGenres = genre["sub_genres"];
240+
241+
for (Value::ConstValueIterator itr1 = subGenres.Begin();
242+
itr1 != subGenres.End(); ++itr1)
243+
{
244+
const Value &subGenre = (*itr1);
245+
TeleboyGenre teleboySubGenre;
246+
int subId = subGenre["id"].GetInt();
247+
teleboySubGenre.name = GetStringOrEmpty(subGenre, "name");
248+
genresById[subId] = teleboySubGenre;
249+
}
250+
}
251+
}
252+
}
253+
220254
bool TeleBoy::LoadChannels()
221255
{
222256
Document json;
@@ -401,9 +435,11 @@ void TeleBoy::GetEPGForChannelAsync(int uniqueChannelId, time_t iStart,
401435
item.HasMember("serie_episode") ? item["serie_episode"].GetInt() : 0;
402436
tag.iEpisodePartNumber = 0; /* not supported */
403437
tag.strEpisodeName = strdup(GetStringOrEmpty(item, "subtitle").c_str());
404-
; /* not supported */
405-
tag.iGenreType = EPG_GENRE_USE_STRING;
406-
tag.strGenreDescription = strdup(GetStringOrEmpty(item, "type").c_str());
438+
if (item.HasMember("genre_id")) {
439+
tag.iGenreType = EPG_GENRE_USE_STRING;
440+
int genreId = item["genre_id"].GetInt();
441+
tag.strGenreDescription = genresById[genreId].name.c_str();
442+
}
407443
tag.iFlags = EPG_TAG_FLAG_UNDEFINED;
408444

409445
PVR->EpgEventStateChange(&tag, EPG_EVENT_CREATED);

src/TeleBoy.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ struct TeleBoyChannel
2121
std::string logoPath;
2222
};
2323

24-
struct PVRIptvEpgGenre
24+
struct TeleboyGenre
2525
{
26-
int iGenreType;
27-
int iGenreSubType;
28-
std::string strGenre;
26+
std::string name;
2927
};
3028

3129
class TeleBoy
@@ -34,6 +32,7 @@ class TeleBoy
3432
TeleBoy(bool favoritesOnly);
3533
virtual ~TeleBoy();
3634
virtual bool Login(string u, string p);
35+
void LoadGenres();
3736
virtual bool LoadChannels();
3837
virtual void GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities);
3938
virtual int GetChannelsAmount(void);
@@ -59,6 +58,7 @@ class TeleBoy
5958
string userId;
6059
string apiKey;
6160
map<int, TeleBoyChannel> channelsById;
61+
map<int, TeleboyGenre> genresById;
6262
vector<int> sortedChannels;
6363
int64_t maxRecallSeconds;
6464
vector<UpdateThread*> updateThreads;

src/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ ADDON_STATUS ADDON_Create(void *hdl, void *props)
101101
if (teleboy->Login(teleboyUsername, teleboyPassword)) {
102102
XBMC->Log(LOG_DEBUG, "Login done");
103103
teleboy->LoadChannels();
104+
teleboy->LoadGenres();
104105
m_CurStatus = ADDON_STATUS_OK;
105106
} else {
106107
XBMC->Log(LOG_ERROR, "Login failed");

0 commit comments

Comments
 (0)