32 #include <QImageWriter>
68 qRegisterMetaType<V2ArtworkInfoList*>(
"V2ArtworkInfoList");
69 qRegisterMetaType<V2ArtworkInfo*>(
"V2ArtworkInfo");
81 const QString &sFileName )
83 QString sGroup = sStorageGroup;
87 LOG(VB_UPNP, LOG_WARNING,
88 "GetFile - StorageGroup missing... using 'Default'");
92 if (sFileName.isEmpty())
94 QString sMsg (
"GetFile - FileName missing." );
106 QString sFullFileName = storage.
FindFile( sFileName );
108 if (sFullFileName.isEmpty())
110 LOG(VB_UPNP, LOG_ERR,
111 QString(
"GetFile - Unable to find %1.").arg(sFileName));
122 return QFileInfo( sFullFileName );
125 LOG(VB_UPNP, LOG_ERR,
126 QString(
"GetFile - File Does not exist %1.").arg(sFullFileName));
136 const QString &sFileName,
140 QString sGroup = sStorageGroup;
142 if (sGroup.isEmpty())
144 LOG(VB_UPNP, LOG_WARNING,
145 "GetImageFile - StorageGroup missing... using 'Default'");
149 if (sFileName.isEmpty())
151 QString sMsg (
"GetImageFile - FileName missing." );
163 QString sFullFileName = storage.
FindFile( sFileName );
165 if (sFullFileName.isEmpty())
167 LOG(VB_UPNP, LOG_WARNING,
168 QString(
"GetImageFile - Unable to find %1.").arg(sFileName));
179 LOG(VB_UPNP, LOG_WARNING,
180 QString(
"GetImageFile - File Does not exist %1.").arg(sFullFileName));
187 if ((nWidth == 0) && (nHeight == 0))
188 return QFileInfo( sFullFileName );
193 QString sNewFileName = QString(
"%1.%2x%3.jpg" )
194 .arg( sFullFileName )
203 return QFileInfo( sNewFileName );
209 auto *pImage =
new QImage( sFullFileName );
211 if (!pImage || pImage->isNull())
214 float fAspect = (float)(pImage->width()) / pImage->height();
217 nWidth = (int)std::rint(nHeight * fAspect);
220 nHeight = (int)std::rint(nWidth / fAspect);
222 QImage img = pImage->scaled( nWidth, nHeight, Qt::KeepAspectRatio,
223 Qt::SmoothTransformation);
225 QByteArray fname = sNewFileName.toLatin1();
226 img.save( fname.constData(),
"JPG", 60 );
230 return QFileInfo( sNewFileName );
240 if (sStorageGroup.isEmpty())
242 QString sMsg(
"GetDirList - StorageGroup missing.");
243 LOG(VB_UPNP, LOG_ERR, sMsg);
260 if (sStorageGroup.isEmpty())
262 QString sMsg(
"GetFileList - StorageGroup missing.");
263 LOG(VB_UPNP, LOG_ERR, sMsg);
278 const QString &sInetref,
291 if (sType.toLower() ==
"coverart")
296 else if (sType.toLower() ==
"fanart")
301 else if (sType.toLower() ==
"banner")
307 if (!map.contains(
type))
310 QUrl url(map.value(
type).url);
311 QString sFileName = url.path();
313 if (sFileName.isEmpty())
316 return GetImageFile( sgroup, sFileName, nWidth, nHeight);
325 const QDateTime &StartTime)
327 if ((RecordedId <= 0) &&
328 (chanid <= 0 || !StartTime.isValid()))
329 throw QString(
"Recorded ID or Channel ID and StartTime appears invalid.");
356 int nId,
int nWidth,
int nHeight )
358 LOG(VB_UPNP, LOG_INFO, QString(
"GetVideoArtwork ID = %1").arg(nId));
360 QString sgroup =
"Coverart";
361 QString column =
"coverfile";
363 if (sType.toLower() ==
"coverart")
366 column =
"coverfile";
368 else if (sType.toLower() ==
"fanart")
373 else if (sType.toLower() ==
"banner")
378 else if (sType.toLower() ==
"screenshot")
380 sgroup =
"Screenshots";
381 column =
"screenshot";
390 QString querystr = QString(
"SELECT %1 FROM videometadata WHERE "
391 "intid = :ITEMID").arg(column);
402 QString sFileName = query.
value(0).toString();
404 if (sFileName.isEmpty())
407 return GetImageFile( sgroup, sFileName, nWidth, nHeight );
426 LOG(VB_GENERAL, LOG_DEBUG, QString(
"GetAlbumArt: %1").arg(sFullFileName));
433 QString sNewFileName = QString(
"/tmp/%1.%2x%3.jpg" )
434 .arg( QFileInfo(sFullFileName).fileName() )
443 return QFileInfo( sNewFileName );
451 if (sFullFileName.startsWith(
"myth://"))
453 RemoteFile rf(sFullFileName,
false,
false, 0s);
457 img.loadFromData(data);
461 img.load(sFullFileName);
469 if ((nWidth == 0) && (nHeight == 0))
471 if (!sFullFileName.startsWith(
"myth://"))
473 QFileInfo fi(sFullFileName);
474 if (fi.suffix().toLower() ==
"jpg")
478 else if (nWidth > img.width() && nHeight > img.height())
488 float fAspect = (float)(img.width()) / img.height();
490 if ( nWidth == 0 || nWidth > img.width() )
491 nWidth = (
int)std::rint(nHeight * fAspect);
493 if ( nHeight == 0 || nHeight > img.height() )
494 nHeight = (int)std::rint(nWidth / fAspect);
496 img = img.scaled( nWidth, nHeight, Qt::KeepAspectRatio,
497 Qt::SmoothTransformation);
500 QString fname = sNewFileName.toLatin1().constData();
503 if (!img.save( fname,
"JPG" ))
506 return QFileInfo( sNewFileName );
515 const QDateTime &StartTime,
519 const QString &sFormat )
521 if ((nRecordedId <= 0) &&
522 (nChanId <= 0 || !StartTime.isValid()))
523 throw QString(
"Recorded ID or Channel ID and StartTime appears invalid.");
525 if (!sFormat.isEmpty()
526 && !QImageWriter::supportedImageFormats().contains(sFormat.toLower().toLocal8Bit()))
528 throw QString(
"GetPreviewImage: Specified 'Format' is not supported.");
544 LOG(VB_GENERAL, LOG_ERR,
545 QString(
"GetPreviewImage: No recording for '%1'")
554 QString(
"GetPreviewImage: Wrong Host '%1' request from '%2'")
558 LOG(VB_UPNP, LOG_ERR, sMsg);
563 QString sImageFormat = sFormat;
564 if (sImageFormat.isEmpty())
565 sImageFormat =
"PNG";
573 QString sPreviewFileName;
575 auto nSecs = std::chrono::seconds(nSecsIn);
579 sPreviewFileName = QString(
"%1.png").arg(sFileName);
583 sPreviewFileName = QString(
"%1.%2.png").arg(sFileName).arg(nSecsIn);
591 if (!pginfo.
IsLocal() && sFileName.startsWith(
"/"))
599 previewgen->SetPreviewTimeAsSeconds( nSecs );
600 previewgen->SetOutputFilename ( sPreviewFileName );
602 bool ok = previewgen->Run();
604 previewgen->deleteLater();
610 bool bDefaultPixmap = (nWidth == 0) && (nHeight == 0);
612 QString sNewFileName;
615 sNewFileName = sPreviewFileName;
618 sNewFileName = QString(
"%1.%2.%3x%4.%5" )
621 .arg( nWidth == 0 ? -1 : nWidth )
622 .arg( nHeight == 0 ? -1 : nHeight )
623 .arg( sImageFormat.toLower() );
631 if (QFileInfo(sPreviewFileName).lastModified() <=
632 QFileInfo(sNewFileName).lastModified())
633 return QFileInfo( sNewFileName );
636 QImage image = QImage(sPreviewFileName);
644 image = image.scaledToHeight(nHeight, Qt::SmoothTransformation);
645 else if ( nHeight <= 0 )
646 image = image.scaledToWidth(nWidth, Qt::SmoothTransformation);
648 image = image.scaled(nWidth, nHeight, Qt::IgnoreAspectRatio,
649 Qt::SmoothTransformation);
651 image.save(sNewFileName, sImageFormat.toUpper().toLocal8Bit());
657 LOG(VB_GENERAL, LOG_ERR,
"Unable to change permissions on "
658 "preview image. Backends and frontends "
659 "running under different users will be "
660 "unable to access it");
665 return QFileInfo( sNewFileName );
669 previewgen->SetPreviewTimeAsSeconds( nSecs );
670 previewgen->SetOutputFilename ( sNewFileName );
671 previewgen->SetOutputSize (QSize(nWidth,nHeight));
673 bool ok = previewgen->Run();
675 previewgen->deleteLater();
680 return QFileInfo( sNewFileName );
689 const QDateTime &StartTime,
690 const QString &Download )
692 if ((nRecordedId <= 0) &&
693 (nChanId <= 0 || !StartTime.isValid()))
694 throw QString(
"Recorded ID or Channel ID and StartTime appears invalid.");
709 LOG(VB_UPNP, LOG_ERR, QString(
"GetRecording - for '%1' failed")
721 QString(
"GetRecording: Wrong Host '%1' request from '%2'.")
725 LOG(VB_UPNP, LOG_ERR, sMsg);
733 m_request->m_headers->insert(
"mythtv-download",Download);
740 return QFileInfo( sFileName );
761 query.
prepare(
"SELECT CONCAT_WS('/', music_directories.path, "
762 "music_songs.filename) AS filename FROM music_songs "
763 "LEFT JOIN music_directories ON "
764 "music_songs.directory_id="
765 "music_directories.directory_id "
766 "WHERE music_songs.song_id = :KEY");
778 sFileName = query.
value(0).toString();
782 if (sFileName.isEmpty())
785 return GetFile(
"Music", sFileName );
804 query.
prepare(
"SELECT filename FROM videometadata WHERE intid = :KEY" );
814 sFileName = query.
value(0).toString();
817 if (sFileName.isEmpty())
821 return GetFile(
"Videos", sFileName );
823 return QFileInfo( sFileName );
831 const QString &sFileName )
833 if ((sFileName.isEmpty()) ||
834 (sFileName.contains(
"/../")) ||
835 (sFileName.startsWith(
"../")))
837 LOG(VB_GENERAL, LOG_ERR,
838 QString(
"ERROR checking for file, filename '%1' "
839 "fails sanity checks").arg(sFileName));
843 QString storageGroup =
"Default";
845 if (!sStorageGroup.isEmpty())
846 storageGroup = sStorageGroup;
850 QString fullname = sgroup.
FindFile(sFileName);
865 QFileInfo finfo(sURL);
866 QString
filename = finfo.fileName();
871 if (outDir.isEmpty())
873 LOG(VB_GENERAL, LOG_ERR,
874 QString(
"Unable to determine directory "
875 "to write to in %1 write command").arg(sURL));
882 LOG(VB_GENERAL, LOG_ERR,
883 QString(
"ERROR: %1 write filename '%2' does not "
884 "pass sanity checks.").arg(sURL,
filename));