MythTV  master
netutils.cpp
Go to the documentation of this file.
1 #include <QDir>
2 #include <QFileInfo>
3 
4 #include "mythdirs.h"
5 #include "mythdb.h"
6 #include "mythcontext.h"
7 #include "mythdate.h"
8 
9 #include "netutils.h"
10 
11 bool findTreeGrabberInDB(const QString& commandline,
13 {
15  query.prepare("SELECT * FROM internetcontent WHERE "
16  "commandline = :COMMAND AND host = :HOST "
17  "AND type = :TYPE AND tree = 1;");
18  QFileInfo fi(commandline);
19  query.bindValue(":COMMAND", fi.fileName());
21  query.bindValue(":TYPE", type);
22  if (!query.exec() || !query.isActive())
23  {
24  MythDB::DBError("Tree find in db", query);
25  return false;
26  }
27 
28  return query.size() > 0;
29 }
30 
31 bool findSearchGrabberInDB(const QString& commandline,
33 {
35  query.prepare("SELECT * FROM internetcontent WHERE "
36  "commandline = :COMMAND AND host = :HOST "
37  "AND type = :TYPE AND search = 1;");
38  QFileInfo fi(commandline);
39  query.bindValue(":COMMAND", fi.fileName());
41  query.bindValue(":TYPE", type);
42  if (!query.exec() || !query.isActive())
43  {
44  MythDB::DBError("Search find in db", query);
45  return false;
46  }
47 
48  return query.size() > 0;
49 }
50 
51 GrabberScript* findTreeGrabberByCommand(const QString& commandline,
53 {
55  query.prepare("SELECT name,thumbnail,author,description,commandline,"
56  "version,search,tree FROM internetcontent "
57  "WHERE commandline = :COMMAND AND "
58  "host = :HOST AND type = :TYPE "
59  "AND tree = 1;");
60  QFileInfo fi(commandline);
61  query.bindValue(":COMMAND", fi.fileName());
63  query.bindValue(":TYPE", type);
64  if (!query.exec() || !query.isActive()) {
65  MythDB::DBError("Tree find in db", query);
66  }
67 
68  QString title = query.value(0).toString();
69  QString image = query.value(1).toString();
70  QString author = query.value(2).toString();
71  QString desc = query.value(3).toString();
72  QString command = QString("%1/internetcontent/%2").arg(GetShareDir())
73  .arg(query.value(4).toString());
74  double ver = query.value(5).toDouble();
75  bool search = query.value(6).toBool();
76  bool tree = query.value(7).toBool();
77 
78  auto *tmp = new GrabberScript(title, image, type, author, search,
79  tree, desc, command, ver);
80  return tmp;
81 }
82 
83 GrabberScript* findSearchGrabberByCommand(const QString& commandline,
85 {
87  query.prepare("SELECT name,thumbnail,author,description,commandline,"
88  "version,search,tree FROM internetcontent "
89  "WHERE commandline = :COMMAND AND "
90  "type = :TYPE AND host = :HOST AND "
91  "search = 1;");
92  QFileInfo fi(commandline);
93  query.bindValue(":COMMAND", fi.fileName());
95  query.bindValue(":TYPE", type);
96  if (!query.exec() || !query.isActive()) {
97  MythDB::DBError("Search find in db", query);
98  }
99 
100  QString title = query.value(0).toString();
101  QString image = query.value(1).toString();
102  QString author = query.value(2).toString();
103  QString desc = query.value(3).toString();
104  QString command = QString("%1/internetcontent/%2").arg(GetShareDir())
105  .arg(query.value(4).toString());
106  double ver = query.value(5).toDouble();
107  bool search = query.value(6).toBool();
108  bool tree = query.value(7).toBool();
109 
110  auto *tmp = new GrabberScript(title, image, type, author, search,
111  tree, desc, command, ver);
112  return tmp;
113 }
114 
116 {
118  query.prepare("SELECT DISTINCT name,thumbnail,type,"
119  "author,description,commandline,"
120  "version,search,tree FROM internetcontent "
121  "where tree = 1 ORDER BY name;");
122  if (!query.exec() || !query.isActive()) {
123  MythDB::DBError("Tree find in db", query);
124  }
125 
127 
128  while (query.next())
129  {
130  QString title = query.value(0).toString();
131  QString image = query.value(1).toString();
132  ArticleType type = (ArticleType)query.value(2).toInt();
133  QString author = query.value(3).toString();
134  QString desc = query.value(4).toString();
135  QString commandline = QString("%1/internetcontent/%2").arg(GetShareDir())
136  .arg(query.value(5).toString());
137  double ver = query.value(6).toDouble();
138  bool search = query.value(7).toBool();
139  bool tree = query.value(8).toBool();
140 
141  auto *script = new GrabberScript(title, image, type, author, search,
142  tree, desc, commandline, ver);
143  tmp.append(script);
144  }
145 
146  return tmp;
147 }
148 
150 {
152  query.prepare("SELECT name,thumbnail,author,description,commandline,"
153  "version,search,tree FROM internetcontent "
154  "WHERE host = :HOST AND type = :TYPE "
155  "AND tree = 1 ORDER BY name;");
157  query.bindValue(":TYPE", type);
158  if (!query.exec() || !query.isActive()) {
159  MythDB::DBError("Tree find in db", query);
160  }
161 
163 
164  while (query.next())
165  {
166  QString title = query.value(0).toString();
167  QString image = query.value(1).toString();
168  QString author = query.value(2).toString();
169  QString desc = query.value(3).toString();
170  QString commandline = QString("%1/internetcontent/%2").arg(GetShareDir())
171  .arg(query.value(4).toString());
172  double ver = query.value(5).toDouble();
173  bool search = query.value(6).toBool();
174  bool tree = query.value(7).toBool();
175 
176  auto *script = new GrabberScript(title, image, type, author, search,
177  tree, desc, commandline, ver);
178  tmp.append(script);
179  }
180 
181  return tmp;
182 }
183 
185 {
187  query.prepare("SELECT name,thumbnail,author,description,commandline,"
188  "version,search,tree FROM internetcontent "
189  "WHERE host = :HOST AND type = :TYPE "
190  "AND search = 1 ORDER BY name;");
192  query.bindValue(":TYPE", type);
193  if (!query.exec() || !query.isActive()) {
194  MythDB::DBError("Search find in db", query);
195  }
196 
198 
199  while (query.next())
200  {
201  QString title = query.value(0).toString();
202  QString image = query.value(1).toString();
203  QString author = query.value(2).toString();
204  QString desc = query.value(3).toString();
205  QString commandline = QString("%1/internetcontent/%2").arg(GetShareDir())
206  .arg(query.value(4).toString());
207  double ver = query.value(5).toDouble();
208  bool search = query.value(6).toBool();
209  bool tree = query.value(7).toBool();
210 
211  auto *script = new GrabberScript(title, image, type, author, search,
212  tree, desc, commandline, ver);
213  tmp.append(script);
214  }
215 
216  return tmp;
217 }
218 
220 {
221  if (!script)
222  return false;
223 
224  return insertGrabberInDB(script->GetTitle(), script->GetImage(),
225  type, script->GetAuthor(), script->GetDescription(),
226  script->GetCommandline(), script->GetVersion(),
227  true, false, false);
228 }
229 
231 {
232  if (!script)
233  return false;
234 
235  return insertGrabberInDB(script->GetTitle(), script->GetImage(),
236  type, script->GetAuthor(), script->GetDescription(),
237  script->GetCommandline(), script->GetVersion(),
238  false, true, false);
239 }
240 
241 bool insertGrabberInDB(const QString &name, const QString &thumbnail,
242  ArticleType type, const QString &author,
243  const QString &description, const QString &commandline,
244  const double &version, bool search, bool tree,
245  bool podcast)
246 {
247  QFileInfo fi(thumbnail);
248  QString thumbbase = fi.fileName();
249 
251  query.prepare("INSERT INTO internetcontent (name,thumbnail,type,author,"
252  "description,commandline,version,search,tree,podcast,"
253  "host) "
254  "VALUES( :NAME, :THUMBNAIL, :TYPE, :AUTHOR, :DESCRIPTION, :COMMAND, "
255  ":VERSION, :SEARCH, :TREE, :PODCAST, :HOST);");
256  query.bindValue(":NAME", name);
257  query.bindValue(":THUMBNAIL", thumbbase);
258  query.bindValue(":TYPE", type);
259  query.bindValue(":AUTHOR", author);
260  query.bindValue(":DESCRIPTION", description);
261  QFileInfo cmd(commandline);
262  query.bindValue(":COMMAND", cmd.fileName());
263  query.bindValue(":VERSION", version);
264  query.bindValue(":SEARCH", search);
265  query.bindValue(":TREE", tree);
266  query.bindValue(":PODCAST", podcast);
268  if (!query.exec() || !query.isActive()) {
269  MythDB::DBError("netcontent: inserting in DB", query);
270  return false;
271  }
272 
273  return (query.numRowsAffected() > 0);
274 }
275 
277 {
278  if (!script) return false;
279 
280  return removeGrabberFromDB(script->GetCommandline(), false);
281 }
282 
284 {
285  if (!script) return false;
286 
287  return removeGrabberFromDB(script->GetCommandline(), true);
288 }
289 
290 bool removeGrabberFromDB(const QString &commandline, const bool &search)
291 {
293  if (search)
294  {
295  query.prepare("DELETE FROM internetcontent WHERE commandline = :COMMAND "
296  "AND host = :HOST AND search = 1;");
297  }
298  else
299  {
300  query.prepare("DELETE FROM internetcontent WHERE commandline = :COMMAND "
301  "AND host = :HOST AND search = 0;");
302  }
303  QFileInfo fi(commandline);
304  query.bindValue(":COMMAND", fi.fileName());
306  if (!query.exec() || !query.isActive()) {
307  MythDB::DBError("netcontent: delete from db", query);
308  return false;
309  }
310 
311  return (query.numRowsAffected() > 0);
312 }
313 
314 bool markTreeUpdated(GrabberScript* script, const QDateTime& curTime)
315 {
317  query.prepare("UPDATE internetcontent SET updated = :UPDATED "
318  "WHERE commandline = :COMMAND AND tree = 1;");
319  query.bindValue(":UPDATED", curTime);
320  QFileInfo fi(script->GetCommandline());
321  query.bindValue(":COMMAND", fi.fileName());
322  if (!query.exec() || !query.isActive()) {
323  MythDB::DBError("netcontent: update db time", query);
324  return false;
325  }
326 
327  return (query.numRowsAffected() > 0);
328 }
329 
330 bool needsUpdate(GrabberScript* script, uint updateFreq)
331 {
332  QDateTime now = MythDate::current();
333  QDateTime then = lastUpdate(script);
334 
335  return then.addSecs(updateFreq * 60 * 60) < now;
336 }
337 
338 QDateTime lastUpdate(GrabberScript* script)
339 {
340  QDateTime updated;
342  query.prepare("SELECT updated "
343  "FROM internetcontent "
344  "WHERE commandline = :COMMAND ORDER "
345  "BY updated DESC LIMIT 1;");
346  QFileInfo fi(script->GetCommandline());
347  query.bindValue(":COMMAND", fi.fileName());
348  if (!query.exec() || !query.isActive())
349  {
350  MythDB::DBError("Tree last update in db", query);
351  }
352  else if (query.next())
353  {
354  updated = MythDate::as_utc(query.value(0).toDateTime());
355  }
356 
357  return updated;
358 }
359 
360 bool clearTreeItems(const QString &feedcommand)
361 {
362  if (feedcommand.isEmpty())
363  return false;
364 
366  query.prepare("DELETE FROM internetcontentarticles "
367  "WHERE feedtitle = :FEEDTITLE AND podcast = 0;");
368  query.bindValue(":FEEDTITLE", feedcommand);
369 
370  if (!query.exec() || !query.isActive())
371  {
372  MythDB::DBError("netcontent: clearing DB", query);
373  return false;
374  }
375 
376  return (query.numRowsAffected() > 0);
377 }
378 
379 bool isTreeInUse(const QString &feedcommand)
380 {
381  if (feedcommand.isEmpty())
382  return false;
383 
385  query.prepare("SELECT * FROM internetcontent "
386  "WHERE commandline = :COMMAND;");
387  QFileInfo fi(feedcommand);
388  query.bindValue(":COMMAND", fi.fileName());
389 
390  if (!query.exec() || !query.isActive())
391  {
392  MythDB::DBError("netcontent: isTreeInUse", query);
393  return false;
394  }
395 
396  return query.next();
397 }
398 
399 bool insertTreeArticleInDB(const QString &feedtitle, const QString &path,
400  const QString &paththumb, ResultItem *item,
402 {
403  if (!item || feedtitle.isEmpty() || path.isEmpty())
404  return false;
405 
407  query.prepare("INSERT INTO internetcontentarticles (feedtitle, path, paththumb, "
408  " title, subtitle, description, url, type, thumbnail, mediaURL, author, "
409  "date, time, rating, filesize, player, playerargs, download, "
410  "downloadargs, width, height, language, podcast, downloadable, "
411  "customhtml, countries, season, episode) "
412  "VALUES( :FEEDTITLE, :PATH, :PATHTHUMB, :TITLE, :SUBTITLE, :DESCRIPTION, "
413  ":URL, :TYPE, :THUMBNAIL, :MEDIAURL, :AUTHOR, :DATE, :TIME, :RATING, "
414  ":FILESIZE, :PLAYER, :PLAYERARGS, :DOWNLOAD, :DOWNLOADARGS, :WIDTH, :HEIGHT, "
415  ":LANGUAGE, :PODCAST, :DOWNLOADABLE, :CUSTOMHTML, :COUNTRIES, :SEASON, "
416  ":EPISODE);");
417  query.bindValue(":FEEDTITLE", feedtitle);
418  query.bindValue(":PATH", path);
419  query.bindValue(":PATHTHUMB", paththumb);
420  query.bindValue(":TITLE", item->GetTitle());
421  query.bindValue(":SUBTITLE", item->GetSubtitle().isNull() ? "" : item->GetSubtitle());
422  query.bindValue(":DESCRIPTION", item->GetDescription());
423  query.bindValue(":URL", item->GetURL());
424  query.bindValue(":TYPE", type);
425  query.bindValue(":THUMBNAIL", item->GetThumbnail());
426  query.bindValue(":MEDIAURL", item->GetMediaURL());
427  query.bindValue(":AUTHOR", item->GetAuthor());
428  query.bindValue(":DATE", item->GetDate());
429  QString time;
430  if (item->GetTime().isEmpty())
431  time = QString::number(0);
432  else
433  time = item->GetTime();
434  query.bindValue(":TIME", time);
435  query.bindValue(":RATING", item->GetRating());
436  query.bindValue(":FILESIZE", (qulonglong)item->GetFilesize());
437  query.bindValue(":PLAYER", item->GetPlayer().isNull() ? "" : item->GetPlayer());
438  query.bindValue(":PLAYERARGS", !item->GetPlayerArguments().count() ? "" :
439  item->GetPlayerArguments().join(" "));
440  query.bindValue(":DOWNLOAD", item->GetDownloader().isNull() ? "" :
441  item->GetDownloader());
442  query.bindValue(":DOWNLOADARGS", !item->GetDownloaderArguments().count() ? "" :
443  item->GetDownloaderArguments().join(" "));
444  query.bindValue(":WIDTH", item->GetWidth());
445  query.bindValue(":HEIGHT", item->GetHeight());
446  query.bindValue(":LANGUAGE", item->GetLanguage().isNull() ? "" : item->GetLanguage());
447  query.bindValue(":PODCAST", false);
448  query.bindValue(":DOWNLOADABLE", item->GetDownloadable());
449  query.bindValue(":CUSTOMHTML", item->GetCustomHTML());
450  query.bindValue(":COUNTRIES", !item->GetCountries().count() ? "" :
451  item->GetCountries().join(" "));
452  query.bindValue(":SEASON", item->GetSeason());
453  query.bindValue(":EPISODE", item->GetEpisode());
454 
455  if (!query.exec() || !query.isActive())
456  {
457  MythDB::DBError("netcontent: inserting article in DB", query);
458  return false;
459  }
460 
461  return (query.numRowsAffected() > 0);
462 }
463 
464 QMultiMap<QPair<QString,QString>, ResultItem*> getTreeArticles(const QString &feedtitle,
466 {
467  QMultiMap<QPair<QString,QString>, ResultItem*> ret;
468 
470  query.prepare("SELECT title, subtitle, description, url, "
471  "type, thumbnail, mediaURL, author, date, time, "
472  "rating, filesize, player, playerargs, download, "
473  "downloadargs, width, height, language, "
474  "downloadable, customhtml, countries, season, episode, "
475  "path, paththumb FROM internetcontentarticles "
476  "WHERE feedtitle = :FEEDTITLE AND podcast = 0 "
477  "AND type = :TYPE ORDER BY title DESC;");
478  query.bindValue(":FEEDTITLE", feedtitle);
479  query.bindValue(":TYPE", type);
480  if (!query.exec() || !query.isActive())
481  {
482  MythDB::DBError("Tree find in db", query);
483  return ret;
484  }
485 
486  while (query.next())
487  {
488  QString title = query.value(0).toString();
489  QString subtitle = query.value(1).toString();
490  QString desc = query.value(2).toString();
491  QString URL = query.value(3).toString();
492  QString feedtype = query.value(4).toString();
493  QString thumbnail = query.value(5).toString();
494  QString mediaURL = query.value(6).toString();
495  QString author = query.value(7).toString();
496  QDateTime date = MythDate::as_utc(query.value(8).toDateTime());
497  QString time = query.value(9).toString();
498  QString rating = query.value(10).toString();
499  off_t filesize = query.value(11).toULongLong();
500  QString player = query.value(12).toString();
501  QStringList playerargs = query.value(13).toString().split(" ");
502  QString download = query.value(14).toString();
503  QStringList downloadargs = query.value(15).toString().split(" ");
504  uint width = query.value(16).toUInt();
505  uint height = query.value(17).toUInt();
506  QString language = query.value(18).toString();
507  bool downloadable = query.value(19).toBool();
508  bool customhtml = query.value(20).toBool();
509  QStringList countries = query.value(21).toString().split(" ");
510  uint season = query.value(22).toUInt();
511  uint episode = query.value(23).toUInt();
512 
513  QString path = query.value(24).toString();
514  QString paththumb = query.value(25).toString();
515 
516  QPair<QString,QString> pair(path,paththumb);
517  ret.insert(pair, new ResultItem(title, QString(),
518  subtitle, QString(), desc, URL,
519  thumbnail, mediaURL, author, date, time, rating, filesize,
520  player, playerargs, download, downloadargs,
521  width, height, language, downloadable, countries,
522  season, episode, customhtml));
523  }
524 
525  return ret;
526 }
527 
528 bool findInDB(const QString& url, ArticleType type)
529 {
531  query.prepare("SELECT commandline FROM internetcontent WHERE commandline = :URL AND "
532  "type = :TYPE AND podcast = 1;");
533  query.bindValue(":URL", url);
534  query.bindValue(":TYPE", type);
535  if (!query.exec() || !query.isActive()) {
536  MythDB::DBError("RSS find in db", query);
537  return false;
538  }
539 
540  return query.size() > 0;
541 }
542 
543 RSSSite* findByURL(const QString& url, ArticleType type)
544 {
545  RSSSite *tmp = nullptr;
547  query.prepare("SELECT name,thumbnail,author,description,"
548  "commandline,download,updated FROM internetcontent "
549  "WHERE commandline = :URL AND type = :TYPE "
550  "AND podcast = 1;");
551  query.bindValue(":URL", url);
552  query.bindValue(":TYPE", type);
553  if (!query.exec() || !query.next())
554  {
555  MythDB::DBError("RSS find in db", query);
556  tmp = new RSSSite(QString(), QString(),
557  QString(), (ArticleType)0, QString(),
558  QString(), QString(), false,
559  QDateTime());
560  }
561  else
562  {
563  QString title = query.value(0).toString();
564  QString image = query.value(1).toString();
565  QString author = query.value(2).toString();
566  QString description = query.value(3).toString();
567  QString outurl = query.value(4).toString();
568  bool download = query.value(5).toBool();
569  QDateTime updated; query.value(6).toDate();
570 
571  tmp = new RSSSite(title, QString(), image, type, description,
572  outurl, author, download, updated);
573  }
574 
575  return tmp;
576 }
577 
579 {
581 
583  query.prepare(
584  "SELECT name, thumbnail, description, commandline, author, "
585  "download, updated FROM internetcontent WHERE podcast = 1 "
586  "AND type = :TYPE ORDER BY name");
587 
588  query.bindValue(":TYPE", type);
589 
590  if (!query.exec())
591  {
592  return tmp;
593  }
594 
595  while (query.next())
596  {
597  QString title = query.value(0).toString();
598  QString image = query.value(1).toString();
599  QString description = query.value(2).toString();
600  QString url = query.value(3).toString();
601  QString author = query.value(4).toString();
602  bool download = query.value(5).toBool();
603  QDateTime updated; query.value(6).toDate();
604  tmp.append(new RSSSite(title, QString(), image, type, description, url,
605  author, download, updated));
606  }
607 
608  return tmp;
609 }
610 
612 {
614 
616  query.prepare(
617  "SELECT name, thumbnail, type, description, commandline, author, "
618  "download, updated FROM internetcontent WHERE podcast = 1 "
619  "ORDER BY name");
620 
621  if (!query.exec())
622  {
623  return tmp;
624  }
625 
626  while (query.next())
627  {
628  QString title = query.value(0).toString();
629  QString image = query.value(1).toString();
630  ArticleType type = (ArticleType)query.value(2).toInt();
631  QString description = query.value(3).toString();
632  QString url = query.value(4).toString();
633  QString author = query.value(5).toString();
634  bool download = query.value(6).toBool();
635  QDateTime updated; query.value(7).toDate();
636  tmp.append(new RSSSite(title, QString(),
637  image, type, description, url,
638  author, download, updated));
639  }
640 
641  return tmp;
642 }
643 
644 bool insertInDB(RSSSite* site)
645 {
646  if (!site) return false;
647 
648  return insertInDB(site->GetTitle(), site->GetSortTitle(), site->GetImage(),
649  site->GetDescription(), site->GetURL(),
650  site->GetAuthor(), site->GetDownload(),
651  site->GetUpdated(), site->GetType());
652 }
653 
654 bool insertInDB(const QString &name, const QString &sortname,
655  const QString &thumbnail,
656  const QString &description, const QString &url,
657  const QString &author, const bool &download,
658  const QDateTime &updated, ArticleType type)
659 {
660  if (findInDB(name, type))
661  return false;
662 
664  query.prepare("INSERT INTO internetcontent (name,thumbnail,description,"
665  "commandline,author,download,updated,podcast, type) "
666  "VALUES( :NAME, :THUMBNAIL, :DESCRIPTION, :URL, :AUTHOR, :DOWNLOAD, "
667  ":UPDATED, :PODCAST, :TYPE);");
668  query.bindValue(":NAME", name);
669  Q_UNUSED(sortname); // query.bindValue(":SORTNAME", sortname);
670  query.bindValue(":THUMBNAIL", thumbnail);
671  query.bindValue(":DESCRIPTION", description);
672  query.bindValue(":URL", url);
673  query.bindValue(":AUTHOR", author);
674  query.bindValue(":DOWNLOAD", download);
675  query.bindValue(":UPDATED", updated);
676  query.bindValue(":PODCAST", true);
677  query.bindValue(":TYPE", type);
678  if (!query.exec() || !query.isActive()) {
679  MythDB::DBError("netcontent: inserting in DB", query);
680  return false;
681  }
682 
683  return (query.numRowsAffected() > 0);
684 }
685 
687 {
688  if (!site) return false;
689 
690  return removeFromDB(site->GetURL(), site->GetType());
691 }
692 
693 bool removeFromDB(const QString &url, ArticleType type)
694 {
696  query.prepare("DELETE FROM internetcontent WHERE commandline = :URL "
697  "AND type = :TYPE;");
698  query.bindValue(":URL", url);
699  query.bindValue(":TYPE", type);
700  if (!query.exec() || !query.isActive()) {
701  MythDB::DBError("netcontent: delete from db", query);
702  return false;
703  }
704 
705  return (query.numRowsAffected() > 0);
706 }
707 
708 void markUpdated(RSSSite *site)
709 {
710  QDateTime now = MythDate::current();
711 
713  query.prepare("UPDATE internetcontent SET updated = :UPDATED "
714  "WHERE commandline = :URL AND type = :TYPE;");
715  query.bindValue(":UPDATED", now);
716  query.bindValue(":URL", site->GetURL());
717  query.bindValue(":TYPE", site->GetType());
718  if (!query.exec() || !query.isActive())
719  MythDB::DBError("netcontent update time", query);
720 }
721 
722 bool clearRSSArticles(const QString &feedtitle, ArticleType type)
723 {
724  if (feedtitle.isEmpty())
725  return false;
726 
728  query.prepare("DELETE FROM internetcontentarticles "
729  "WHERE feedtitle = :FEEDTITLE AND podcast = 1 "
730  "AND type = :TYPE ;");
731  query.bindValue(":FEEDTITLE", feedtitle);
732  query.bindValue(":TYPE", type);
733 
734  if (!query.exec() || !query.isActive()) {
735  MythDB::DBError("netcontent: clearing DB", query);
736  return false;
737  }
738 
739  return (query.numRowsAffected() > 0);
740 }
741 
742 bool insertRSSArticleInDB(const QString &feedtitle, ResultItem *item,
744 {
745  if (!item || feedtitle.isEmpty())
746  return false;
747 
749  query.prepare("INSERT INTO internetcontentarticles (feedtitle, title, "
750  "description, url, type, thumbnail, mediaURL, author, date, time, "
751  "rating, filesize, player, playerargs, download, "
752  "downloadargs, width, height, language, downloadable, countries, "
753  "podcast) "
754  "VALUES( :FEEDTITLE, :TITLE, :DESCRIPTION, :URL, :TYPE, :THUMBNAIL, "
755  ":MEDIAURL, :AUTHOR, :DATE, :TIME, :RATING, :FILESIZE, :PLAYER, "
756  ":PLAYERARGS, :DOWNLOAD, :DOWNLOADARGS, :WIDTH, :HEIGHT, "
757  ":LANGUAGE, :DOWNLOADABLE, :COUNTRIES, :PODCAST);");
758  query.bindValue(":FEEDTITLE", feedtitle);
759  query.bindValue(":TITLE", item->GetTitle());
760  //RSS articles don't have subtitles
761  query.bindValue(":DESCRIPTION", item->GetDescription());
762  query.bindValue(":URL", item->GetURL());
763  query.bindValue(":TYPE", type);
764  query.bindValue(":THUMBNAIL", item->GetThumbnail());
765  query.bindValue(":MEDIAURL", item->GetMediaURL());
766  query.bindValue(":AUTHOR", item->GetAuthor());
767  query.bindValue(":DATE", item->GetDate());
768  QString time;
769  if (item->GetTime().isEmpty())
770  time = QString::number(0);
771  else
772  time = item->GetTime();
773  query.bindValue(":TIME", time);
774  query.bindValue(":RATING", item->GetRating());
775  query.bindValue(":FILESIZE", (qulonglong)item->GetFilesize());
776  query.bindValue(":PLAYER", item->GetPlayer().isNull() ? "" : item->GetPlayer());
777  query.bindValue(":PLAYERARGS", !item->GetPlayerArguments().count() ? "" :
778  item->GetPlayerArguments().join(" "));
779  query.bindValue(":DOWNLOAD", item->GetDownloader().isNull() ? "" :
780  item->GetDownloader());
781  query.bindValue(":DOWNLOADARGS", !item->GetDownloaderArguments().count() ? "" :
782  item->GetDownloaderArguments().join(" "));
783  query.bindValue(":WIDTH", item->GetWidth());
784  query.bindValue(":HEIGHT", item->GetHeight());
785  query.bindValue(":LANGUAGE", item->GetLanguage().isNull() ? "" : item->GetLanguage());
786  query.bindValue(":DOWNLOADABLE", item->GetDownloadable());
787  query.bindValue(":COUNTRIES", item->GetCountries());
788  query.bindValue(":PODCAST", true);
789 
790  if (!query.exec() || !query.isActive()) {
791  MythDB::DBError("netcontent: inserting article in DB", query);
792  return false;
793  }
794 
795  return (query.numRowsAffected() > 0);
796 }
797 
798 ResultItem::resultList getRSSArticles(const QString &feedtitle,
800 {
802 
804  query.prepare("SELECT title, description, url, "
805  "thumbnail, mediaURL, author, date, time, "
806  "rating, filesize, player, playerargs, download, "
807  "downloadargs, width, height, language, "
808  "downloadable, countries, season, episode "
809  "FROM internetcontentarticles "
810  "WHERE feedtitle = :FEEDTITLE AND podcast = 1 "
811  "AND type = :TYPE ORDER BY date DESC;");
812  query.bindValue(":FEEDTITLE", feedtitle);
813  query.bindValue(":TYPE", type);
814  if (!query.exec() || !query.isActive()) {
815  MythDB::DBError("RSS find in db", query);
816  return ret;
817  }
818 
819  while (query.next())
820  {
821  QString title = query.value(0).toString();
822  //RSS articles don't have subtitles
823  QString desc = query.value(1).toString();
824  QString URL = query.value(2).toString();
825  QString thumbnail = query.value(3).toString();
826  QString mediaURL = query.value(4).toString();
827  QString author = query.value(5).toString();
828  QDateTime date = MythDate::as_utc(query.value(6).toDateTime());
829  QString time = query.value(7).toString();
830  QString rating = query.value(8).toString();
831  off_t filesize = query.value(9).toULongLong();
832  QString player = query.value(10).toString();
833  QStringList playerargs = query.value(11).toString().split(" ");
834  QString download = query.value(12).toString();
835  QStringList downloadargs = query.value(13).toString().split(" ");
836  uint width = query.value(14).toUInt();
837  uint height = query.value(15).toUInt();
838  QString language = query.value(16).toString();
839  bool downloadable = query.value(17).toBool();
840  QStringList countries = query.value(18).toString().split(" ");
841  uint season = query.value(19).toUInt();
842  uint episode = query.value(20).toUInt();
843 
844  ret.append(new ResultItem(title, QString(), QString(),
845  QString(), desc, URL, thumbnail,
846  mediaURL, author, date, time, rating, filesize,
847  player, playerargs, download, downloadargs,
848  width, height, language, downloadable, countries,
849  season, episode, false));
850  }
851 
852  return ret;
853 }
854 
855 QString GetDownloadFilename(const QString& title, const QString& url)
856 {
857  QByteArray urlarr(url.toLatin1());
858  quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length());
859  QByteArray titlearr(title.toLatin1());
860  quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length());
861  QUrl qurl(url);
862  QString ext = QFileInfo(qurl.path()).suffix();
863  QString basefilename = QString("download_%1_%2.%3")
864  .arg(QString::number(urlChecksum))
865  .arg(QString::number(titleChecksum)).arg(ext);
866 
867  return basefilename;
868 }
MSqlQuery::isActive
bool isActive(void) const
Definition: mythdbcon.h:204
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:126
ResultItem::GetFilesize
const off_t & GetFilesize() const
Definition: rssparse.h:146
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:203
GrabberScript::GetAuthor
const QString & GetAuthor() const
Definition: netgrabbermanager.h:37
insertTreeArticleInDB
bool insertTreeArticleInDB(const QString &feedtitle, const QString &path, const QString &paththumb, ResultItem *item, ArticleType type)
Definition: netutils.cpp:399
insertInDB
bool insertInDB(RSSSite *site)
Definition: netutils.cpp:644
GetDownloadFilename
QString GetDownloadFilename(const QString &title, const QString &url)
Definition: netutils.cpp:855
RSSSite::GetDownload
const bool & GetDownload() const
Definition: mythrssmanager.h:60
findTreeGrabberByCommand
GrabberScript * findTreeGrabberByCommand(const QString &commandline, ArticleType type)
Definition: netutils.cpp:51
findInDB
bool findInDB(const QString &url, ArticleType type)
Definition: netutils.cpp:528
GrabberScript::GetCommandline
const QString & GetCommandline() const
Definition: netgrabbermanager.h:41
mythdb.h
RSSSite::GetSortTitle
const QString & GetSortTitle() const
Definition: mythrssmanager.h:54
findAllDBSearchGrabbers
GrabberScript::scriptList findAllDBSearchGrabbers(ArticleType type)
Definition: netutils.cpp:184
MythDate::as_utc
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
Definition: mythdate.cpp:23
ResultItem::GetPlayer
const QString & GetPlayer() const
Definition: rssparse.h:147
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:633
markUpdated
void markUpdated(RSSSite *site)
Definition: netutils.cpp:708
ResultItem::GetTitle
const QString & GetTitle() const
Definition: rssparse.h:134
GrabberScript::GetImage
const QString & GetImage() const
Definition: netgrabbermanager.h:35
RSSSite::GetType
const ArticleType & GetType() const
Definition: mythrssmanager.h:56
ResultItem::GetCustomHTML
const bool & GetCustomHTML() const
Definition: rssparse.h:158
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
removeGrabberFromDB
bool removeGrabberFromDB(const QString &commandline, const bool &search)
Definition: netutils.cpp:290
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
GrabberScript::GetDescription
const QString & GetDescription() const
Definition: netgrabbermanager.h:40
RSSSite::GetDescription
const QString & GetDescription() const
Definition: mythrssmanager.h:57
GrabberScript::GetTitle
const QString & GetTitle() const
Definition: netgrabbermanager.h:34
findAllDBRSSByType
RSSSite::rssList findAllDBRSSByType(ArticleType type)
Definition: netutils.cpp:578
insertRSSArticleInDB
bool insertRSSArticleInDB(const QString &feedtitle, ResultItem *item, ArticleType type)
Definition: netutils.cpp:742
ResultItem::GetCountries
const QStringList & GetCountries() const
Definition: rssparse.h:155
mythdirs.h
findSearchGrabberInDB
bool findSearchGrabberInDB(const QString &commandline, ArticleType type)
Definition: netutils.cpp:31
findAllDBTreeGrabbers
GrabberScript::scriptList findAllDBTreeGrabbers()
Definition: netutils.cpp:115
needsUpdate
bool needsUpdate(GrabberScript *script, uint updateFreq)
Definition: netutils.cpp:330
getTreeArticles
QMultiMap< QPair< QString, QString >, ResultItem * > getTreeArticles(const QString &feedtitle, ArticleType type)
Definition: netutils.cpp:464
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
tmp
static guint32 * tmp
Definition: goom_core.cpp:30
markTreeUpdated
bool markTreeUpdated(GrabberScript *script, const QDateTime &curTime)
Definition: netutils.cpp:314
GrabberScript::scriptList
QList< GrabberScript * > scriptList
Definition: netgrabbermanager.h:46
findTreeGrabberInDB
bool findTreeGrabberInDB(const QString &commandline, ArticleType type)
Definition: netutils.cpp:11
ResultItem::GetAuthor
const QString & GetAuthor() const
Definition: rssparse.h:142
mythdate.h
ResultItem::GetRating
const QString & GetRating() const
Definition: rssparse.h:145
ResultItem::GetThumbnail
const QString & GetThumbnail() const
Definition: rssparse.h:140
ResultItem::GetDate
const QDateTime & GetDate() const
Definition: rssparse.h:143
ResultItem::GetWidth
const uint & GetWidth() const
Definition: rssparse.h:151
removeFromDB
bool removeFromDB(RSSSite *site)
Definition: netutils.cpp:686
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
GetShareDir
QString GetShareDir(void)
Definition: mythdirs.cpp:222
hardwareprofile.scan.rating
def rating(profile, smoonURL, gate)
Definition: scan.py:39
ResultItem::GetDownloader
const QString & GetDownloader() const
Definition: rssparse.h:149
netutils.h
ResultItem::GetTime
const QString & GetTime() const
Definition: rssparse.h:144
insertSearchInDB
bool insertSearchInDB(GrabberScript *script, ArticleType type)
Definition: netutils.cpp:219
ResultItem::GetLanguage
const QString & GetLanguage() const
Definition: rssparse.h:153
ResultItem::GetSeason
const uint & GetSeason() const
Definition: rssparse.h:156
insertGrabberInDB
bool insertGrabberInDB(const QString &name, const QString &thumbnail, ArticleType type, const QString &author, const QString &description, const QString &commandline, const double &version, bool search, bool tree, bool podcast)
Definition: netutils.cpp:241
GrabberScript
Definition: netgrabbermanager.h:17
isTreeInUse
bool isTreeInUse(const QString &feedcommand)
Definition: netutils.cpp:379
ResultItem::GetSubtitle
const QString & GetSubtitle() const
Definition: rssparse.h:136
uint
unsigned int uint
Definition: compat.h:140
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
RSSSite::GetAuthor
const QString & GetAuthor() const
Definition: mythrssmanager.h:59
ArticleType
ArticleType
Definition: rssparse.h:20
GrabberScript::GetVersion
const double & GetVersion() const
Definition: netgrabbermanager.h:42
off_t
#define off_t
Definition: mythiowrapper.cpp:238
ResultItem::GetDescription
const QString & GetDescription() const
Definition: rssparse.h:138
findSearchGrabberByCommand
GrabberScript * findSearchGrabberByCommand(const QString &commandline, ArticleType type)
Definition: netutils.cpp:83
ResultItem::GetPlayerArguments
const QStringList & GetPlayerArguments() const
Definition: rssparse.h:148
ResultItem::GetEpisode
const uint & GetEpisode() const
Definition: rssparse.h:157
RSSSite::GetUpdated
const QDateTime & GetUpdated() const
Definition: mythrssmanager.h:61
findAllDBRSS
RSSSite::rssList findAllDBRSS()
Definition: netutils.cpp:611
lastUpdate
QDateTime lastUpdate(GrabberScript *script)
Definition: netutils.cpp:338
RSSSite::GetImage
const QString & GetImage() const
Definition: mythrssmanager.h:55
ResultItem::GetURL
const QString & GetURL() const
Definition: rssparse.h:139
countries
QDomElement countries
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:782
clearTreeItems
bool clearTreeItems(const QString &feedcommand)
Definition: netutils.cpp:360
ResultItem
Definition: rssparse.h:110
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
RSSSite::GetTitle
const QString & GetTitle() const
Definition: mythrssmanager.h:53
findByURL
RSSSite * findByURL(const QString &url, ArticleType type)
Definition: netutils.cpp:543
mythcontext.h
insertTreeInDB
bool insertTreeInDB(GrabberScript *script, ArticleType type)
Definition: netutils.cpp:230
ResultItem::resultList
QList< ResultItem * > resultList
Definition: rssparse.h:114
MSqlQuery::numRowsAffected
int numRowsAffected() const
Definition: mythdbcon.h:206
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:856
removeTreeFromDB
bool removeTreeFromDB(GrabberScript *script)
Definition: netutils.cpp:276
clearRSSArticles
bool clearRSSArticles(const QString &feedtitle, ArticleType type)
Definition: netutils.cpp:722
getRSSArticles
ResultItem::resultList getRSSArticles(const QString &feedtitle, ArticleType type)
Definition: netutils.cpp:798
URL
static const char URL[]
Definition: cddb.cpp:29
ResultItem::GetDownloaderArguments
const QStringList & GetDownloaderArguments() const
Definition: rssparse.h:150
query
MSqlQuery query(MSqlQuery::InitCon())
ResultItem::GetDownloadable
const bool & GetDownloadable() const
Definition: rssparse.h:154
nv_python_libs.bbciplayer.bbciplayer_api.version
string version
Definition: bbciplayer_api.py:81
RSSSite::GetURL
const QString & GetURL() const
Definition: mythrssmanager.h:58
removeSearchFromDB
bool removeSearchFromDB(GrabberScript *script)
Definition: netutils.cpp:283
RSSSite
Definition: mythrssmanager.h:20
findAllDBTreeGrabbersByHost
GrabberScript::scriptList findAllDBTreeGrabbersByHost(ArticleType type)
Definition: netutils.cpp:149
ResultItem::GetHeight
const uint & GetHeight() const
Definition: rssparse.h:152
RSSSite::rssList
QList< RSSSite * > rssList
Definition: mythrssmanager.h:51
ResultItem::GetMediaURL
const QString & GetMediaURL() const
Definition: rssparse.h:141
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808