MythTV  master
videodbcheck.cpp
Go to the documentation of this file.
1 /* Integrates the MythVideo DB schema into the core MythTV DB schema. Used
2  * only by DB update 1267. Any further changes to the core MythTV schema,
3  * including changes to those parts that were previously MythVideo, should
4  * be done in mythtv/libs/libmythtv/dbcheck.cpp. */
5 
6 #include <QString>
7 #include <QStringList>
8 
9 #include "mythdbcheck.h"
10 #include "videodbcheck.h"
11 #include "mythdb.h"
12 #include "mythcorecontext.h"
13 #include "mythlogging.h"
14 #include "remotefile.h"
15 #include "mythmiscutil.h"
17 
18 const QString minimumVideoDatabaseVersion = "1016";
19 const QString finalVideoDatabaseVersion = "1038";
20 const QString MythVideoVersionName = "mythvideo.DBSchemaVer";
21 
22 static void AddFileType(const QString &extension,
23  const QString &playCommand = QString("Internal"),
24  bool ignored = false, bool useDefault = false)
25 {
27  query.prepare("SELECT * FROM videotypes WHERE "
28  "LOWER(extension) = LOWER(:EXTENSION) LIMIT 1");
29  query.bindValue(":EXTENSION", extension);
30  if (query.exec() && !query.size())
31  {
32  query.prepare("INSERT INTO videotypes (extension, playcommand, "
33  "f_ignore, use_default) VALUES (:EXTENSION, :PLAYCOMMAND, "
34  ":IGNORE, :USEDEFAULT)");
35  query.bindValue(":EXTENSION", extension);
36  query.bindValue(":PLAYCOMMAND", playCommand);
37  query.bindValue(":IGNORE", ignored);
38  query.bindValue(":USEDEFAULT", useDefault);
39  if (!query.exec())
40  MythDB::DBError(QObject::tr("Error: failed to add new file "
41  "type '%1'").arg(extension), query);
42  }
43 }
44 
45 static void UpdateHashes(void)
46 {
48  query.prepare("SELECT `filename`, `host` FROM videometadata WHERE "
49  "`hash` = \"\"");
50  if (query.exec() && query.size())
51  {
52  while (query.next())
53  {
54  QString filename = query.value(0).toString();
55  QString host = query.value(1).toString();
56  QString hash;
57 
58  if (!host.isEmpty())
59  {
60  QString url = generate_file_url("Videos", host, filename);
61  hash = RemoteFile::GetFileHash(url);
62  }
63  else
64  hash = FileHash(filename);
65 
66  if (hash == "NULL")
67  hash = QString();
68 
69  MSqlQuery updatequery(MSqlQuery::InitCon());
70 
71  updatequery.prepare("UPDATE videometadata set `hash` = :HASH "
72  "WHERE `filename` = :FILENAME AND "
73  "`host` = :HOST");
74  updatequery.bindValue(":HASH", hash);
75  updatequery.bindValue(":FILENAME", filename);
76  updatequery.bindValue(":HOST", host);
77  if (!updatequery.exec())
78  {
79  MythDB::DBError(QObject::tr("Error: failed to hash file "
80  "'%1'").arg(filename), updatequery);
81  }
82  else
83  {
84  LOG(VB_GENERAL, LOG_INFO,
85  QString("Hash (%1) generated for file (%2)")
86  .arg(hash).arg(filename));
87  }
88  }
89  }
90 }
91 
92 static bool InitializeVideoSchema(void)
93 {
95  LOG(VB_GENERAL, LOG_NOTICE,
96  "Inserting initial video database information.");
97 
98  DBUpdates updates {
99 "CREATE TABLE dvdinput ("
100 " intid int(10) unsigned NOT NULL,"
101 " hsize int(10) unsigned DEFAULT NULL,"
102 " vsize int(10) unsigned DEFAULT NULL,"
103 " ar_num int(10) unsigned DEFAULT NULL,"
104 " ar_denom int(10) unsigned DEFAULT NULL,"
105 " fr_code int(10) unsigned DEFAULT NULL,"
106 " letterbox tinyint(1) DEFAULT NULL,"
107 " v_format varchar(16) DEFAULT NULL,"
108 " PRIMARY KEY (intid)"
109 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
110 "CREATE TABLE dvdtranscode ("
111 " intid int(11) NOT NULL AUTO_INCREMENT,"
112 " input int(10) unsigned DEFAULT NULL,"
113 " `name` varchar(128) NOT NULL,"
114 " sync_mode int(10) unsigned DEFAULT NULL,"
115 " use_yv12 tinyint(1) DEFAULT NULL,"
116 " cliptop int(11) DEFAULT NULL,"
117 " clipbottom int(11) DEFAULT NULL,"
118 " clipleft int(11) DEFAULT NULL,"
119 " clipright int(11) DEFAULT NULL,"
120 " f_resize_h int(11) DEFAULT NULL,"
121 " f_resize_w int(11) DEFAULT NULL,"
122 " hq_resize_h int(11) DEFAULT NULL,"
123 " hq_resize_w int(11) DEFAULT NULL,"
124 " grow_h int(11) DEFAULT NULL,"
125 " grow_w int(11) DEFAULT NULL,"
126 " clip2top int(11) DEFAULT NULL,"
127 " clip2bottom int(11) DEFAULT NULL,"
128 " clip2left int(11) DEFAULT NULL,"
129 " clip2right int(11) DEFAULT NULL,"
130 " codec varchar(128) NOT NULL,"
131 " codec_param varchar(128) DEFAULT NULL,"
132 " bitrate int(11) DEFAULT NULL,"
133 " a_sample_r int(11) DEFAULT NULL,"
134 " a_bitrate int(11) DEFAULT NULL,"
135 " two_pass tinyint(1) DEFAULT NULL,"
136 " tc_param varchar(128) DEFAULT NULL,"
137 " PRIMARY KEY (intid)"
138 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
139 "CREATE TABLE filemarkup ("
140 " filename text NOT NULL,"
141 " mark mediumint(8) unsigned NOT NULL DEFAULT '0',"
142 " `offset` bigint(20) unsigned DEFAULT NULL,"
143 " `type` tinyint(4) NOT NULL DEFAULT '0',"
144 " KEY filename (filename(255))"
145 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
146 "CREATE TABLE videocast ("
147 " intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
148 " cast varchar(128) NOT NULL,"
149 " PRIMARY KEY (intid)"
150 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
151 "CREATE TABLE videocategory ("
152 " intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
153 " category varchar(128) NOT NULL,"
154 " PRIMARY KEY (intid)"
155 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
156 "CREATE TABLE videocountry ("
157 " intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
158 " country varchar(128) NOT NULL,"
159 " PRIMARY KEY (intid)"
160 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
161 "CREATE TABLE videogenre ("
162 " intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
163 " genre varchar(128) NOT NULL,"
164 " PRIMARY KEY (intid)"
165 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
166 "CREATE TABLE videometadata ("
167 " intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
168 " title varchar(128) NOT NULL,"
169 " subtitle text NOT NULL,"
170 " tagline varchar(255) DEFAULT NULL,"
171 " director varchar(128) NOT NULL,"
172 " studio varchar(128) DEFAULT NULL,"
173 " plot text,"
174 " rating varchar(128) NOT NULL,"
175 " inetref varchar(255) NOT NULL,"
176 " homepage text NOT NULL,"
177 " `year` int(10) unsigned NOT NULL,"
178 " releasedate date NOT NULL,"
179 " userrating float NOT NULL,"
180 " length int(10) unsigned NOT NULL,"
181 " season smallint(5) unsigned NOT NULL DEFAULT '0',"
182 " episode smallint(5) unsigned NOT NULL DEFAULT '0',"
183 " showlevel int(10) unsigned NOT NULL,"
184 " filename text NOT NULL,"
185 " `hash` varchar(128) NOT NULL,"
186 " coverfile text NOT NULL,"
187 " childid int(11) NOT NULL DEFAULT '-1',"
188 " browse tinyint(1) NOT NULL DEFAULT '1',"
189 " watched tinyint(1) NOT NULL DEFAULT '0',"
190 " processed tinyint(1) NOT NULL DEFAULT '0',"
191 " playcommand varchar(255) DEFAULT NULL,"
192 " category int(10) unsigned NOT NULL DEFAULT '0',"
193 " trailer text,"
194 " `host` text NOT NULL,"
195 " screenshot text,"
196 " banner text,"
197 " fanart text,"
198 " insertdate timestamp NULL DEFAULT CURRENT_TIMESTAMP,"
199 " PRIMARY KEY (intid),"
200 " KEY director (director),"
201 " KEY title (title)"
202 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
203 "CREATE TABLE videometadatacast ("
204 " idvideo int(10) unsigned NOT NULL,"
205 " idcast int(10) unsigned NOT NULL,"
206 " UNIQUE KEY idvideo (idvideo,idcast)"
207 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
208 "CREATE TABLE videometadatacountry ("
209 " idvideo int(10) unsigned NOT NULL,"
210 " idcountry int(10) unsigned NOT NULL,"
211 " UNIQUE KEY idvideo_2 (idvideo,idcountry),"
212 " KEY idvideo (idvideo),"
213 " KEY idcountry (idcountry)"
214 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
215 "CREATE TABLE videometadatagenre ("
216 " idvideo int(10) unsigned NOT NULL,"
217 " idgenre int(10) unsigned NOT NULL,"
218 " UNIQUE KEY idvideo_2 (idvideo,idgenre),"
219 " KEY idvideo (idvideo),"
220 " KEY idgenre (idgenre)"
221 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
222 "CREATE TABLE videotypes ("
223 " intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
224 " extension varchar(128) NOT NULL,"
225 " playcommand varchar(255) NOT NULL,"
226 " f_ignore tinyint(1) DEFAULT NULL,"
227 " use_default tinyint(1) DEFAULT NULL,"
228 " PRIMARY KEY (intid)"
229 ") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
230 "INSERT INTO dvdinput VALUES (1,720,480,16,9,1,1,'ntsc');",
231 "INSERT INTO dvdinput VALUES (2,720,480,16,9,1,0,'ntsc');",
232 "INSERT INTO dvdinput VALUES (3,720,480,4,3,1,1,'ntsc');",
233 "INSERT INTO dvdinput VALUES (4,720,480,4,3,1,0,'ntsc');",
234 "INSERT INTO dvdinput VALUES (5,720,576,16,9,3,1,'pal');",
235 "INSERT INTO dvdinput VALUES (6,720,576,16,9,3,0,'pal');",
236 "INSERT INTO dvdinput VALUES (7,720,576,4,3,3,1,'pal');",
237 "INSERT INTO dvdinput VALUES (8,720,576,4,3,3,0,'pal');",
238 "INSERT INTO dvdtranscode VALUES (1,1,'Good',2,1,16,16,0,0,2,0,0,0,0,0,32,32,8,8,'divx5',NULL,1618,NULL,NULL,0,NULL);",
239 "INSERT INTO dvdtranscode VALUES (2,2,'Excellent',2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'divx5',NULL,0,NULL,NULL,1,NULL);",
240 "INSERT INTO dvdtranscode VALUES (3,2,'Good',2,1,0,0,8,8,0,0,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
241 "INSERT INTO dvdtranscode VALUES (4,2,'Medium',2,1,0,0,8,8,5,5,0,0,0,0,0,0,0,0,'divx5',NULL,1200,NULL,NULL,0,NULL);",
242 "INSERT INTO dvdtranscode VALUES (5,3,'Good',2,1,0,0,0,0,0,0,0,0,2,0,80,80,8,8,'divx5',NULL,0,NULL,NULL,0,NULL);",
243 "INSERT INTO dvdtranscode VALUES (6,4,'Excellent',2,1,0,0,0,0,0,0,0,0,2,0,0,0,0,0,'divx5',NULL,0,NULL,NULL,1,NULL);",
244 "INSERT INTO dvdtranscode VALUES (7,4,'Good',2,1,0,0,8,8,0,2,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
245 "INSERT INTO dvdtranscode VALUES (8,5,'Good',1,1,16,16,0,0,5,0,0,0,0,0,40,40,8,8,'divx5',NULL,1618,NULL,NULL,0,NULL);",
246 "INSERT INTO dvdtranscode VALUES (9,6,'Good',1,1,0,0,16,16,5,0,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
247 "INSERT INTO dvdtranscode VALUES (10,7,'Good',1,1,0,0,0,0,1,0,0,0,0,0,76,76,8,8,'divx5',NULL,1618,NULL,NULL,0,NULL);",
248 "INSERT INTO dvdtranscode VALUES (11,8,'Good',1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
249 "INSERT INTO videotypes VALUES (1,'txt','',1,0);",
250 "INSERT INTO videotypes VALUES (2,'log','',1,0);",
251 "INSERT INTO videotypes VALUES (3,'mpg','Internal',0,0);",
252 "INSERT INTO videotypes VALUES (4,'avi','',0,1);",
253 "INSERT INTO videotypes VALUES (5,'vob','Internal',0,0);",
254 "INSERT INTO videotypes VALUES (6,'mpeg','Internal',0,0);",
255 "INSERT INTO videotypes VALUES (8,'iso','Internal',0,0);",
256 "INSERT INTO videotypes VALUES (9,'img','Internal',0,0);",
257 "INSERT INTO videotypes VALUES (10,'mkv','Internal',0,0);",
258 "INSERT INTO videotypes VALUES (11,'mp4','Internal',0,0);",
259 "INSERT INTO videotypes VALUES (12,'m2ts','Internal',0,0);",
260 "INSERT INTO videotypes VALUES (13,'evo','Internal',0,0);",
261 "INSERT INTO videotypes VALUES (14,'divx','Internal',0,0);",
262 "INSERT INTO videotypes VALUES (15,'mov','Internal',0,0);",
263 "INSERT INTO videotypes VALUES (16,'qt','Internal',0,0);",
264 "INSERT INTO videotypes VALUES (17,'wmv','Internal',0,0);",
265 "INSERT INTO videotypes VALUES (18,'3gp','Internal',0,0);",
266 "INSERT INTO videotypes VALUES (19,'asf','Internal',0,0);",
267 "INSERT INTO videotypes VALUES (20,'ogg','Internal',0,0);",
268 "INSERT INTO videotypes VALUES (21,'ogm','Internal',0,0);",
269 "INSERT INTO videotypes VALUES (22,'flv','Internal',0,0);",
270 "INSERT INTO videotypes VALUES (23,'ogv','Internal',0,0);",
271 "INSERT INTO videotypes VALUES (25,'nut','Internal',0,0);",
272 "INSERT INTO videotypes VALUES (26,'mxf','Internal',0,0);",
273 "INSERT INTO videotypes VALUES (27,'m4v','Internal',0,0);",
274 "INSERT INTO videotypes VALUES (28,'rm','Internal',0,0);",
275 "INSERT INTO videotypes VALUES (29,'ts','Internal',0,0);",
276 "INSERT INTO videotypes VALUES (30,'swf','Internal',0,0);",
277 "INSERT INTO videotypes VALUES (31,'f4v','Internal',0,0);",
278 "INSERT INTO videotypes VALUES (32,'nuv','Internal',0,0);"
279 };
280 
281  QString dbver = "";
282  return performActualUpdate("MythVideo", MythVideoVersionName,
283  updates, finalVideoDatabaseVersion, dbver);
284 }
285 
287 {
288  QString dbver = gCoreContext->GetSetting("mythvideo.DBSchemaVer");
289  if (dbver == finalVideoDatabaseVersion)
290  {
291  return true;
292  }
293 
294  QString olddbver = gCoreContext->GetSetting("VideoDBSchemaVer");
295  QString dvddbver = gCoreContext->GetSetting("DVDDBSchemaVer");
296  if (dbver.isEmpty() && olddbver.isEmpty() && dvddbver.isEmpty())
297  {
298  if (!InitializeVideoSchema())
299  return false;
300  dbver = gCoreContext->GetSetting("mythvideo.DBSchemaVer");
301  }
302 
303  if (dbver.isEmpty() || dbver.toInt() < minimumVideoDatabaseVersion.toInt())
304  {
305  LOG(VB_GENERAL, LOG_ERR,
306  "Unrecognized video database schema version. "
307  "Unable to upgrade database.");
308  LOG(VB_GENERAL, LOG_ERR, QString("mythvideo.DBSchemaVer: '%1', "
309  "VideoDBSchemaVer: '%2', DVDDBSchemaVer: '%3'").arg(dbver)
310  .arg(olddbver).arg(dvddbver));
311  return false;
312  }
313 
314  if (dbver == "1016")
315  {
316  DBUpdates updates {
317 // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
318 "ALTER TABLE dvdbookmark"
319 " MODIFY serialid varbinary(16) NOT NULL default '',"
320 " MODIFY name varbinary(32) default NULL;",
321 "ALTER TABLE dvdinput"
322 " MODIFY v_format varbinary(16) default NULL;",
323 "ALTER TABLE dvdtranscode"
324 " MODIFY name varbinary(128) NOT NULL,"
325 " MODIFY codec varbinary(128) NOT NULL,"
326 " MODIFY codec_param varbinary(128) default NULL,"
327 " MODIFY tc_param varbinary(128) default NULL;",
328 "ALTER TABLE filemarkup"
329 " MODIFY filename blob NOT NULL;",
330 "ALTER TABLE videocast"
331 " MODIFY cast varbinary(128) NOT NULL;",
332 "ALTER TABLE videocategory"
333 " MODIFY category varbinary(128) NOT NULL;",
334 "ALTER TABLE videocountry"
335 " MODIFY country varbinary(128) NOT NULL;",
336 "ALTER TABLE videogenre"
337 " MODIFY genre varbinary(128) NOT NULL;",
338 "ALTER TABLE videometadata"
339 " MODIFY title varbinary(128) NOT NULL,"
340 " MODIFY director varbinary(128) NOT NULL,"
341 " MODIFY plot blob,"
342 " MODIFY rating varbinary(128) NOT NULL,"
343 " MODIFY inetref varbinary(255) NOT NULL,"
344 " MODIFY filename blob NOT NULL,"
345 " MODIFY coverfile blob NOT NULL,"
346 " MODIFY playcommand varbinary(255) default NULL;",
347 "ALTER TABLE videotypes"
348 " MODIFY extension varbinary(128) NOT NULL,"
349 " MODIFY playcommand varbinary(255) NOT NULL;"
350 };
351 
352  if (!performActualUpdate("MythVideo", MythVideoVersionName,
353  updates, "1017", dbver))
354  return false;
355  }
356 
357 
358  if (dbver == "1017")
359  {
360  DBUpdates updates {
361 // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
362 "ALTER TABLE dvdbookmark"
363 " DEFAULT CHARACTER SET default,"
364 " MODIFY serialid varchar(16) CHARACTER SET utf8 NOT NULL default '',"
365 " MODIFY name varchar(32) CHARACTER SET utf8 default NULL;",
366 "ALTER TABLE dvdinput"
367 " DEFAULT CHARACTER SET default,"
368 " MODIFY v_format varchar(16) CHARACTER SET utf8 default NULL;",
369 "ALTER TABLE dvdtranscode"
370 " DEFAULT CHARACTER SET default,"
371 " MODIFY name varchar(128) CHARACTER SET utf8 NOT NULL,"
372 " MODIFY codec varchar(128) CHARACTER SET utf8 NOT NULL,"
373 " MODIFY codec_param varchar(128) CHARACTER SET utf8 default NULL,"
374 " MODIFY tc_param varchar(128) CHARACTER SET utf8 default NULL;",
375 "ALTER TABLE filemarkup"
376 " DEFAULT CHARACTER SET default,"
377 " MODIFY filename text CHARACTER SET utf8 NOT NULL;",
378 "ALTER TABLE videocast"
379 " DEFAULT CHARACTER SET default,"
380 " MODIFY cast varchar(128) CHARACTER SET utf8 NOT NULL;",
381 "ALTER TABLE videocategory"
382 " DEFAULT CHARACTER SET default,"
383 " MODIFY category varchar(128) CHARACTER SET utf8 NOT NULL;",
384 "ALTER TABLE videocountry"
385 " DEFAULT CHARACTER SET default,"
386 " MODIFY country varchar(128) CHARACTER SET utf8 NOT NULL;",
387 "ALTER TABLE videogenre"
388 " DEFAULT CHARACTER SET default,"
389 " MODIFY genre varchar(128) CHARACTER SET utf8 NOT NULL;",
390 "ALTER TABLE videometadata"
391 " DEFAULT CHARACTER SET default,"
392 " MODIFY title varchar(128) CHARACTER SET utf8 NOT NULL,"
393 " MODIFY director varchar(128) CHARACTER SET utf8 NOT NULL,"
394 " MODIFY plot text CHARACTER SET utf8,"
395 " MODIFY rating varchar(128) CHARACTER SET utf8 NOT NULL,"
396 " MODIFY inetref varchar(255) CHARACTER SET utf8 NOT NULL,"
397 " MODIFY filename text CHARACTER SET utf8 NOT NULL,"
398 " MODIFY coverfile text CHARACTER SET utf8 NOT NULL,"
399 " MODIFY playcommand varchar(255) CHARACTER SET utf8 default NULL;",
400 "ALTER TABLE videometadatacast"
401 " DEFAULT CHARACTER SET default;",
402 "ALTER TABLE videometadatacountry"
403 " DEFAULT CHARACTER SET default;",
404 "ALTER TABLE videometadatagenre"
405 " DEFAULT CHARACTER SET default;",
406 "ALTER TABLE videotypes"
407 " DEFAULT CHARACTER SET default,"
408 " MODIFY extension varchar(128) CHARACTER SET utf8 NOT NULL,"
409 " MODIFY playcommand varchar(255) CHARACTER SET utf8 NOT NULL;"
410 };
411 
412  if (!performActualUpdate("MythVideo", MythVideoVersionName,
413  updates, "1018", dbver))
414  return false;
415  }
416 
417  if (dbver == "1018")
418  {
419  DBUpdates updates {
420  "DELETE FROM settings WHERE value="
421  "'MovieListCommandLine' AND data LIKE '%imdb%';",
422  "DELETE FROM settings WHERE value="
423  "'MovieDataCommandLine' AND data LIKE '%imdb%';",
424  "DELETE FROM settings WHERE value="
425  "'MoviePosterCommandLine' AND data LIKE '%imdb%';"
426  };
427  if (!performActualUpdate("MythVideo", MythVideoVersionName,
428  updates, "1019", dbver))
429  return false;
430  }
431 
432  if (dbver == "1019")
433  {
434  DBUpdates updates {
435  "ALTER TABLE videometadata ADD `trailer` TEXT;"
436  };
437  if (!performActualUpdate("MythVideo", MythVideoVersionName,
438  updates, "1020", dbver))
439  return false;
440  }
441 
442  if (dbver == "1020")
443  {
444  LOG(VB_GENERAL, LOG_NOTICE,
445  "Upgrading to MythVideo schema version 1021");
446 
447  AddFileType("mkv");
448  AddFileType("mp4");
449  AddFileType("m2ts");
450  AddFileType("evo");
451  AddFileType("divx");
452  AddFileType("mov");
453  AddFileType("qt");
454  AddFileType("wmv");
455  AddFileType("3gp");
456  AddFileType("asf");
457  AddFileType("ogg");
458  AddFileType("ogm");
459  AddFileType("flv");
460 
461  if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1021", dbver))
462  return false;
463  }
464 
465  if (dbver == "1021")
466  {
467  DBUpdates updates {
468  "ALTER TABLE videometadata ADD host text CHARACTER SET utf8 NOT NULL;"
469  };
470 
471  if (!performActualUpdate("MythVideo", MythVideoVersionName,
472  updates, "1022", dbver))
473  return false;
474  }
475 
476  if (dbver == "1022")
477  {
478  DBUpdates updates {
479  "ALTER TABLE videometadata ADD `screenshot` TEXT;",
480  "ALTER TABLE videometadata ADD `banner` TEXT;",
481  "ALTER TABLE videometadata ADD `fanart` TEXT;"
482  };
483  if (!performActualUpdate("MythVideo", MythVideoVersionName,
484  updates, "1023", dbver))
485  return false;
486  }
487 
488  if (dbver == "1023")
489  {
490  DBUpdates updates {
491  "ALTER TABLE videometadata ADD `subtitle` TEXT "
492  "NOT NULL AFTER `title`;",
493  "ALTER TABLE videometadata ADD `season` SMALLINT "
494  "UNSIGNED NOT NULL DEFAULT '0' AFTER `length`;",
495  "ALTER TABLE videometadata ADD `episode` SMALLINT "
496  "UNSIGNED NOT NULL DEFAULT '0' AFTER `season`;"
497  };
498  if (!performActualUpdate("MythVideo", MythVideoVersionName,
499  updates, "1024", dbver))
500  return false;
501  }
502 
503  if (dbver == "1024")
504  {
505  DBUpdates updates {
506  "ALTER TABLE videometadata ADD watched BOOL "
507  "NOT NULL DEFAULT 0 AFTER browse;"
508  };
509  if (!performActualUpdate("MythVideo", MythVideoVersionName,
510  updates, "1025", dbver))
511  return false;
512  }
513 
514  if (dbver == "1025")
515  {
516  DBUpdates updates {
517  "ALTER TABLE videometadata ADD `insertdate` TIMESTAMP "
518  "NULL DEFAULT CURRENT_TIMESTAMP AFTER `fanart`;"
519  };
520  if (!performActualUpdate("MythVideo", MythVideoVersionName,
521  updates, "1026", dbver))
522  return false;
523  }
524 
525  if (dbver == "1026")
526  {
527  DBUpdates updates {
528  "DELETE FROM keybindings "
529  " WHERE action = 'DELETE' AND context = 'Video';"
530  };
531  if (!performActualUpdate("MythVideo", MythVideoVersionName,
532  updates, "1027", dbver))
533  return false;
534  }
535 
536  if (dbver == "1027")
537  {
538  LOG(VB_GENERAL, LOG_NOTICE,
539  "Upgrading to MythVideo schema version 1028");
540  LOG(VB_GENERAL, LOG_INFO,
541  "Converting filenames in filemarkup table "
542  "from absolute to relative paths. This may take a long "
543  "time if you have a large number of MythVideo seektables.");
544 
545  bool ok = true;
547  MSqlQuery update(MSqlQuery::InitCon());
548 
549  query.prepare("SELECT DISTINCT filename FROM filemarkup;");
550  update.prepare("UPDATE filemarkup SET filename = :RELPATH "
551  " WHERE filename = :FULLPATH;");
552  if (query.exec())
553  {
554  QString origPath;
555  QString relPath;
556  while (query.next())
557  {
558  origPath = query.value(0).toString();
559  if (origPath.startsWith("dvd:"))
560  continue;
561 
562  relPath = StorageGroup::GetRelativePathname(origPath);
563  if ((!relPath.isEmpty()) &&
564  (relPath != origPath))
565  {
566  update.bindValue(":RELPATH", relPath);
567  update.bindValue(":FULLPATH", origPath);
568  if (!update.exec())
569  {
570  LOG(VB_GENERAL, LOG_ERR,
571  QString("ERROR converting '%1' to '%2' in "
572  "filemarkup table.")
573  .arg(origPath).arg(relPath));
574  ok = false;
575  }
576  }
577  }
578  }
579  else
580  ok = false;
581 
582  if (!ok)
583  return false;
584 
585  if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1028", dbver))
586  return false;
587  }
588 
589  if (dbver == "1028")
590  {
591  DBUpdates updates {
592  "ALTER TABLE videometadata ADD `releasedate` DATE "
593  "NOT NULL AFTER `year`;",
594  "ALTER TABLE videometadata ADD `homepage` TEXT "
595  "NOT NULL AFTER `inetref`;"
596  };
597  if (!performActualUpdate("MythVideo", MythVideoVersionName,
598  updates, "1029", dbver))
599  return false;
600  }
601 
602  if (dbver == "1029")
603  {
604  DBUpdates updates {
605  "ALTER TABLE videometadata ADD `hash` VARCHAR(128) "
606  "NOT NULL AFTER `filename`;"
607  };
608  if (!performActualUpdate("MythVideo", MythVideoVersionName,
609  updates, "1030", dbver))
610  return false;
611  }
612 
613  if (dbver == "1030")
614  {
615  UpdateHashes();
616  if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1031", dbver))
617  return false;
618  }
619 
620  if (dbver == "1031")
621  {
623  query.prepare("SHOW INDEX FROM videometadata");
624 
625  if (!query.exec())
626  {
627  MythDB::DBError("Unable to retrieve current indices on "
628  "videometadata.", query);
629  }
630  else
631  {
632  while (query.next())
633  {
634  QString index_name = query.value(2).toString();
635 
636  if ("title_2" == index_name)
637  {
638  MSqlQuery update(MSqlQuery::InitCon());
639  update.prepare("ALTER TABLE videometadata "
640  " DROP INDEX title_2");
641 
642  if (!update.exec())
643  {
644  MythDB::DBError("Unable to drop duplicate index "
645  "on videometadata. Ignoring.",
646  update);
647  }
648  break;
649  }
650  }
651  }
652 
653  if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1032", dbver))
654  return false;
655  }
656 
657  if (dbver == "1032")
658  {
659  DBUpdates updates {
660  // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
661  "CREATE TEMPORARY TABLE bad_videometadatacast"
662  " AS SELECT * FROM videometadatacast,",
663  "CREATE TEMPORARY TABLE bad_videometadatagenre"
664  " AS SELECT * FROM videometadatagenre,",
665  "CREATE TEMPORARY TABLE bad_videometadatacountry"
666  " AS SELECT * FROM videometadatacountry,",
667  "TRUNCATE TABLE videometadatacast,",
668  "TRUNCATE TABLE videometadatagenre,",
669  "TRUNCATE TABLE videometadatacountry,",
670  "INSERT videometadatacast SELECT idvideo,idcast"
671  " FROM bad_videometadatacast GROUP BY idvideo,idcast,",
672  "INSERT videometadatagenre SELECT idvideo,idgenre"
673  " FROM bad_videometadatagenre GROUP BY idvideo,idgenre,",
674  "INSERT videometadatacountry SELECT idvideo,idcountry"
675  " FROM bad_videometadatacountry GROUP BY idvideo,idcountry,",
676  "DROP TEMPORARY TABLE bad_videometadatacast,",
677  "DROP TEMPORARY TABLE bad_videometadatagenre,",
678  "DROP TEMPORARY TABLE bad_videometadatacountry,",
679  "ALTER TABLE videometadatacast ADD UNIQUE INDEX (`idvideo`,`idcast`),",
680  "ALTER TABLE videometadatagenre ADD UNIQUE INDEX (`idvideo`,`idgenre`),",
681  "ALTER TABLE videometadatacountry ADD UNIQUE INDEX (`idvideo`,`idcountry`);"
682  };
683  if (!performActualUpdate("MythVideo", MythVideoVersionName,
684  updates, "1033", dbver))
685  return false;
686 
687  dbver = "1033";
688  }
689 
690  if (dbver == "1033")
691  {
692  AddFileType("ogv");
693  AddFileType("BDMV");
694  AddFileType("nut");
695  AddFileType("mxf");
696  AddFileType("m4v");
697  AddFileType("rm");
698  AddFileType("ts");
699  AddFileType("swf");
700  AddFileType("f4v");
701  AddFileType("nuv");
702 
703  if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1034", dbver))
704  return false;
705  }
706 
707  if (dbver == "1034")
708  {
709  DBUpdates updates {
710  "ALTER TABLE videometadata ADD `tagline` VARCHAR (255) "
711  "AFTER `subtitle`;"
712  };
713 
714  if (!performActualUpdate("MythVideo", MythVideoVersionName,
715  updates, "1035", dbver))
716  return false;
717  }
718 
719  if (dbver == "1035")
720  {
721  DBUpdates updates {
722  "ALTER TABLE videometadata ADD processed BOOL "
723  "NOT NULL DEFAULT 0 AFTER watched;"
724  };
725  if (!performActualUpdate("MythVideo", MythVideoVersionName,
726  updates, "1036", dbver))
727  return false;
728  }
729 
730  if (dbver == "1036")
731  {
732  DBUpdates updates {
733  "ALTER TABLE videometadata ADD `studio` VARCHAR( 128 ) "
734  "AFTER `director`;"
735  };
736  if (!performActualUpdate("MythVideo", MythVideoVersionName,
737  updates, "1037", dbver))
738  return false;
739  }
740 
741  if (dbver == "1037")
742  {
743  DBUpdates updates {
744  "DELETE FROM videotypes WHERE extension = 'VIDEO_TS';",
745  "DELETE FROM videotypes WHERE extension = 'BDMV';"
746  };
747  if (!performActualUpdate("MythVideo", MythVideoVersionName,
748  updates, "1038", dbver))
749  return false;
750  }
751 
752  return true;
753 }
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
generate_file_url
QString generate_file_url(const QString &storage_group, const QString &host, const QString &path)
Definition: videoutils.h:65
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:203
InitializeVideoSchema
static bool InitializeVideoSchema(void)
Definition: videodbcheck.cpp:92
mythdb.h
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
arg
arg(title).arg(filename).arg(doDelete))
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
videodbcheck.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
UpdateHashes
static void UpdateHashes(void)
Definition: videodbcheck.cpp:45
AddFileType
static void AddFileType(const QString &extension, const QString &playCommand=QString("Internal"), bool ignored=false, bool useDefault=false)
Definition: videodbcheck.cpp:22
mythlogging.h
remotefile.h
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:178
minimumVideoDatabaseVersion
const QString minimumVideoDatabaseVersion
Definition: videodbcheck.cpp:18
mythdbcheck.h
RemoteFile::GetFileHash
static QString GetFileHash(const QString &url)
Definition: remotefile.cpp:553
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:637
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
StorageGroup::GetRelativePathname
static QString GetRelativePathname(const QString &filename)
Returns the relative pathname of a file by comparing the filename against all Storage Group directori...
Definition: storagegroup.cpp:420
UpdateDBVersionNumber
bool UpdateDBVersionNumber(const QString &component, const QString &versionkey, const QString &newnumber, QString &dbver)
Updates the schema version stored in the database.
Definition: dbcheckcommon.cpp:28
performActualUpdate
bool performActualUpdate(const QString &component, const QString &versionkey, const DBUpdates &updates, const QString &version, QString &dbver)
Definition: dbcheckcommon.cpp:113
mythmiscutil.h
mythcorecontext.h
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
finalVideoDatabaseVersion
const QString finalVideoDatabaseVersion
Definition: videodbcheck.cpp:19
doUpgradeVideoDatabaseSchema
bool doUpgradeVideoDatabaseSchema(void)
Definition: videodbcheck.cpp:286
DBUpdates
std::vector< std::string > DBUpdates
Definition: mythdbcheck.h:9
FileHash
QString FileHash(const QString &filename)
Definition: mythmiscutil.cpp:594
query
MSqlQuery query(MSqlQuery::InitCon())
videoutils.h
MythVideoVersionName
const QString MythVideoVersionName
Definition: videodbcheck.cpp:20
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:919
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808