MythTV master
v2video.cpp
Go to the documentation of this file.
1// MythTV
9#include "libmythbase/mythversion.h"
17
18// MythBackend
19#include "v2artworkInfoList.h"
20#include "v2castMemberList.h"
21#include "v2genreList.h"
22#include "v2serviceUtil.h"
23#include "v2video.h"
24
25
26// This will be initialised in a thread safe manner on first use
28 (VIDEO_HANDLE, V2Video::staticMetaObject, &V2Video::RegisterCustomTypes))
29
31{
32 qRegisterMetaType<V2VideoMetadataInfo*>("V2VideoMetadataInfo");
33 qRegisterMetaType<V2VideoMetadataInfoList*>("V2VideoMetadataInfoList");
34 qRegisterMetaType<V2VideoLookupList*>("V2VideoLookupList");
35 qRegisterMetaType<V2BlurayInfo*>("V2BlurayInfo");
36 qRegisterMetaType<V2VideoStreamInfoList*>("V2VideoStreamInfoList");
37 qRegisterMetaType<V2VideoStreamInfo*>("V2VideoStreamInfo");
38 qRegisterMetaType<V2ArtworkInfoList*>("V2ArtworkInfoList");
39 qRegisterMetaType<V2ArtworkInfo*>("V2ArtworkInfo");
40 qRegisterMetaType<V2CastMemberList*>("V2CastMemberList");
41 qRegisterMetaType<V2CastMember*>("V2CastMember");
42 qRegisterMetaType<V2GenreList*>("V2GenreList");
43 qRegisterMetaType<V2Genre*>("V2Genre");
44 qRegisterMetaType<V2VideoLookupList*>("V2VideoLookupList");
45 qRegisterMetaType<V2VideoLookup*>("V2VideoLookup");
46 qRegisterMetaType<V2ArtworkItem*>("V2ArtworkItem");
47 qRegisterMetaType<V2CutList*>("V2CutList");
48 qRegisterMetaType<V2Cutting*>("V2Cutting");
49 qRegisterMetaType<V2VideoCategory*>("V2VideoCategory");
50 qRegisterMetaType<V2VideoCategoryList*>("V2VideoCategoryList");
51}
52
54 : MythHTTPService(s_service)
55{
56}
57
59{
62
63 if ( !metadata )
64 throw( QString( "No metadata found for selected ID!." ));
65
66 auto *pVideoMetadataInfo = new V2VideoMetadataInfo();
67
68 V2FillVideoMetadataInfo ( pVideoMetadataInfo, metadata, true );
69
70 return pVideoMetadataInfo;
71}
72
74{
77 QScopedPointer<VideoMetadataListManager> mlm(new VideoMetadataListManager());
78 mlm->setList(videolist);
79 VideoMetadataListManager::VideoMetadataPtr metadata = mlm->byFilename(FileName);
80
81 if ( !metadata )
82 throw( QString( "No metadata found for selected filename!." ));
83
84 auto *pVideoMetadataInfo = new V2VideoMetadataInfo();
85
86 V2FillVideoMetadataInfo ( pVideoMetadataInfo, metadata, true );
87
88 return pVideoMetadataInfo;
89}
90
91
93// Get bookmark of a video as a frame number.
95
97{
99
100 query.prepare("SELECT filename "
101 "FROM videometadata "
102 "WHERE intid = :ID ");
103 query.bindValue(":ID", Id);
104
105 if (!query.exec())
106 {
107 MythDB::DBError("V2Video::GetSavedBookmark", query);
108 return 0;
109 }
110
111 QString fileName;
112
113 if (query.next())
114 fileName = query.value(0).toString();
115 else
116 {
117 LOG(VB_GENERAL, LOG_ERR, QString("V2Video/GetSavedBookmark Video id %1 Not found.").arg(Id));
118 return -1;
119 }
120
121 ProgramInfo pi(fileName,
122 nullptr, // _plot,
123 nullptr, // _title,
124 nullptr, // const QString &_sortTitle,
125 nullptr, // const QString &_subtitle,
126 nullptr, // const QString &_sortSubtitle,
127 nullptr, // const QString &_director,
128 0, // int _season,
129 0, // int _episode,
130 nullptr, // const QString &_inetref,
131 0min, // uint _length_in_minutes,
132 0, // uint _year,
133 nullptr); //const QString &_programid);
134
135 long ret = pi.QueryBookmark();
136 return ret;
137}
138
140// Get last play pos of a video as a frame number.
142
144{
146
147 query.prepare("SELECT filename "
148 "FROM videometadata "
149 "WHERE intid = :ID ");
150 query.bindValue(":ID", Id);
151
152 if (!query.exec())
153 {
154 MythDB::DBError("V2Video::GetLastPlayPos", query);
155 return 0;
156 }
157
158 QString fileName;
159
160 if (query.next())
161 fileName = query.value(0).toString();
162 else
163 {
164 LOG(VB_GENERAL, LOG_ERR, QString("V2Video/GetLastPlayPos Video id %1 Not found.").arg(Id));
165 return -1;
166 }
167
168 ProgramInfo pi(fileName,
169 nullptr, // _plot,
170 nullptr, // _title,
171 nullptr, // const QString &_sortTitle,
172 nullptr, // const QString &_subtitle,
173 nullptr, // const QString &_sortSubtitle,
174 nullptr, // const QString &_director,
175 0, // int _season,
176 0, // int _episode,
177 nullptr, // const QString &_inetref,
178 0min, // uint _length_in_minutes,
179 0, // uint _year,
180 nullptr); //const QString &_programid);
181
182 long ret = pi.QueryLastPlayPos();
183 return ret;
184}
185
186
187// If CollapseSubDirs is true, then files in subdirectories are not returned.
188// Instead, one row is returned for each subdirectory, with the full
189// directory name in FileName and the lowest part of the directory name
190// in Title. These directories are returned at the beginning of the list.
191//
192// Example: If the database has these files:
193// one.mkv
194// dir1/two.mkv
195// dir1/dir2/two.mkv
196//
197// With no Folder name and CollapseSubDirs=true, you get
198// one.mkv
199// dir1 Title=dir1
200//
201// With Folder=dir1 and CollapseSubDirs=true, you get
202// dir1/two.mkv
203// dir1/dir2 Title=dir2
204
206 const QString &Sort,
207 const QString &TitleRegEx,
208 int Category,
209 bool bDescending,
210 int nStartIndex,
211 int nCount,
212 bool CollapseSubDirs )
213{
214 QString fields = "title,director,studio,plot,rating,year,releasedate,"
215 "userrating,length,playcount,filename,hash,showlevel,"
216 "coverfile,inetref,collectionref,homepage,childid,browse,watched,"
217 "playcommand,category,intid,trailer,screenshot,banner,fanart,"
218 "subtitle,tagline,season,episode,host,insertdate,processed,contenttype";
219
220 QStringList sortFields = fields.split(',');
221
223
224 QString sql = "";
225 QString folder;
226 QStringList bindValues;
227
228 if (!Folder.isEmpty())
229 {
230 if (Folder.endsWith('/'))
231 folder = Folder;
232 else
233 folder = Folder + "/";
234 sql.append(" WHERE filename LIKE :BIND0 ");
235 bindValues.append(folder + "%");
236 }
237 if (!TitleRegEx.isEmpty())
238 {
239 if (bindValues.empty())
240 {
241 sql.append(" WHERE ");
242 }
243 else
244 {
245 sql.append(" AND ");
246 }
247 sql.append(" title REGEXP :BIND" + QString::number(bindValues.size()) + " ");
248 bindValues.append(TitleRegEx);
249 }
250 if (HAS_PARAMv2("Category") && Category != -1)
251 {
252 if (bindValues.empty())
253 {
254 sql.append(" WHERE ");
255 }
256 else
257 {
258 sql.append(" AND ");
259 }
260 sql.append(" category = :BIND" + QString::number(bindValues.size()) + " ");
261 bindValues.append( QString::number(Category) );
262 }
263 sql.append(" ORDER BY ");
264 QString defSeq = " ASC";
265 if (bDescending)
266 defSeq = " DESC";
267
268 QStringList sortList = Sort.toLower().split(',',Qt::SkipEmptyParts);
269 bool next = false;
270 for (const auto & item : std::as_const(sortList))
271 {
272 QStringList partList = item.split(' ',Qt::SkipEmptyParts);
273 if (partList.empty())
274 continue;
275 QString sort = partList[0];
276 if (sort == "added")
277 sort = "insertdate";
278 else if (sort == "released")
279 sort = "releasedate";
280 if (sortFields.contains(sort))
281 {
282 if (next)
283 sql.append(",");
284 if (sort == "title")
285 {
286 std::shared_ptr<MythSortHelper>sh = getMythSortHelper();
287 QString prefixes = sh->getPrefixes();
288 sort = "REGEXP_REPLACE(title,'" + prefixes + "','')";
289 }
290 else if (sort == "subtitle")
291 {
292 std::shared_ptr<MythSortHelper>sh = getMythSortHelper();
293 QString prefixes = sh->getPrefixes();
294 sort = "REGEXP_REPLACE(subtitle,'" + prefixes + "','')";
295 }
296 sql.append(sort);
297 if (partList.length() > 1 && partList[1].compare("DESC",Qt::CaseInsensitive) == 0)
298 sql.append(" DESC");
299 else if (partList.length() > 1 && partList[1].compare("ASC",Qt::CaseInsensitive) == 0)
300 sql.append(" ASC");
301 else
302 sql.append(defSeq);
303 next = true;
304 }
305 }
306 if (!next)
307 {
308 sql.append("intid");
309 sql.append(defSeq);
310 }
311
312 VideoMetadataListManager::loadAllFromDatabase(videolist, sql, bindValues);
313 std::vector<VideoMetadataListManager::VideoMetadataPtr> videos(videolist.begin(), videolist.end());
314
315 // ----------------------------------------------------------------------
316 // Build Response
317 // ----------------------------------------------------------------------
318
319 auto *pVideoMetadataInfos = new V2VideoMetadataInfoList();
320 QMap<QString, QString> map;
321 int folderlen = folder.length();
322
323 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, (int)videos.size() ) : 0;
324 int selectedCount = 0;
325 int totalCount = 0;
326 QString dir;
327
328 // Make directory list
329 if (CollapseSubDirs)
330 {
331 for( const auto& metadata : videos )
332 {
333 if (!metadata)
334 break;
335 QString fnPart = metadata->GetFilename().mid(folderlen);
336 int slashPos = fnPart.indexOf('/',1);
337 if (slashPos >= 0)
338 {
339 dir = fnPart.mid(0, slashPos);
340 QString key = dir.toLower();
341 std::shared_ptr<MythSortHelper>sh = getMythSortHelper();
342 key = sh->doTitle(key);
343 if (!map.contains(key))
344 map.insert(key, dir);
345 }
346 }
347 // Insert directory entries at the front of the list, ordered ascending
348 // or descending, depending on the value of bDescending
349 QMapIterator<QString, QString> it(map);
350 if (bDescending)
351 it.toBack();
352
353 while (bDescending? it.hasPrevious() : it.hasNext())
354 {
355 if (bDescending)
356 it.previous();
357 else
358 it.next();
359 if (totalCount >= nStartIndex && (nCount == 0 || selectedCount < nCount)) {
360 V2VideoMetadataInfo *pVideoMetadataInfo =
361 pVideoMetadataInfos->AddNewVideoMetadataInfo();
362 pVideoMetadataInfo->setContentType("DIRECTORY");
363 pVideoMetadataInfo->setFileName(folder + it.value());
364 pVideoMetadataInfo->setTitle(it.value());
365 selectedCount++;
366 }
367 totalCount++;
368 }
369 }
370
371 for( const auto& metadata : videos )
372 {
373 if (!metadata)
374 break;
375
376 if (CollapseSubDirs)
377 {
378 QString fnPart = metadata->GetFilename().mid(folderlen);
379 int slashPos = fnPart.indexOf('/',1);
380 if (slashPos >= 0)
381 continue;
382 }
383
384 if (totalCount >= nStartIndex && (nCount == 0 || selectedCount < nCount)) {
385 V2VideoMetadataInfo *pVideoMetadataInfo = pVideoMetadataInfos->AddNewVideoMetadataInfo();
386 V2FillVideoMetadataInfo ( pVideoMetadataInfo, metadata, true );
387 selectedCount++;
388 }
389 totalCount++;
390 }
391
392 int curPage = 0;
393 int totalPages = 0;
394 if (nCount == 0)
395 totalPages = 1;
396 else
397 totalPages = (int)ceil((float)totalCount / nCount);
398
399 if (totalPages == 1)
400 curPage = 1;
401 else
402 {
403 curPage = (int)ceil((float)nStartIndex / nCount) + 1;
404 }
405
406 pVideoMetadataInfos->setStartIndex ( nStartIndex );
407 pVideoMetadataInfos->setCount ( selectedCount );
408 pVideoMetadataInfos->setCurrentPage ( curPage );
409 pVideoMetadataInfos->setTotalPages ( totalPages );
410 pVideoMetadataInfos->setTotalAvailable( totalCount );
411 pVideoMetadataInfos->setAsOf ( MythDate::current() );
412 pVideoMetadataInfos->setVersion ( MYTH_BINARY_VERSION );
413 pVideoMetadataInfos->setProtoVer ( MYTH_PROTO_VERSION );
414
415 return pVideoMetadataInfos;
416}
417
418
420 const QString &Subtitle,
421 const QString &Inetref,
422 int Season,
423 int Episode,
424 const QString &GrabberType,
425 bool AllowGeneric )
426{
427 auto *pVideoLookups = new V2VideoLookupList();
428
430
431 auto *factory = new MetadataFactory(nullptr);
432
433 if (factory)
434 {
435 list = factory->SynchronousLookup(Title, Subtitle,
436 Inetref, Season, Episode,
437 GrabberType, AllowGeneric);
438 }
439
440 if ( list.empty() )
441 return pVideoLookups;
442
443 //MetadataLookupList is a reference counted list.
444 //it will delete all its content at its end of life
445 for(const auto & lookup : std::as_const(list))
446 {
447 V2VideoLookup *pVideoLookup = pVideoLookups->AddNewVideoLookup();
448
449 if (lookup)
450 {
451 pVideoLookup->setTitle(lookup->GetTitle());
452 pVideoLookup->setSubTitle(lookup->GetSubtitle());
453 pVideoLookup->setSeason(lookup->GetSeason());
454 pVideoLookup->setEpisode(lookup->GetEpisode());
455 pVideoLookup->setYear(lookup->GetYear());
456 pVideoLookup->setTagline(lookup->GetTagline());
457 pVideoLookup->setDescription(lookup->GetDescription());
458 pVideoLookup->setCertification(lookup->GetCertification());
459 pVideoLookup->setInetref(lookup->GetInetref());
460 pVideoLookup->setCollectionref(lookup->GetCollectionref());
461 pVideoLookup->setHomePage(lookup->GetHomepage());
462#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
463 pVideoLookup->setReleaseDate(
464 QDateTime(lookup->GetReleaseDate(),
465 QTime(0,0),Qt::LocalTime).toUTC());
466#else
467 pVideoLookup->setReleaseDate(
468 QDateTime(lookup->GetReleaseDate(),
469 QTime(0,0),
470 QTimeZone(QTimeZone::LocalTime)).toUTC());
471#endif
472 pVideoLookup->setUserRating(lookup->GetUserRating());
473 pVideoLookup->setLength(lookup->GetRuntime().count());
474 pVideoLookup->setLanguage(lookup->GetLanguage());
475 pVideoLookup->setCountries(lookup->GetCountries());
476 pVideoLookup->setPopularity(lookup->GetPopularity());
477 pVideoLookup->setBudget(lookup->GetBudget());
478 pVideoLookup->setRevenue(lookup->GetRevenue());
479 pVideoLookup->setIMDB(lookup->GetIMDB());
480 pVideoLookup->setTMSRef(lookup->GetTMSref());
481
482 ArtworkList coverartlist = lookup->GetArtwork(kArtworkCoverart);
483 ArtworkList::iterator c;
484 for (c = coverartlist.begin(); c != coverartlist.end(); ++c)
485 {
486 V2ArtworkItem *art = pVideoLookup->AddNewArtwork();
487 art->setType("coverart");
488 art->setUrl((*c).url);
489 art->setThumbnail((*c).thumbnail);
490 art->setWidth((*c).width);
491 art->setHeight((*c).height);
492 }
493 ArtworkList fanartlist = lookup->GetArtwork(kArtworkFanart);
494 ArtworkList::iterator f;
495 for (f = fanartlist.begin(); f != fanartlist.end(); ++f)
496 {
497 V2ArtworkItem *art = pVideoLookup->AddNewArtwork();
498 art->setType("fanart");
499 art->setUrl((*f).url);
500 art->setThumbnail((*f).thumbnail);
501 art->setWidth((*f).width);
502 art->setHeight((*f).height);
503 }
504 ArtworkList bannerlist = lookup->GetArtwork(kArtworkBanner);
505 ArtworkList::iterator b;
506 for (b = bannerlist.begin(); b != bannerlist.end(); ++b)
507 {
508 V2ArtworkItem *art = pVideoLookup->AddNewArtwork();
509 art->setType("banner");
510 art->setUrl((*b).url);
511 art->setThumbnail((*b).thumbnail);
512 art->setWidth((*b).width);
513 art->setHeight((*b).height);
514 }
515 ArtworkList screenshotlist = lookup->GetArtwork(kArtworkScreenshot);
516 ArtworkList::iterator s;
517 for (s = screenshotlist.begin(); s != screenshotlist.end(); ++s)
518 {
519 V2ArtworkItem *art = pVideoLookup->AddNewArtwork();
520 art->setType("screenshot");
521 art->setUrl((*s).url);
522 art->setThumbnail((*s).thumbnail);
523 art->setWidth((*s).width);
524 art->setHeight((*s).height);
525 }
526 }
527 }
528
529 pVideoLookups->setCount ( list.count() );
530 pVideoLookups->setAsOf ( MythDate::current() );
531 pVideoLookups->setVersion ( MYTH_BINARY_VERSION );
532 pVideoLookups->setProtoVer ( MYTH_PROTO_VERSION );
533
534 delete factory;
535
536 return pVideoLookups;
537}
538
539
541{
542 bool bResult = false;
543
546 QScopedPointer<VideoMetadataListManager> mlm(new VideoMetadataListManager());
547 mlm->setList(videolist);
548 VideoMetadataListManager::VideoMetadataPtr metadata = mlm->byID(Id);
549
550 if (metadata)
551 bResult = metadata->DeleteFromDatabase();
552
553 return bResult;
554}
555
556bool V2Video::AddVideo( const QString &sFileName,
557 const QString &sHostName )
558{
559 if ( sHostName.isEmpty() )
560 throw( QString( "Host not provided! Local storage is deprecated and "
561 "is not supported by the API." ));
562
563 if ( sFileName.isEmpty() ||
564 (sFileName.contains("/../")) ||
565 (sFileName.startsWith("../")) )
566 {
567 throw( QString( "Filename not provided, or fails sanity checks!" ));
568 }
569
570 StorageGroup sgroup("Videos", sHostName);
571
572 QString fullname = sgroup.FindFile(sFileName);
573
574 if ( !QFile::exists(fullname) )
575 throw( QString( "Provided filename does not exist!" ));
576
577 QString hash = FileHash(fullname);
578
579 if (hash == "NULL")
580 {
581 LOG(VB_GENERAL, LOG_ERR, "Video Hash Failed. Unless this is a DVD or "
582 "Blu-ray, something has probably gone wrong.");
583 hash = "";
584 }
585
586 VideoMetadata newFile(sFileName, QString(), hash,
592 QString(), QString(), QString(), QString(),
593 QString(), VIDEO_YEAR_DEFAULT,
594 QDate::fromString("0000-00-00","YYYY-MM-DD"),
595 VIDEO_INETREF_DEFAULT, 0, QString(),
597 0.0, VIDEO_RATING_DEFAULT, 0, 0,
598 0, 0,
599 MythDate::current().date(), 0,
601
602 newFile.SetHost(sHostName);
603 newFile.SaveToDatabase();
604
605 return true;
606}
607
609//
611
613 bool bWatched )
614{
617 QScopedPointer<VideoMetadataListManager> mlm(new VideoMetadataListManager());
618 mlm->setList(videolist);
619 VideoMetadataListManager::VideoMetadataPtr metadata = mlm->byID(nId);
620
621 if ( !metadata )
622 return false;
623
624 metadata->SetWatched(bWatched);
625 metadata->UpdateDatabase();
626
627 return true;
628}
629
631 const QString &sTitle,
632 const QString &sSubTitle,
633 const QString &sTagLine,
634 const QString &sDirector,
635 const QString &sStudio,
636 const QString &sPlot,
637 const QString &sRating,
638 const QString &sInetref,
639 int nCollectionRef,
640 const QString &sHomePage,
641 int nYear,
642 QDate sReleasedate,
643 float fUserRating,
644 int nLength,
645 int nPlayCount,
646 int nSeason,
647 int nEpisode,
648 int nShowLevel,
649 const QString &sFileName,
650 const QString &sHash,
651 const QString &sCoverFile,
652 int nChildID,
653 bool bBrowse,
654 bool bWatched,
655 bool bProcessed,
656 const QString &sPlayCommand,
657 int nCategory,
658 const QString &sTrailer,
659 const QString &sHost,
660 const QString &sScreenshot,
661 const QString &sBanner,
662 const QString &sFanart,
663 QDate sInsertDate,
664 const QString &sContentType,
665 const QString &sGenres,
666 const QString &sCast,
667 const QString &sCountries)
668{
669 bool update_required = false;
672 QScopedPointer<VideoMetadataListManager> mlm(new VideoMetadataListManager());
673 mlm->setList(videolist);
674 VideoMetadataListManager::VideoMetadataPtr metadata = mlm->byID(nId);
675
676 if (!metadata)
677 {
678 LOG(VB_GENERAL, LOG_ERR, QString("UpdateVideoMetadata: Id=%1 not found")
679 .arg(nId));
680 return false;
681 }
682
683 if (HAS_PARAMv2("Title"))
684 {
685 metadata->SetTitle(sTitle);
686 update_required = true;
687 }
688
689 if (HAS_PARAMv2("SubTitle"))
690 {
691 metadata->SetSubtitle(sSubTitle);
692 update_required = true;
693 }
694
695 if (HAS_PARAMv2("TagLine"))
696 {
697 metadata->SetTagline(sTagLine);
698 update_required = true;
699 }
700
701 if (HAS_PARAMv2("Director"))
702 {
703 metadata->SetDirector(sDirector);
704 update_required = true;
705 }
706
707 if (HAS_PARAMv2("Studio"))
708 {
709 metadata->SetStudio(sStudio);
710 update_required = true;
711 }
712
713 if (HAS_PARAMv2("Plot"))
714 {
715 metadata->SetPlot(sPlot);
716 update_required = true;
717 }
718
719 if (HAS_PARAMv2("UserRating"))
720 {
721 metadata->SetUserRating(fUserRating);
722 update_required = true;
723 }
724
725 if (HAS_PARAMv2("Inetref"))
726 {
727 metadata->SetInetRef(sInetref);
728 update_required = true;
729 }
730
731 if (HAS_PARAMv2("CollectionRef"))
732 {
733 metadata->SetCollectionRef(nCollectionRef);
734 update_required = true;
735 }
736
737 if (HAS_PARAMv2("HomePage"))
738 {
739 metadata->SetHomepage(sHomePage);
740 update_required = true;
741 }
742
743 if (HAS_PARAMv2("Year"))
744 {
745 metadata->SetYear(nYear);
746 update_required = true;
747 }
748
749 if (HAS_PARAMv2("ReleaseDate"))
750 {
751 metadata->SetReleaseDate(sReleasedate);
752 update_required = true;
753 }
754
755 if (HAS_PARAMv2("Rating"))
756 {
757 metadata->SetRating(sRating);
758 update_required = true;
759 }
760
761 if (HAS_PARAMv2("Length"))
762 {
763 metadata->SetLength(std::chrono::minutes(nLength));
764 update_required = true;
765 }
766
767 if (HAS_PARAMv2("PlayCount"))
768 {
769 metadata->SetPlayCount(nPlayCount);
770 update_required = true;
771 }
772
773 if (HAS_PARAMv2("Season"))
774 {
775 metadata->SetSeason(nSeason);
776 update_required = true;
777 }
778
779 if (HAS_PARAMv2("Episode"))
780 {
781 metadata->SetEpisode(nEpisode);
782 update_required = true;
783 }
784
785 if (HAS_PARAMv2("ShowLevel"))
786 {
787 metadata->SetShowLevel(ParentalLevel::Level(nShowLevel));
788 update_required = true;
789 }
790
791 if (HAS_PARAMv2("FileName"))
792 {
793 metadata->SetFilename(sFileName);
794 update_required = true;
795 }
796
797 if (HAS_PARAMv2("Hash"))
798 {
799 metadata->SetHash(sHash);
800 update_required = true;
801 }
802
803 if (HAS_PARAMv2("CoverFile"))
804 {
805 metadata->SetCoverFile(sCoverFile);
806 update_required = true;
807 }
808
809 if (HAS_PARAMv2("ChildID"))
810 {
811 metadata->SetChildID(nChildID);
812 update_required = true;
813 }
814
815 if (HAS_PARAMv2("Browse"))
816 {
817 metadata->SetBrowse(bBrowse);
818 update_required = true;
819 }
820
821 if (HAS_PARAMv2("Watched"))
822 {
823 metadata->SetWatched(bWatched);
824 update_required = true;
825 }
826
827 if (HAS_PARAMv2("Processed"))
828 {
829 metadata->SetProcessed(bProcessed);
830 update_required = true;
831 }
832
833 if (HAS_PARAMv2("PlayCommand"))
834 {
835 metadata->SetPlayCommand(sPlayCommand);
836 update_required = true;
837 }
838
839 if (HAS_PARAMv2("Category"))
840 {
841 metadata->SetCategoryID(nCategory);
842 update_required = true;
843 }
844
845 if (HAS_PARAMv2("Trailer"))
846 {
847 metadata->SetTrailer(sTrailer);
848 update_required = true;
849 }
850
851 if (HAS_PARAMv2("Host"))
852 {
853 metadata->SetHost(sHost);
854 update_required = true;
855 }
856
857 if (HAS_PARAMv2("Screenshot"))
858 {
859 metadata->SetScreenshot(sScreenshot);
860 update_required = true;
861 }
862
863 if (HAS_PARAMv2("Banner"))
864 {
865 metadata->SetBanner(sBanner);
866 update_required = true;
867 }
868
869 if (HAS_PARAMv2("Fanart"))
870 {
871 metadata->SetFanart(sFanart);
872 update_required = true;
873 }
874
875 if (HAS_PARAMv2("InsertDate"))
876 {
877 metadata->SetInsertdate(sInsertDate);
878 update_required = true;
879 }
880
881 if (HAS_PARAMv2("ContentType"))
882 {
883 // valid values for ContentType are 'MOVIE','TELEVISION','ADULT','MUSICVIDEO','HOMEVIDEO'
884 VideoContentType contentType = kContentUnknown;
885 if (sContentType == "MOVIE")
886 contentType = kContentMovie;
887
888 if (sContentType == "TELEVISION")
889 contentType = kContentTelevision;
890
891 if (sContentType == "ADULT")
892 contentType = kContentAdult;
893
894 if (sContentType == "MUSICVIDEO")
895 contentType = kContentMusicVideo;
896
897 if (sContentType == "HOMEVIDEO")
898 contentType = kContentHomeMovie;
899
900 if (contentType != kContentUnknown)
901 {
902 metadata->SetContentType(contentType);
903 update_required = true;
904 }
905 else
906 {
907 LOG(VB_GENERAL, LOG_ERR, QString("UpdateVideoMetadata: Ignoring unknown ContentType: %1").arg(sContentType));
908 }
909 }
910
911 if (HAS_PARAMv2("Genres"))
912 {
914 QStringList genresList = sGenres.split(',', Qt::SkipEmptyParts);
915 std::transform(genresList.cbegin(), genresList.cend(), std::back_inserter(genres),
916 [](const QString& name)
917 {return VideoMetadata::genre_list::value_type(-1, name.simplified());} );
918
919 metadata->SetGenres(genres);
920 update_required = true;
921 }
922
923 if (HAS_PARAMv2("Cast"))
924 {
926 QStringList castList = sCast.split(',', Qt::SkipEmptyParts);
927 std::transform(castList.cbegin(), castList.cend(), std::back_inserter(cast),
928 [](const QString& name)
929 {return VideoMetadata::cast_list::value_type(-1, name.simplified());} );
930
931 metadata->SetCast(cast);
932 update_required = true;
933 }
934
935 if (HAS_PARAMv2("Countries"))
936 {
938 QStringList countryList = sCountries.split(',', Qt::SkipEmptyParts);
939 std::transform(countryList.cbegin(), countryList.cend(), std::back_inserter(countries),
940 [](const QString& name)
941 {return VideoMetadata::country_list::value_type(-1, name.simplified());} );
942
943 metadata->SetCountries(countries);
944 update_required = true;
945 }
946
947 if (update_required)
948 metadata->UpdateDatabase();
949
950 return true;
951}
952
954// Set bookmark of a video as a frame number.
956
957bool V2Video::SetSavedBookmark( int Id, long Offset )
958{
960
961 query.prepare("SELECT filename "
962 "FROM videometadata "
963 "WHERE intid = :ID ");
964 query.bindValue(":ID", Id);
965
966 if (!query.exec())
967 {
968 MythDB::DBError("Video::SetSavedBookmark", query);
969 return false;
970 }
971
972 QString fileName;
973
974 if (query.next())
975 fileName = query.value(0).toString();
976 else
977 {
978 LOG(VB_GENERAL, LOG_ERR, QString("Video/SetSavedBookmark Video id %1 Not found.").arg(Id));
979 return false;
980 }
981
982 ProgramInfo pi(fileName,
983 nullptr, // _plot,
984 nullptr, // _title,
985 nullptr, // const QString &_sortTitle,
986 nullptr, // const QString &_subtitle,
987 nullptr, // const QString &_sortSubtitle,
988 nullptr, // const QString &_director,
989 0, // int _season,
990 0, // int _episode,
991 nullptr, // const QString &_inetref,
992 0min, // uint _length_in_minutes,
993 0, // uint _year,
994 nullptr); //const QString &_programid);
995
996 pi.SaveBookmark(Offset);
997 return true;
998}
999
1001// Set bookmark of a video as a frame number.
1003
1004bool V2Video::SetLastPlayPos( int Id, long Offset )
1005{
1007
1008 query.prepare("SELECT filename "
1009 "FROM videometadata "
1010 "WHERE intid = :ID ");
1011 query.bindValue(":ID", Id);
1012
1013 if (!query.exec())
1014 {
1015 MythDB::DBError("Video::SetLastPlayPos", query);
1016 return false;
1017 }
1018
1019 QString fileName;
1020
1021 if (query.next())
1022 fileName = query.value(0).toString();
1023 else
1024 {
1025 LOG(VB_GENERAL, LOG_ERR, QString("Video/SetLastPlayPos Video id %1 Not found.").arg(Id));
1026 return false;
1027 }
1028
1029 ProgramInfo pi(fileName,
1030 nullptr, // _plot,
1031 nullptr, // _title,
1032 nullptr, // const QString &_sortTitle,
1033 nullptr, // const QString &_subtitle,
1034 nullptr, // const QString &_sortSubtitle,
1035 nullptr, // const QString &_director,
1036 0, // int _season,
1037 0, // int _episode,
1038 nullptr, // const QString &_inetref,
1039 0min, // uint _length_in_minutes,
1040 0, // uint _year,
1041 nullptr); //const QString &_programid);
1042
1043 pi.SaveLastPlayPos(Offset);
1044 return true;
1045}
1046
1047
1048V2BlurayInfo* V2Video::GetBluray( const QString &sPath )
1049{
1050 QString path = sPath;
1051
1052 if (sPath.isEmpty())
1053 path = gCoreContext->GetSetting( "BluRayMountpoint", "/media/cdrom");
1054
1055 LOG(VB_GENERAL, LOG_NOTICE,
1056 QString("Parsing Blu-ray at path: %1 ").arg(path));
1057
1058 auto *bdmeta = new BlurayMetadata(path);
1059
1060 if ( !bdmeta )
1061 throw( QString( "Unable to open Blu-ray Metadata Parser!" ));
1062
1063 if ( !bdmeta->OpenDisc() )
1064 throw( QString( "Unable to open Blu-ray Disc/Path!" ));
1065
1066 if ( !bdmeta->ParseDisc() )
1067 throw( QString( "Unable to parse metadata from Blu-ray Disc/Path!" ));
1068
1069 auto *pBlurayInfo = new V2BlurayInfo();
1070
1071 pBlurayInfo->setPath(path);
1072 pBlurayInfo->setTitle(bdmeta->GetTitle());
1073 pBlurayInfo->setAltTitle(bdmeta->GetAlternateTitle());
1074 pBlurayInfo->setDiscLang(bdmeta->GetDiscLanguage());
1075 pBlurayInfo->setDiscNum(bdmeta->GetCurrentDiscNumber());
1076 pBlurayInfo->setTotalDiscNum(bdmeta->GetTotalDiscNumber());
1077 pBlurayInfo->setTitleCount(bdmeta->GetTitleCount());
1078 pBlurayInfo->setThumbCount(bdmeta->GetThumbnailCount());
1079 pBlurayInfo->setTopMenuSupported(bdmeta->GetTopMenuSupported());
1080 pBlurayInfo->setFirstPlaySupported(bdmeta->GetFirstPlaySupported());
1081 pBlurayInfo->setNumHDMVTitles(bdmeta->GetNumHDMVTitles());
1082 pBlurayInfo->setNumBDJTitles(bdmeta->GetNumBDJTitles());
1083 pBlurayInfo->setNumUnsupportedTitles(bdmeta->GetNumUnsupportedTitles());
1084 pBlurayInfo->setAACSDetected(bdmeta->GetAACSDetected());
1085 pBlurayInfo->setLibAACSDetected(bdmeta->GetLibAACSDetected());
1086 pBlurayInfo->setAACSHandled(bdmeta->GetAACSHandled());
1087 pBlurayInfo->setBDPlusDetected(bdmeta->GetBDPlusDetected());
1088 pBlurayInfo->setLibBDPlusDetected(bdmeta->GetLibBDPlusDetected());
1089 pBlurayInfo->setBDPlusHandled(bdmeta->GetBDPlusHandled());
1090
1091 QStringList thumbs = bdmeta->GetThumbnails();
1092 if (!thumbs.empty())
1093 pBlurayInfo->setThumbPath(thumbs.at(0));
1094
1095 delete bdmeta;
1096
1097 return pBlurayInfo;
1098}
1099
1100
1102// Jun 3, 2020
1103// Service to get stream info for all streams in a media file.
1104// This gets some basic info. If anything more is needed it can be added,
1105// depending on whether it is available from ffmpeg avformat apis.
1106// See the MythStreamInfoList class for the code that uses avformat to
1107// extract the information.
1109
1111 ( const QString &storageGroup,
1112 const QString &FileName )
1113{
1114
1115 // Search for the filename
1116
1117 StorageGroup storage( storageGroup );
1118 QString sFullFileName = storage.FindFile( FileName );
1119 MythStreamInfoList infos(sFullFileName);
1120
1121 // The constructor of this class reads the file and gets the needed
1122 // information.
1123 auto *pVideoStreamInfos = new V2VideoStreamInfoList();
1124
1125 pVideoStreamInfos->setCount ( infos.m_streamInfoList.size() );
1126 pVideoStreamInfos->setAsOf ( MythDate::current() );
1127 pVideoStreamInfos->setVersion ( MYTH_BINARY_VERSION );
1128 pVideoStreamInfos->setProtoVer ( MYTH_PROTO_VERSION );
1129 pVideoStreamInfos->setErrorCode ( infos.m_errorCode );
1130 pVideoStreamInfos->setErrorMsg ( infos.m_errorMsg );
1131
1132 for (const auto & info : std::as_const(infos.m_streamInfoList))
1133 {
1134 V2VideoStreamInfo *pVideoStreamInfo = pVideoStreamInfos->AddNewVideoStreamInfo();
1135 pVideoStreamInfo->setCodecType ( QString(QChar(info.m_codecType)) );
1136 pVideoStreamInfo->setCodecName ( info.m_codecName );
1137 pVideoStreamInfo->setWidth ( info.m_width );
1138 pVideoStreamInfo->setHeight ( info.m_height );
1139 pVideoStreamInfo->setAspectRatio ( info.m_SampleAspectRatio );
1140 pVideoStreamInfo->setFieldOrder ( info.m_fieldOrder );
1141 pVideoStreamInfo->setFrameRate ( info.m_frameRate );
1142 pVideoStreamInfo->setAvgFrameRate ( info.m_avgFrameRate );
1143 pVideoStreamInfo->setChannels ( info.m_channels );
1144 pVideoStreamInfo->setDuration ( info.m_duration );
1145
1146 }
1147 return pVideoStreamInfos;
1148}
1149
1151// October 26,2022
1152// Support for Cut List for Videos
1154
1156 const QString &offsettype,
1157 bool includeFps )
1158{
1160
1161 query.prepare("SELECT filename "
1162 "FROM videometadata "
1163 "WHERE intid = :ID ");
1164 query.bindValue(":ID", Id);
1165
1166 if (!query.exec())
1167 {
1168 MythDB::DBError("V2Video::GetVideoCommBreak", query);
1169 throw QString("Database Error.");
1170 }
1171
1172 QString fileName;
1173
1174 if (query.next())
1175 fileName = query.value(0).toString();
1176 else
1177 {
1178 LOG(VB_GENERAL, LOG_ERR, QString("V2Video/GetVideoCommBreak Video id %1 Not found.").arg(Id));
1179 throw QString("Video Not Found.");
1180 }
1181
1182 ProgramInfo pi(fileName,
1183 nullptr, // _plot,
1184 nullptr, // _title,
1185 nullptr, // const QString &_sortTitle,
1186 nullptr, // const QString &_subtitle,
1187 nullptr, // const QString &_sortSubtitle,
1188 nullptr, // const QString &_director,
1189 0, // int _season,
1190 0, // int _episode,
1191 nullptr, // const QString &_inetref,
1192 0min, // uint _length_in_minutes,
1193 0, // uint _year,
1194 nullptr); //const QString &_programid);
1195
1196
1197 int marktype = 0;
1198
1199 auto* pCutList = new V2CutList();
1200 if (offsettype.toLower() == "position")
1201 marktype = 1;
1202 else if (offsettype.toLower() == "duration")
1203 marktype = 2;
1204 else
1205 marktype = 0;
1206
1207 V2FillCutList(pCutList, &pi, marktype, includeFps);
1208
1209 return pCutList;
1210}
1211
1213// October 26,2022
1214// Support for Commercial Break List for Videos
1216
1218 const QString &offsettype,
1219 bool includeFps )
1220{
1222
1223 query.prepare("SELECT filename "
1224 "FROM videometadata "
1225 "WHERE intid = :ID ");
1226 query.bindValue(":ID", Id);
1227
1228 if (!query.exec())
1229 {
1230 MythDB::DBError("V2Video::GetVideoCommBreak", query);
1231 throw QString("Database Error.");
1232 }
1233
1234 QString fileName;
1235
1236 if (query.next())
1237 fileName = query.value(0).toString();
1238 else
1239 {
1240 LOG(VB_GENERAL, LOG_ERR, QString("V2Video/GetVideoCommBreak Video id %1 Not found.").arg(Id));
1241 throw QString("Video Not Found.");
1242 }
1243
1244 ProgramInfo pi(fileName,
1245 nullptr, // _plot,
1246 nullptr, // _title,
1247 nullptr, // const QString &_sortTitle,
1248 nullptr, // const QString &_subtitle,
1249 nullptr, // const QString &_sortSubtitle,
1250 nullptr, // const QString &_director,
1251 0, // int _season,
1252 0, // int _episode,
1253 nullptr, // const QString &_inetref,
1254 0min, // uint _length_in_minutes,
1255 0, // uint _year,
1256 nullptr); //const QString &_programid);
1257
1258
1259 int marktype = 0;
1260
1261 auto* pCutList = new V2CutList();
1262 if (offsettype.toLower() == "position")
1263 marktype = 1;
1264 else if (offsettype.toLower() == "duration")
1265 marktype = 2;
1266 else
1267 marktype = 0;
1268
1269 V2FillCommBreak(pCutList, &pi, marktype, includeFps);
1270
1271 return pCutList;
1272}
1273
1275{
1276 auto* pCatList = new V2VideoCategoryList();
1278
1279 query.prepare("SELECT intid,category "
1280 "FROM videocategory ");
1281
1282 if (!query.exec())
1283 {
1284 MythDB::DBError("V2Video::GetCategoryList", query);
1285 throw QString("Database Error.");
1286 }
1287
1288 while (query.next())
1289 {
1290 auto *cat = pCatList->AddNewCategory();
1291 cat->setId(query.value(0).toInt());
1292 cat->setName(query.value(1).toString());
1293 }
1294
1295 return pCatList;
1296}
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
QVariant value(int i) const
Definition: mythdbcon.h:204
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
QString GetSetting(const QString &key, const QString &defaultval="")
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
bool HAS_PARAMv2(const QString &p)
QVector< MythStreamInfo > m_streamInfoList
Definition: mythavutil.h:104
Holds information on recordings and videos.
Definition: programinfo.h:68
void SaveLastPlayPos(uint64_t frame)
TODO Move to RecordingInfo.
uint64_t QueryLastPlayPos(void) const
Gets any lastplaypos position in database, unless the ignore lastplaypos flag is set.
uint64_t QueryBookmark(void) const
Gets any bookmark position in database, unless the ignore bookmark flag is set.
void SaveBookmark(uint64_t frame)
Clears any existing bookmark in DB and if frame is greater than 0 sets a new bookmark.
QString FindFile(const QString &filename)
V2ArtworkItem * AddNewArtwork()
bool UpdateVideoMetadata(int Id, const QString &Title, const QString &SubTitle, const QString &TagLine, const QString &Director, const QString &Studio, const QString &Plot, const QString &Rating, const QString &Inetref, int CollectionRef, const QString &HomePage, int Year, QDate ReleaseDate, float UserRating, int Length, int PlayCount, int Season, int Episode, int ShowLevel, const QString &FileName, const QString &Hash, const QString &CoverFile, int ChildID, bool Browse, bool Watched, bool Processed, const QString &PlayCommand, int Category, const QString &Trailer, const QString &Host, const QString &Screenshot, const QString &Banner, const QString &Fanart, QDate InsertDate, const QString &ContentType, const QString &Genres, const QString &Cast, const QString &Countries)
Definition: v2video.cpp:630
static V2CutList * GetVideoCutList(int Id, const QString &OffsetType, bool IncludeFps)
Definition: v2video.cpp:1155
static bool AddVideo(const QString &FileName, const QString &HostName)
Definition: v2video.cpp:556
static V2VideoMetadataInfo * GetVideoByFileName(const QString &FileName)
Definition: v2video.cpp:73
V2Video()
Definition: v2video.cpp:53
static bool SetSavedBookmark(int Id, long Offset)
Definition: v2video.cpp:957
static void RegisterCustomTypes()
static bool UpdateVideoWatchedStatus(int Id, bool Watched)
Definition: v2video.cpp:612
static V2CutList * GetVideoCommBreak(int Id, const QString &OffsetType, bool IncludeFps)
Definition: v2video.cpp:1217
static bool RemoveVideoFromDB(int Id)
Definition: v2video.cpp:540
static bool SetLastPlayPos(int Id, long Offset)
Definition: v2video.cpp:1004
static long GetLastPlayPos(int Id)
Definition: v2video.cpp:143
static long GetSavedBookmark(int Id)
Definition: v2video.cpp:96
static V2VideoLookupList * LookupVideo(const QString &Title, const QString &Subtitle, const QString &Inetref, int Season, int Episode, const QString &GrabberType, bool AllowGeneric)
Definition: v2video.cpp:419
static V2BlurayInfo * GetBluray(const QString &Path)
Definition: v2video.cpp:1048
V2VideoMetadataInfoList * GetVideoList(const QString &Folder, const QString &Sort, const QString &TitleRegEx, int Category, bool Descending, int StartIndex, int Count, bool CollapseSubDirs)
Definition: v2video.cpp:205
static V2VideoStreamInfoList * GetStreamInfo(const QString &StorageGroup, const QString &FileName)
Definition: v2video.cpp:1111
static V2VideoMetadataInfo * GetVideo(int Id)
Definition: v2video.cpp:58
static V2VideoCategoryList * GetCategoryList()
Definition: v2video.cpp:1274
std::list< VideoMetadataPtr > metadata_list
static VideoMetadataPtr loadOneFromDatabase(uint id)
static void loadAllFromDatabase(metadata_list &items, const QString &sql="", const QStringList &bindValues=QStringList())
Load videometadata database into memory.
std::vector< cast_entry > cast_list
Definition: videometadata.h:34
std::vector< genre_entry > genre_list
Definition: videometadata.h:32
std::vector< country_entry > country_list
Definition: videometadata.h:33
void SetHost(const QString &host)
const QString VIDEO_INETREF_DEFAULT
Definition: globals.cpp:24
const QString VIDEO_PLOT_DEFAULT
Definition: globals.cpp:32
const QString VIDEO_TRAILER_DEFAULT
Definition: globals.cpp:26
const QString VIDEO_BANNER_DEFAULT
Definition: globals.cpp:28
const QString VIDEO_SCREENSHOT_DEFAULT
Definition: globals.cpp:27
const QString VIDEO_FANART_DEFAULT
Definition: globals.cpp:29
const QString VIDEO_RATING_DEFAULT
Definition: globals.cpp:30
const QString VIDEO_DIRECTOR_DEFAULT
Definition: globals.cpp:23
const QString VIDEO_COVERFILE_DEFAULT
Definition: globals.cpp:25
VideoContentType
@ kContentMusicVideo
@ kContentTelevision
@ kContentAdult
@ kContentUnknown
@ kContentHomeMovie
@ kContentMovie
GrabberType
QList< ArtworkInfo > ArtworkList
@ kArtworkScreenshot
@ kArtworkFanart
@ kArtworkBanner
@ kArtworkCoverart
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QString FileHash(const QString &filename)
std::shared_ptr< MythSortHelper > getMythSortHelper(void)
Get a pointer to the MythSortHelper singleton.
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:39
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
dictionary info
Definition: azlyrics.py:7
bool exists(str path)
Definition: xbmcvfs.py:51
void V2FillCommBreak(V2CutList *pCutList, ProgramInfo *rInfo, int marktype, bool includeFps)
void V2FillVideoMetadataInfo(V2VideoMetadataInfo *pVideoMetadataInfo, const VideoMetadataListManager::VideoMetadataPtr &pMetadata, bool bDetails)
void V2FillCutList(V2CutList *pCutList, ProgramInfo *rInfo, int marktype, bool includeFps)
Q_GLOBAL_STATIC_WITH_ARGS(MythHTTPMetaService, s_service,(VIDEO_HANDLE, V2Video::staticMetaObject, &V2Video::RegisterCustomTypes)) void V2Video
Definition: v2video.cpp:27
#define VIDEO_HANDLE
Definition: v2video.h:14
static constexpr uint16_t VIDEO_YEAR_DEFAULT
Definition: videometadata.h:18