DTC::ProgramList* Dvr::GetRecordedList( bool bDescending, int nStartIndex, int nCount, const QString &sTitleRegEx, const QString &sRecGroup, const QString &sStorageGroup ) { QMap< QString, ProgramInfo* > recMap; if (gCoreContext->GetScheduler()) recMap = gCoreContext->GetScheduler()->GetRecording(); QMap< QString, uint32_t > inUseMap = ProgramInfo::QueryInUseMap(); QMap< QString, bool > isJobRunning= ProgramInfo::QueryJobsRunning(JOB_COMMFLAG); ProgramList progList; int desc = 1; if (bDescending) desc = -1; LoadFromRecorded( progList, false, inUseMap, isJobRunning, recMap, desc ); QMap< QString, ProgramInfo* >::iterator mit = recMap.begin(); for (; mit != recMap.end(); mit = recMap.erase(mit)) delete *mit; // ---------------------------------------------------------------------- // Build Response // ---------------------------------------------------------------------- DTC::ProgramList *pPrograms = new DTC::ProgramList(); int nAvailable = 0; int nMax = (nCount > 0) ? nCount : progList.size(); nAvailable = 0; nCount = 0; QRegExp rTitleRegEx = QRegExp(sTitleRegEx, Qt::CaseInsensitive); for( unsigned int n = 0; n < progList.size(); n++) { ProgramInfo *pInfo = progList[ n ]; if (pInfo->IsDeletePending() || (!sTitleRegEx.isEmpty() && !pInfo->GetTitle().contains(rTitleRegEx)) || (!sRecGroup.isEmpty() && sRecGroup != pInfo->GetRecordingGroup()) || (!sStorageGroup.isEmpty() && sStorageGroup != pInfo->GetStorageGroup())) continue; if ((nAvailable < nStartIndex) || (nCount >= nMax)) { ++nAvailable; continue; } ++nAvailable; ++nCount; DTC::Program *pProgram = pPrograms->AddNewProgram(); FillProgramInfo( pProgram, pInfo, true ); } // ---------------------------------------------------------------------- pPrograms->setStartIndex ( nStartIndex ); pPrograms->setCount ( nCount ); pPrograms->setTotalAvailable( nAvailable ); pPrograms->setAsOf ( MythDate::current() ); pPrograms->setVersion ( MYTH_BINARY_VERSION ); pPrograms->setProtoVer ( MYTH_PROTO_VERSION ); return pPrograms; }
DTC::LiveStreamInfo *Content::AddRecordingLiveStream( int nRecordedId, int nChanId, const QDateTime &recstarttsRaw, int nMaxSegments, int nWidth, int nHeight, int nBitrate, int nAudioBitrate, int nSampleRate ) { if ((nRecordedId <= 0) && (nChanId <= 0 || !recstarttsRaw.isValid())) throw QString("Recorded ID or Channel ID and StartTime appears invalid."); // ------------------------------------------------------------------ // Read Recording From Database // ------------------------------------------------------------------ // TODO Should use RecordingInfo ProgramInfo pginfo; if (nRecordedId > 0) pginfo = ProgramInfo(nRecordedId); else pginfo = ProgramInfo(nChanId, recstarttsRaw.toUTC()); if (!pginfo.GetChanID()) { LOG(VB_UPNP, LOG_ERR, QString("AddRecordingLiveStream - for %1, %2 failed") .arg(QString::number(nRecordedId))); return NULL; } if (pginfo.GetHostname().toLower() != gCoreContext->GetHostName().toLower()) { // We only handle requests for local resources QString sMsg = QString("GetRecording: Wrong Host '%1' request from '%2'.") .arg( gCoreContext->GetHostName()) .arg( pginfo.GetHostname() ); LOG(VB_UPNP, LOG_ERR, sMsg); throw HttpRedirectException( pginfo.GetHostname() ); } QString sFileName( GetPlaybackURL(&pginfo) ); // ---------------------------------------------------------------------- // check to see if the file exists // ---------------------------------------------------------------------- if (!QFile::exists( sFileName )) { LOG( VB_UPNP, LOG_ERR, QString("AddRecordingLiveStream - for %1, %2 failed") .arg( nChanId ) .arg( recstarttsRaw.toUTC().toString() )); return NULL; } QFileInfo fInfo( sFileName ); return AddLiveStream( pginfo.GetStorageGroup(), fInfo.fileName(), pginfo.GetHostname(), nMaxSegments, nWidth, nHeight, nBitrate, nAudioBitrate, nSampleRate ); }