MythTV  master
content.h
Go to the documentation of this file.
1 // Program Name: content.h
3 // Created : Mar. 7, 2011
4 //
5 // Copyright (c) 2011 David Blain <dblain@mythtv.org>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //
25 
26 #ifndef CONTENT_H
27 #define CONTENT_H
28 
29 #include "libmythbase/mythconfig.h"
30 #if CONFIG_QTSCRIPT
31 #include <QScriptEngine>
32 #endif
33 
35 
36 class Content : public ContentServices
37 {
38  Q_OBJECT
39 
40  public:
41 
42  Q_INVOKABLE explicit Content( QObject */*parent*/ = nullptr ) {}
43 
44  public:
45 
46  QFileInfo GetFile ( const QString &StorageGroup,
47  const QString &FileName ) override; // ContentServices
48 
49  QFileInfo GetImageFile ( const QString &StorageGroup,
50  const QString &FileName,
51  int Width, int Height ) override; // ContentServices
52 
53  QStringList GetFileList ( const QString &StorageGroup ) override; // ContentServices
54 
55  QStringList GetDirList ( const QString &StorageGroup ) override; // ContentServices
56 
57  QFileInfo GetRecordingArtwork ( const QString &Type,
58  const QString &Inetref,
59  int Season, int Width,
60  int Height) override; // ContentServices
61 
63  GetRecordingArtworkList( int RecordedId,
64  int ChanId,
65  const QDateTime &recstarttsRaw ) override; // ContentServices
66 
68  GetProgramArtworkList( const QString &Inetref,
69  int Season ) override; // ContentServices
70 
71  QFileInfo GetVideoArtwork ( const QString &Type,
72  int Id, int Width, int Height ) override; // ContentServices
73 
74  QFileInfo GetAlbumArt ( int Id, int Width, int Height ) override; // ContentServices
75 
76  QFileInfo GetPreviewImage ( int RecordedId,
77  int ChanId,
78  const QDateTime &recstarttsRaw,
79  int Width,
80  int Height,
81  int SecsIn,
82  const QString &Format) override; // ContentServices
83 
84  QFileInfo GetRecording ( int RecordedId,
85  int ChanId,
86  const QDateTime &recstarttsRaw ) override; // ContentServices
87 
88  QFileInfo GetMusic ( int Id ) override; // ContentServices
89  QFileInfo GetVideo ( int Id ) override; // ContentServices
90 
91  QString GetHash ( const QString &StorageGroup,
92  const QString &FileName ) override; // ContentServices
93 
94  bool DownloadFile ( const QString &URL,
95  const QString &StorageGroup ) override; // ContentServices
96 
97  // HTTP Live Streaming
99  const QString &FileName,
100  const QString &HostName,
101  int MaxSegments,
102  int Width,
103  int Height,
104  int Bitrate,
105  int AudioBitrate,
106  int SampleRate ) override; // ContentServices
107 
109  int ChanId,
110  const QDateTime &recstarttsRaw,
111  int MaxSegments,
112  int Width,
113  int Height,
114  int Bitrate,
115  int AudioBitrate,
116  int SampleRate ) override; // ContentServices
117 
119  int MaxSegments,
120  int Width,
121  int Height,
122  int Bitrate,
123  int AudioBitrate,
124  int SampleRate ) override; // ContentServices
125 
126  DTC::LiveStreamInfo *GetLiveStream ( int Id ) override; // ContentServices
127  DTC::LiveStreamInfoList *GetLiveStreamList ( const QString &FileName ) override; // ContentServices
128 
129  DTC::LiveStreamInfo *StopLiveStream ( int Id ) override; // ContentServices
130  bool RemoveLiveStream ( int Id ) override; // ContentServices
131 };
132 
133 // --------------------------------------------------------------------------
134 // The following class wrapper is due to a limitation in Qt Script Engine. It
135 // requires all methods that return pointers to user classes that are derived from
136 // QObject actually return QObject* (not the user class *). If the user class pointer
137 // is returned, the script engine treats it as a QVariant and doesn't create a
138 // javascript prototype wrapper for it.
139 //
140 // This class allows us to keep the rich return types in the main API class while
141 // offering the script engine a class it can work with.
142 //
143 // Only API Classes that return custom classes needs to implement these wrappers.
144 //
145 // We should continue to look for a cleaning solution to this problem.
146 // --------------------------------------------------------------------------
147 
148 #if CONFIG_QTSCRIPT
149 class ScriptableContent : public QObject
150 {
151  Q_OBJECT
152 
153  private:
154 
155  Content m_obj;
156  QScriptEngine *m_pEngine;
157 
158  public:
159 
160  Q_INVOKABLE explicit ScriptableContent( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
161  {
162  m_pEngine = pEngine;
163  }
164 
165  public slots:
166 
167  QObject* GetRecordingArtworkList( int RecordedId )
168  {
169  SCRIPT_CATCH_EXCEPTION( nullptr,
170  return m_obj.GetRecordingArtworkList( RecordedId, 0, QDateTime() );
171  )
172  }
173 
174  QObject* GetProgramArtworkList( const QString &Inetref,
175  int Season )
176  {
177  SCRIPT_CATCH_EXCEPTION( nullptr,
178  return m_obj.GetProgramArtworkList( Inetref, Season );
179  )
180  }
181 
182  QString GetHash ( const QString &StorageGroup,
183  const QString &FileName )
184  {
185  SCRIPT_CATCH_EXCEPTION( QString(),
186  return m_obj.GetHash( StorageGroup, FileName );
187  )
188  }
189 
190  // HTTP Live Streaming
191  QObject* AddLiveStream ( const QString &StorageGroup,
192  const QString &FileName,
193  const QString &HostName,
194  int MaxSegments,
195  int Width,
196  int Height,
197  int Bitrate,
198  int AudioBitrate,
199  int SampleRate )
200  {
201  SCRIPT_CATCH_EXCEPTION( nullptr,
202  return m_obj.AddLiveStream(StorageGroup, FileName, HostName,
203  MaxSegments, Width, Height, Bitrate,
204  AudioBitrate, SampleRate);
205  )
206  }
207 
208  QObject* AddRecordingLiveStream (int RecordedId,
209  int MaxSegments,
210  int Width,
211  int Height,
212  int Bitrate,
213  int AudioBitrate,
214  int SampleRate )
215  {
216  SCRIPT_CATCH_EXCEPTION( nullptr,
217  return m_obj.AddRecordingLiveStream(RecordedId, 0, QDateTime(),
218  MaxSegments,
219  Width, Height, Bitrate,
220  AudioBitrate, SampleRate);
221  )
222  }
223 
224  QObject* AddVideoLiveStream( int Id,
225  int MaxSegments,
226  int Width,
227  int Height,
228  int Bitrate,
229  int AudioBitrate,
230  int SampleRate )
231  {
232  SCRIPT_CATCH_EXCEPTION( nullptr,
233  return m_obj.AddVideoLiveStream(Id, MaxSegments, Width, Height,
234  Bitrate, AudioBitrate, SampleRate);
235  )
236  }
237 
238  QObject* GetLiveStream( int Id )
239  {
240  SCRIPT_CATCH_EXCEPTION( nullptr,
241  return m_obj.GetLiveStream( Id );
242  )
243  }
244 
245  QObject* GetLiveStreamList( const QString &FileName )
246  {
247  SCRIPT_CATCH_EXCEPTION( nullptr,
248  return m_obj.GetLiveStreamList( FileName );
249  )
250  }
251 
252  QObject* StopLiveStream( int Id )
253  {
254  SCRIPT_CATCH_EXCEPTION( nullptr,
255  return m_obj.StopLiveStream(Id);
256  )
257  }
258 
259  bool RemoveLiveStream( int Id )
260  {
261  SCRIPT_CATCH_EXCEPTION( false,
262  return m_obj.RemoveLiveStream(Id);
263  )
264  }
265 };
266 
267 // NOLINTNEXTLINE(modernize-use-auto)
268 Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV( ScriptableContent, QObject*);
269 #endif
270 
271 #endif
Content::GetRecordingArtwork
QFileInfo GetRecordingArtwork(const QString &Type, const QString &Inetref, int Season, int Width, int Height) override
Definition: content.cpp:264
ContentServices
Definition: contentServices.h:40
Content::GetPreviewImage
QFileInfo GetPreviewImage(int RecordedId, int ChanId, const QDateTime &recstarttsRaw, int Width, int Height, int SecsIn, const QString &Format) override
Definition: content.cpp:498
Content::AddLiveStream
DTC::LiveStreamInfo * AddLiveStream(const QString &StorageGroup, const QString &FileName, const QString &HostName, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate) override
Definition: content.cpp:878
Content::GetFileList
QStringList GetFileList(const QString &StorageGroup) override
Definition: content.cpp:244
DTC::LiveStreamInfo
Definition: liveStreamInfo.h:15
Content::GetAlbumArt
QFileInfo GetAlbumArt(int Id, int Width, int Height) override
Definition: content.cpp:401
Content::RemoveLiveStream
bool RemoveLiveStream(int Id) override
Definition: content.cpp:951
DTC::LiveStreamInfoList
Definition: liveStreamInfoList.h:14
Content::GetVideoArtwork
QFileInfo GetVideoArtwork(const QString &Type, int Id, int Width, int Height) override
Definition: content.cpp:342
MythDate::Format
Format
Definition: mythdate.h:15
SampleRate
Definition: recordingprofile.cpp:109
Content::GetProgramArtworkList
DTC::ArtworkInfoList * GetProgramArtworkList(const QString &Inetref, int Season) override
Definition: content.cpp:328
Content::AddVideoLiveStream
DTC::LiveStreamInfo * AddVideoLiveStream(int Id, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate) override
Definition: content.cpp:1088
Content::GetLiveStream
DTC::LiveStreamInfo * GetLiveStream(int Id) override
Definition: content.cpp:969
Content::GetFile
QFileInfo GetFile(const QString &StorageGroup, const QString &FileName) override
Definition: content.cpp:67
Content::Content
Q_INVOKABLE Content(QObject *=nullptr)
Definition: content.h:42
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV
#define Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(T, _Arg1)
Definition: service.h:113
Content::GetRecordingArtworkList
DTC::ArtworkInfoList * GetRecordingArtworkList(int RecordedId, int ChanId, const QDateTime &recstarttsRaw) override
Definition: content.cpp:310
Content::GetImageFile
QFileInfo GetImageFile(const QString &StorageGroup, const QString &FileName, int Width, int Height) override
Definition: content.cpp:122
SCRIPT_CATCH_EXCEPTION
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:85
Content::AddRecordingLiveStream
DTC::LiveStreamInfo * AddRecordingLiveStream(int RecordedId, int ChanId, const QDateTime &recstarttsRaw, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate) override
Definition: content.cpp:1006
Content::GetHash
QString GetHash(const QString &StorageGroup, const QString &FileName) override
Definition: content.cpp:811
Content::GetMusic
QFileInfo GetMusic(int Id) override
Definition: content.cpp:730
contentServices.h
Content::GetDirList
QStringList GetDirList(const QString &StorageGroup) override
Definition: content.cpp:224
Content::StopLiveStream
DTC::LiveStreamInfo * StopLiveStream(int Id) override
Definition: content.cpp:960
StorageGroup
Definition: storagegroup.h:11
Content::GetVideo
QFileInfo GetVideo(int Id) override
Definition: content.cpp:773
Content::GetRecording
QFileInfo GetRecording(int RecordedId, int ChanId, const QDateTime &recstarttsRaw) override
Definition: content.cpp:672
Content
Definition: content.h:36
DTC::ArtworkInfoList
Definition: artworkInfoList.h:25
Content::DownloadFile
bool DownloadFile(const QString &URL, const QString &StorageGroup) override
Definition: content.cpp:844
Content::GetLiveStreamList
DTC::LiveStreamInfoList * GetLiveStreamList(const QString &FileName) override
Definition: content.cpp:997