bool CMythFile::Exists(const CURL& url) { CStdString path(url.GetFileName()); /* * mythbackend provides access to the .mpg or .nuv recordings. The associated thumbnails * (*.mpg.png or *.nuv.png) and channel icons, which are an arbitrary image format, are requested * through the files/ path. */ if ((path.Left(11) == "recordings/" || path.Left(7) == "movies/" || path.Left(8) == "tvshows/") && (URIUtils::GetExtension(path).Equals(".mpg") || URIUtils::GetExtension(path).Equals(".nuv"))) { if(!SetupConnection(url, true, false, false)) return false; m_filename = url.GetFileNameWithoutPath(); DLL_CTRL_CALL( m_program, m_program == NULL, m_control, proginfo_get_from_basename(m_control, m_filename.c_str()) ); if(!m_program) { CLog::Log(LOGERROR, "%s - unable to get find %s", __FUNCTION__, m_filename.c_str()); return false; } return true; } else if(path.Left(6) == "files/") return true; return false; }
bool CMythFile::Exists(const CURL& url) { std::string path(url.GetFileName()); /* * mythbackend provides access to the .mpg or .nuv recordings. The associated thumbnails * (*.mpg.png or *.nuv.png) and channel icons, which are an arbitrary image format, are requested * through the files/ path. */ if ((StringUtils::StartsWith(path, "recordings/") || StringUtils::StartsWith(path, "movies/") || StringUtils::StartsWith(path, "tvshows/")) && (URIUtils::HasExtension(path, ".mpg|.nuv"))) { if(!SetupConnection(url, true, false, false)) return false; m_filename = url.GetFileNameWithoutPath(); m_program = m_dll->proginfo_get_from_basename(m_control, m_filename.c_str()); if(!m_program) { CLog::Log(LOGERROR, "%s - unable to get find %s", __FUNCTION__, m_filename.c_str()); return false; } return true; } else if(StringUtils::StartsWith(path, "files/")) return true; return false; }
bool CWinLibraryDirectory::Create(const CURL& url) { auto folder = GetFolder(url); if (folder) // already exists return true; CURL parentUrl = CURL(URIUtils::GetParentPath(url.Get())); folder = GetFolder(parentUrl); if (!folder) return false; try { std::wstring wStrPath = ToW(url.GetFileNameWithoutPath()); Wait(folder->CreateFolderAsync(ref new Platform::String(wStrPath.c_str()))); } catch (Platform::Exception^ ex) { return false; } return true; }
bool CWinLibraryDirectory::Create(const CURL& url) { auto folder = GetFolder(url); if (folder) // already exists return true; CURL parentUrl = CURL(URIUtils::GetParentPath(url.Get())); folder = GetFolder(parentUrl); if (!folder) return false; try { std::wstring wStrPath = ToW(url.GetFileNameWithoutPath()); Wait(folder.CreateFolderAsync(wStrPath)); } catch (const winrt::hresult_error&) { return false; } return true; }
bool CSlingboxFile::Open(const CURL& url) { // Setup the IP/hostname and port (setup default port if none specified) unsigned int uiPort; if (url.HasPort()) uiPort = (unsigned int)url.GetPort(); else uiPort = 5001; m_pSlingbox->SetAddress(url.GetHostName(), uiPort); // Prepare to connect to the Slingbox bool bAdmin; if (url.GetUserName().CompareNoCase("administrator") == 0) bAdmin = true; else if (url.GetUserName().CompareNoCase("viewer") == 0) bAdmin = false; else { CLog::Log(LOGERROR, "%s - Invalid or no username specified for Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); return false; } // Connect to the Slingbox if (m_pSlingbox->Connect(bAdmin, url.GetPassWord())) { CLog::Log(LOGDEBUG, "%s - Successfully connected to Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); } else { CLog::Log(LOGERROR, "%s - Error connecting to Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); return false; } // Initialize the stream if (m_pSlingbox->InitializeStream()) { CLog::Log(LOGDEBUG, "%s - Successfully initialized stream on Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); } else { CLog::Log(LOGERROR, "%s - Error initializing stream on Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); return false; } // Set correct input if (url.GetFileNameWithoutPath() != "") { if (m_pSlingbox->SetInput(atoi(url.GetFileNameWithoutPath()))) CLog::Log(LOGDEBUG, "%s - Successfully requested change to input %i on Slingbox: %s", __FUNCTION__, atoi(url.GetFileNameWithoutPath()), url.GetHostName().c_str()); else CLog::Log(LOGERROR, "%s - Error requesting change to input %i on Slingbox: %s", __FUNCTION__, atoi(url.GetFileNameWithoutPath()), url.GetHostName().c_str()); } // Load the video settings LoadSettings(url.GetHostName()); // Setup video options if (m_pSlingbox->StreamSettings((CSlingbox::Resolution)m_sSlingboxSettings.iVideoResolution, m_sSlingboxSettings.iVideoBitrate, m_sSlingboxSettings.iVideoFramerate, m_sSlingboxSettings.iVideoSmoothing, m_sSlingboxSettings.iAudioBitrate, m_sSlingboxSettings.iIFrameInterval)) { CLog::Log(LOGDEBUG, "%s - Successfully set stream options (resolution: %ix%i; " "video bitrate: %i kbit/s; fps: %i; smoothing: %i%%; audio bitrate %i kbit/s; " "I frame interval: %i) on Slingbox: %s", __FUNCTION__, m_sSlingboxSettings.iVideoWidth, m_sSlingboxSettings.iVideoHeight, m_sSlingboxSettings.iVideoBitrate, m_sSlingboxSettings.iVideoFramerate, m_sSlingboxSettings.iVideoSmoothing, m_sSlingboxSettings.iAudioBitrate, m_sSlingboxSettings.iIFrameInterval, url.GetHostName().c_str()); } else { CLog::Log(LOGERROR, "%s - Error setting stream options on Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); } // Start the stream if (m_pSlingbox->StartStream()) { CLog::Log(LOGDEBUG, "%s - Successfully started stream on Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); } else { CLog::Log(LOGERROR, "%s - Error starting stream on Slingbox: %s", __FUNCTION__, url.GetHostName().c_str()); return false; } // Check for correct input if (url.GetFileNameWithoutPath() != "") { if (m_pSlingbox->GetInput() == -1) CLog::Log(LOGDEBUG, "%s - Unable to confirm change to input %i on Slingbox: %s", __FUNCTION__, atoi(url.GetFileNameWithoutPath()), url.GetHostName().c_str()); else if (m_pSlingbox->GetInput() == atoi(url.GetFileNameWithoutPath())) CLog::Log(LOGDEBUG, "%s - Comfirmed change to input %i on Slingbox: %s", __FUNCTION__, atoi(url.GetFileNameWithoutPath()), url.GetHostName().c_str()); else CLog::Log(LOGERROR, "%s - Error changing to input %i on Slingbox: %s", __FUNCTION__, atoi(url.GetFileNameWithoutPath()), url.GetHostName().c_str()); } return true; }
bool CMythFile::SetupLiveTV(const CURL& url) { if (url.GetFileName().Left(9) != "channels/") return false; if(!SetupConnection(url, true, true, true)) return false; CStdString channel = url.GetFileNameWithoutPath(); if(!URIUtils::GetExtension(channel).Equals(".ts")) { CLog::Log(LOGERROR, "%s - invalid channel url %s", __FUNCTION__, channel.c_str()); return false; } URIUtils::RemoveExtension(channel); for(int i=0;i<16;i++) { DLL_CTRL_CALL( m_recorder, m_recorder == NULL, m_control, conn_get_recorder_from_num(m_control, i) ); if(!m_recorder) continue; if(m_dll->recorder_is_recording(m_recorder)) { /* for now don't allow reuse of tuners, we would have to change tuner on channel * * and make sure we don't stop the tuner when stopping playback as that affects * * other clients */ #if 0 /* if already recording, check if it is this channel */ cmyth_proginfo_t program; program = m_dll->recorder_get_cur_proginfo(m_recorder); if(program) { if(channel == GetValue(m_dll->proginfo_chanstr(program))) { m_dll->ref_release(program); break; } m_dll->ref_release(program); } #endif } else { /* not recording, check if it supports this channel */ if(m_dll->recorder_check_channel(m_recorder, (char*)channel.c_str()) == 0) break; } m_dll->ref_release(m_recorder); m_recorder = NULL; } if(!m_recorder) { CLog::Log(LOGERROR, "%s - unable to get recorder", __FUNCTION__); return false; } m_recording = !!m_dll->recorder_is_recording(m_recorder); if(!m_recording) CLog::Log(LOGDEBUG, "%s - recorder isn't running, let's start it", __FUNCTION__); char* msg = NULL; if(!(m_recorder = m_dll->spawn_live_tv(m_recorder, 16*1024, 4096, prog_update_callback, &msg, (char*)channel.c_str()))) { CLog::Log(LOGERROR, "%s - unable to spawn live tv: %s", __FUNCTION__, msg ? msg : ""); return false; } m_program = m_dll->recorder_get_cur_proginfo(m_recorder); m_timestamp = XbmcThreads::SystemClockMillis(); if(m_program) m_starttime = m_dll->proginfo_rec_start(m_program); if(m_recording) { /* recorder was running when we started, seek to last position */ if(!m_dll->livetv_seek(m_recorder, 0, SEEK_END)) CLog::Log(LOGDEBUG, "%s - failed to seek to last position", __FUNCTION__); } m_filename = GetValue(m_dll->recorder_get_filename(m_recorder)); return true; }
bool CMythFile::SetupRecording(const CURL& url) { if (url.GetFileName().Left(11) != "recordings/" && url.GetFileName().Left(7) != "movies/" && url.GetFileName().Left(8) != "tvshows/") return false; if(!SetupConnection(url, true, false, false)) return false; m_filename = url.GetFileNameWithoutPath(); DLL_CTRL_CALL( m_program, m_program == NULL, m_control, proginfo_get_from_basename(m_control, m_filename.c_str()) ); if(!m_program) { CLog::Log(LOGERROR, "%s - unable to get find selected file", __FUNCTION__); return false; } DLL_CTRL_CALL( m_file, m_file == NULL, m_control, conn_connect_file(m_program, m_control, 16*1024, 4096) ); if(!m_file) { CLog::Log(LOGERROR, "%s - unable to connect to file", __FUNCTION__); return false; } /* * proginfo_get_from_basename doesn't return the recording status. Hopefully this will be added to * mythbackend eventually. * * Since cycling through the recorders to check if the program is recording takes some time * (depending on the MythTV backend configuration), make some assumptions based on the recording * end time since nearly all recordings opened won't be recording. */ m_recording = false; CDateTime start = GetValue(m_dll->proginfo_rec_start(m_program)); CDateTime end = GetValue(m_dll->proginfo_rec_end(m_program)); if (end > start // Assume could be recording if empty date comes back as the epoch && end < CDateTime::GetCurrentDateTime()) CLog::Log(LOGDEBUG, "%s - Assumed not recording since recording end time before current time: %s", __FUNCTION__, end.GetAsLocalizedDateTime().c_str()); else { CLog::Log(LOGDEBUG, "%s - Checking recording status using tuners since recording end time NULL or before current time: %s", __FUNCTION__, end.GetAsLocalizedDateTime().c_str()); for(int i=0;i<16 && !m_recording;i++) { cmyth_recorder_t recorder = NULL; DLL_CTRL_CALL( recorder, recorder == NULL, m_control, conn_get_recorder_from_num(m_control, i) ); if(!recorder) continue; if(m_dll->recorder_is_recording(recorder)) { cmyth_proginfo_t program = m_dll->recorder_get_cur_proginfo(recorder); if(m_dll->proginfo_compare(program, m_program) == 0) m_recording = true; m_dll->ref_release(program); } m_dll->ref_release(recorder); } } if (m_recording) CLog::Log(LOGDEBUG, "%s - Currently recording: %s", __FUNCTION__, m_filename.c_str()); return true; }