1 | Index: programs/mythfilldatabase/filldata.cpp |
---|
2 | =================================================================== |
---|
3 | --- programs/mythfilldatabase/filldata.cpp (revision 9370) |
---|
4 | +++ programs/mythfilldatabase/filldata.cpp (working copy) |
---|
5 | @@ -60,6 +60,7 @@ |
---|
6 | bool dddataretrieved = false; |
---|
7 | bool mark_repeats = true; |
---|
8 | bool channel_updates = false; |
---|
9 | +bool insert_new_channels = true; |
---|
10 | |
---|
11 | int maxDays = 0; |
---|
12 | int listing_wrap_offset = 0; |
---|
13 | @@ -791,128 +792,152 @@ |
---|
14 | MSqlQuery no_xmltvid_q(MSqlQuery::DDCon()); |
---|
15 | MSqlQuery query(MSqlQuery::DDCon()); |
---|
16 | MSqlQuery chan_update_q(MSqlQuery::DDCon()); |
---|
17 | + MSqlQuery purge_new_chans(MSqlQuery::DDCon()); |
---|
18 | QString querystr; |
---|
19 | |
---|
20 | ddprocessor.updateStationViewTable(); |
---|
21 | |
---|
22 | - // Find all the channels in the dd_v_station temp table |
---|
23 | - // where there is no channel with the same xmltvid in the |
---|
24 | - // DB using the same source. |
---|
25 | - no_xmltvid_q.prepare( |
---|
26 | - "SELECT dd_v_station.stationid, dd_v_station.callsign," |
---|
27 | - " dd_v_station.stationname, dd_v_station.channel," |
---|
28 | - " dd_v_station.fccchannelnumber, dd_v_station.channelMinor " |
---|
29 | - "FROM dd_v_station LEFT JOIN channel ON " |
---|
30 | - " dd_v_station.stationid = channel.xmltvid AND " |
---|
31 | - " channel.sourceid = :SOURCEID " |
---|
32 | - "WHERE channel.chanid IS NULL;"); |
---|
33 | - no_xmltvid_q.bindValue(":SOURCEID", source.id); |
---|
34 | + if (insert_new_channels) |
---|
35 | + { |
---|
36 | + // Find all the channels in the dd_v_station temp table |
---|
37 | + // where there is no channel with the same xmltvid in the |
---|
38 | + // DB using the same source. |
---|
39 | + no_xmltvid_q.prepare( |
---|
40 | + "SELECT dd_v_station.stationid, dd_v_station.callsign," |
---|
41 | + " dd_v_station.stationname, dd_v_station.channel," |
---|
42 | + " dd_v_station.fccchannelnumber, dd_v_station.channelMinor " |
---|
43 | + "FROM dd_v_station LEFT JOIN channel ON " |
---|
44 | + " dd_v_station.stationid = channel.xmltvid AND " |
---|
45 | + " channel.sourceid = :SOURCEID " |
---|
46 | + "WHERE channel.chanid IS NULL;"); |
---|
47 | + no_xmltvid_q.bindValue(":SOURCEID", source.id); |
---|
48 | |
---|
49 | - if (!no_xmltvid_q.exec()) |
---|
50 | - MythContext::DBError("Selecting new channels", no_xmltvid_q); |
---|
51 | + if (!no_xmltvid_q.exec()) |
---|
52 | + MythContext::DBError("Selecting new channels", no_xmltvid_q); |
---|
53 | |
---|
54 | - if (no_xmltvid_q.isActive() && no_xmltvid_q.size() > 0) |
---|
55 | - { |
---|
56 | - while (no_xmltvid_q.next()) |
---|
57 | + if (no_xmltvid_q.isActive() && no_xmltvid_q.size() > 0) |
---|
58 | { |
---|
59 | - // Get the important info from our first query |
---|
60 | - QString xmltvid = no_xmltvid_q.value(0).toString(); |
---|
61 | - QString callsign = no_xmltvid_q.value(1).toString(); |
---|
62 | - QString name = no_xmltvid_q.value(2).toString(); |
---|
63 | - QString channum = no_xmltvid_q.value(3).toString(); |
---|
64 | - int freqid = no_xmltvid_q.value(4).toInt(); |
---|
65 | - QString minor = no_xmltvid_q.value(5).toString(); |
---|
66 | - QString tvformat = "Default"; |
---|
67 | - callsign = (callsign == "") ? name : callsign; |
---|
68 | - |
---|
69 | - int major = 0, atscsrcid = -9999; |
---|
70 | - if (minor != "") |
---|
71 | + while (no_xmltvid_q.next()) |
---|
72 | { |
---|
73 | - major = channum.toInt(); |
---|
74 | - atscsrcid = (major << 8) | minor.toInt(); |
---|
75 | - tvformat = "atsc"; |
---|
76 | - // default channum number |
---|
77 | - channum += SourceUtil::GetChannelSeparator(source.id) + minor; |
---|
78 | - } |
---|
79 | - else |
---|
80 | - { |
---|
81 | - freqid = channum.toInt(); |
---|
82 | - } |
---|
83 | + // Get the important info from our first query |
---|
84 | + QString xmltvid = no_xmltvid_q.value(0).toString(); |
---|
85 | + QString callsign = no_xmltvid_q.value(1).toString(); |
---|
86 | + QString name = no_xmltvid_q.value(2).toString(); |
---|
87 | + QString channum = no_xmltvid_q.value(3).toString(); |
---|
88 | + int freqid = no_xmltvid_q.value(4).toInt(); |
---|
89 | + QString minor = no_xmltvid_q.value(5).toString(); |
---|
90 | + QString tvformat = "Default"; |
---|
91 | + callsign = (callsign == "") ? name : callsign; |
---|
92 | |
---|
93 | - // First check if channel already in DB, but without xmltvid |
---|
94 | - query.prepare("SELECT chanid FROM channel " |
---|
95 | - "WHERE sourceid = :SOURCEID AND " |
---|
96 | - " (channum=:CHANNUM OR atscsrcid=:ATSCSRCID)"); |
---|
97 | - query.bindValue(":SOURCEID", source.id); |
---|
98 | - query.bindValue(":CHANNUM", channum); |
---|
99 | - query.bindValue(":ATSCSRCID", atscsrcid); |
---|
100 | + int major = 0, atscsrcid = -9999; |
---|
101 | + if (minor != "") |
---|
102 | + { |
---|
103 | + major = channum.toInt(); |
---|
104 | + atscsrcid = (major << 8) | minor.toInt(); |
---|
105 | + tvformat = "atsc"; |
---|
106 | + // default channum number |
---|
107 | + channum += SourceUtil::GetChannelSeparator(source.id) + minor; |
---|
108 | + } |
---|
109 | + else |
---|
110 | + { |
---|
111 | + freqid = channum.toInt(); |
---|
112 | + } |
---|
113 | |
---|
114 | - if (!query.exec() || !query.isActive()) |
---|
115 | - { |
---|
116 | - MythContext::DBError( |
---|
117 | - "Getting chanid of existing channel", query); |
---|
118 | - continue; // go on to next channel without xmltv |
---|
119 | - } |
---|
120 | + // First check if channel already in DB, but without xmltvid |
---|
121 | + query.prepare("SELECT chanid FROM channel " |
---|
122 | + "WHERE sourceid = :SOURCEID AND " |
---|
123 | + " (channum=:CHANNUM OR atscsrcid=:ATSCSRCID)"); |
---|
124 | + query.bindValue(":SOURCEID", source.id); |
---|
125 | + query.bindValue(":CHANNUM", channum); |
---|
126 | + query.bindValue(":ATSCSRCID", atscsrcid); |
---|
127 | |
---|
128 | - if (query.size() > 0) |
---|
129 | - { |
---|
130 | - // The channel already exists in DB, at least once, |
---|
131 | - // so set the xmltvid.. |
---|
132 | - chan_update_q.prepare( |
---|
133 | - "UPDATE channel " |
---|
134 | - "SET xmltvid = :XMLTVID " |
---|
135 | - "WHERE chanid = :CHANID AND sourceid = :SOURCEID"); |
---|
136 | + if (!query.exec() || !query.isActive()) |
---|
137 | + { |
---|
138 | + MythContext::DBError( |
---|
139 | + "Getting chanid of existing channel", query); |
---|
140 | + continue; // go on to next channel without xmltv |
---|
141 | + } |
---|
142 | |
---|
143 | - while (query.next()) |
---|
144 | + if (query.size() > 0) |
---|
145 | { |
---|
146 | - uint chanid = query.value(0).toInt(); |
---|
147 | - chan_update_q.bindValue(":CHANID", chanid); |
---|
148 | - chan_update_q.bindValue(":XMLTVID", xmltvid); |
---|
149 | - chan_update_q.bindValue(":SOURCEID", source.id); |
---|
150 | - if (!chan_update_q.exec() || !chan_update_q.isActive()) |
---|
151 | + // The channel already exists in DB, at least once, |
---|
152 | + // so set the xmltvid.. |
---|
153 | + chan_update_q.prepare( |
---|
154 | + "UPDATE channel " |
---|
155 | + "SET xmltvid = :XMLTVID " |
---|
156 | + "WHERE chanid = :CHANID AND sourceid = :SOURCEID"); |
---|
157 | + |
---|
158 | + while (query.next()) |
---|
159 | { |
---|
160 | - MythContext::DBError( |
---|
161 | - "Updating XMLTVID of existing channel", chan_update_q); |
---|
162 | - continue; // go on to next instance of this channel |
---|
163 | + uint chanid = query.value(0).toInt(); |
---|
164 | + chan_update_q.bindValue(":CHANID", chanid); |
---|
165 | + chan_update_q.bindValue(":XMLTVID", xmltvid); |
---|
166 | + chan_update_q.bindValue(":SOURCEID", source.id); |
---|
167 | + if (!chan_update_q.exec() || !chan_update_q.isActive()) |
---|
168 | + { |
---|
169 | + MythContext::DBError( |
---|
170 | + "Updating XMLTVID of existing channel", chan_update_q); |
---|
171 | + continue; // go on to next instance of this channel |
---|
172 | + } |
---|
173 | } |
---|
174 | + continue; // go on to next channel without xmltv |
---|
175 | } |
---|
176 | - continue; // go on to next channel without xmltv |
---|
177 | - } |
---|
178 | |
---|
179 | - // The channel doesn't exist in the DB, insert it... |
---|
180 | - int mplexid = -1, majorC, minorC, chanid = 0; |
---|
181 | - long long freq; |
---|
182 | - get_atsc_stuff(channum, source.id, freqid, |
---|
183 | - majorC, minorC, freq); |
---|
184 | + // The channel doesn't exist in the DB, insert it... |
---|
185 | + int mplexid = -1, majorC, minorC, chanid = 0; |
---|
186 | + long long freq; |
---|
187 | + get_atsc_stuff(channum, source.id, freqid, |
---|
188 | + majorC, minorC, freq); |
---|
189 | |
---|
190 | - if (minorC > 0 && freq >= 0) |
---|
191 | - { |
---|
192 | - mplexid = ChannelUtil::CreateMultiplex( |
---|
193 | - source.id, "atsc", freq, "8vsb"); |
---|
194 | - } |
---|
195 | + if (minorC > 0 && freq >= 0) |
---|
196 | + { |
---|
197 | + mplexid = ChannelUtil::CreateMultiplex( |
---|
198 | + source.id, "atsc", freq, "8vsb"); |
---|
199 | + } |
---|
200 | |
---|
201 | - if ((mplexid > 0) || (minorC == 0)) |
---|
202 | - chanid = ChannelUtil::CreateChanID(source.id, channum); |
---|
203 | + if ((mplexid > 0) || (minorC == 0)) |
---|
204 | + chanid = ChannelUtil::CreateChanID(source.id, channum); |
---|
205 | |
---|
206 | - if (chanid > 0) |
---|
207 | - { |
---|
208 | - QString icon = ""; |
---|
209 | - int serviceid = 0; |
---|
210 | - bool oag = false; // use on air guide |
---|
211 | - bool hidden = false; |
---|
212 | - bool hidden_in_guide = false; |
---|
213 | + if (chanid > 0) |
---|
214 | + { |
---|
215 | + QString icon = ""; |
---|
216 | + int serviceid = 0; |
---|
217 | + bool oag = false; // use on air guide |
---|
218 | + bool hidden = false; |
---|
219 | + bool hidden_in_guide = false; |
---|
220 | |
---|
221 | - ChannelUtil::CreateChannel( |
---|
222 | - mplexid, source.id, chanid, |
---|
223 | - callsign, name, channum, |
---|
224 | - serviceid, majorC, minorC, |
---|
225 | - oag, hidden, hidden_in_guide, |
---|
226 | - freqid, icon, tvformat, |
---|
227 | - xmltvid); |
---|
228 | + ChannelUtil::CreateChannel( |
---|
229 | + mplexid, source.id, chanid, |
---|
230 | + callsign, name, channum, |
---|
231 | + serviceid, majorC, minorC, |
---|
232 | + oag, hidden, hidden_in_guide, |
---|
233 | + freqid, icon, tvformat, |
---|
234 | + xmltvid); |
---|
235 | + } |
---|
236 | } |
---|
237 | } |
---|
238 | } |
---|
239 | + else // !insert_new_channels ("--no-new-channels" option) |
---|
240 | + { |
---|
241 | + // Delete all channels from the temp DB that are not already in |
---|
242 | + // the main channel DB |
---|
243 | + VERBOSE(VB_GENERAL, QString("Purging unused channels")); |
---|
244 | + purge_new_chans.prepare( |
---|
245 | + "DELETE dd_v_station " |
---|
246 | + "FROM dd_v_station " |
---|
247 | + "LEFT JOIN channel ON " |
---|
248 | + " dd_v_station.stationid = channel.xmltvid AND " |
---|
249 | + " channel.sourceid = :SOURCEID " |
---|
250 | + "WHERE channel.chanid IS NULL;"); |
---|
251 | + purge_new_chans.bindValue(":SOURCEID", source.id); |
---|
252 | |
---|
253 | + if (!purge_new_chans.exec()) |
---|
254 | + MythContext::DBError("Purging new channels", purge_new_chans); |
---|
255 | + else |
---|
256 | + VERBOSE(VB_GENERAL, |
---|
257 | + QString(" Purged %1 rows").arg(purge_new_chans.numRowsAffected())); |
---|
258 | + } |
---|
259 | + |
---|
260 | if (channel_updates) |
---|
261 | { |
---|
262 | // |
---|
263 | @@ -3447,6 +3472,10 @@ |
---|
264 | { |
---|
265 | channel_updates = true; |
---|
266 | } |
---|
267 | + else if (!strcmp(a.argv()[argpos], "--no-new-channels")) |
---|
268 | + { |
---|
269 | + insert_new_channels = false; |
---|
270 | + } |
---|
271 | else if (!strcmp(a.argv()[argpos], "--graboptions")) |
---|
272 | { |
---|
273 | if (((argpos + 1) >= a.argc())) |
---|
274 | @@ -3652,6 +3681,15 @@ |
---|
275 | cout << " override custom channel names, which is why it is\n"; |
---|
276 | cout << " off by default.\n"; |
---|
277 | cout << "\n"; |
---|
278 | + cout << "--no-new-channels\n"; |
---|
279 | + cout << " When using DataDirect, don't add data for new\n"; |
---|
280 | + cout << " channels added (usually without your knowledge) to your\n"; |
---|
281 | + cout << " DD lineup. This prevents your listings from being\n"; |
---|
282 | + cout << " flooded with channels you don't get, but also means\n"; |
---|
283 | + cout << " you have to run mythfilldatabase without this option\n"; |
---|
284 | + cout << " whenever you really want to add new channels to your\n"; |
---|
285 | + cout << " listings in Myth.\n"; |
---|
286 | + cout << "\n"; |
---|
287 | cout << "--graboptions <\"options\">\n"; |
---|
288 | cout << " Pass options to grabber\n"; |
---|
289 | cout << "\n"; |
---|