Debian Codegraph @

src/channels.cpp

raw
1 /*
2 * Copyright (C) 2005-2021 Team Kodi (https://kodi.tv)
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 * See LICENSE.md for more information.
6 */
7
8 #include <vector>
9 #include "channels.h"
10 #include "utils.h"
11 #include <stdlib.h>
12 #include <string.h>
13
14 cChannel::cChannel()
15 {
16 uid = 0;
17 external_id = 0;
18 iswebstream = false;
19 encrypted = false;
20 visibleinguide = true;
21 majorChannelNr = -1;
22 minorChannelNr = -1;
23 }
24
25 cChannel::~cChannel()
26 {
27 }
28
29 bool cChannel::Parse(const std::string& data)
30 {
31 std::vector<std::string> fields;
32
33 Tokenize(data, fields, "|");
34
35 if (fields.size() >= 4)
36 {
37 // Expected format:
38 // ListTVChannels, ListRadioChannels
39 // 0 = channel uid
40 // 1 = channel external id/number
41 // 2 = channel name
42 // 3 = isencrypted ("0"/"1")
43 // ListRadioChannels only: (TVServerKodi >= v1.1.0.100)
44 // 4 = iswebstream
45 // 5 = webstream url
46 // 6 = visibleinguide (TVServerKodi >= v1.2.3.120)
47 // 7 = ATSC major channel number (TVServerKodi >= v1.8.0.126)
48 // 8 = ATSC minor channel number (TVServerKodi >= v1.8.0.126)
49
50 uid = atoi(fields[0].c_str());
51 external_id = atoi(fields[1].c_str());
52 name = fields[2];
53 encrypted = (strncmp(fields[3].c_str(), "1", 1) == 0);
54
55 if (fields.size() >= 6)
56 {
57 iswebstream = (strncmp(fields[4].c_str(), "1", 1) == 0);
58 url = fields[5].c_str();
59
60 if (fields.size() >= 7)
61 {
62 visibleinguide = (strncmp(fields[6].c_str(), "1", 1) == 0);
63 if (fields.size() >= 9)
64 {
65 majorChannelNr = atoi(fields[7].c_str());
66 minorChannelNr = atoi(fields[8].c_str());
67 }
68 else
69 {
70 majorChannelNr = -1;
71 minorChannelNr = -1;
72 }
73 }
74 }
75
76 return true;
77 }
78 else
79 {
80 return false;
81 }
82 }