diff options
author | Arne Morten Kvarving <spiff@kodi.tv> | 2024-05-05 22:14:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-05 22:14:30 +0200 |
commit | d74b274138954c2d28f2e2a40aa298c1951ea261 (patch) | |
tree | 16448c6cf504acff3f8c9c68bb55d7a5984bb93e | |
parent | 43f62acbcbbed087b5e6b41a926b712f2aa7763d (diff) | |
parent | d349d0d04bf53143e1bcdbdc643ca31fcdccb9b2 (diff) | |
download | xbmc-d74b274138954c2d28f2e2a40aa298c1951ea261.tar.xz |
Merge pull request #25124 from notspiff/add_network_fileitem_classify
Add NetworkFileItemClassify
31 files changed, 474 insertions, 137 deletions
diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index 1890f21db0..8b7012a0e6 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -32,6 +32,7 @@ #include "music/MusicFileItemClassify.h" #include "music/tags/MusicInfoTag.h" #include "music/tags/MusicInfoTagLoaderFactory.h" +#include "network/NetworkFileItemClassify.h" #include "pictures/PictureInfoTag.h" #include "playlists/PlayList.h" #include "playlists/PlayListFactory.h" @@ -67,7 +68,6 @@ #include <memory> using namespace KODI; -using namespace KODI::VIDEO; using namespace XFILE; using namespace PLAYLIST; using namespace MUSIC_INFO; @@ -842,16 +842,11 @@ void CFileItem::ToSortable(SortItem &sortable, const Fields &fields) const bool CFileItem::Exists(bool bUseCache /* = true */) const { - if (m_strPath.empty() - || IsPath("add") - || IsInternetStream() - || IsParentFolder() - || IsVirtualDirectoryRoot() - || IsPlugin() - || IsPVR()) + if (m_strPath.empty() || IsPath("add") || NETWORK::IsInternetStream(*this) || IsParentFolder() || + IsVirtualDirectoryRoot() || IsPlugin() || IsPVR()) return true; - if (IsVideoDb(*this) && HasVideoInfoTag()) + if (VIDEO::IsVideoDb(*this) && HasVideoInfoTag()) { CFileItem dbItem(m_bIsFolder ? GetVideoInfoTag()->m_strPath : GetVideoInfoTag()->m_strFileNameAndPath, m_bIsFolder); return dbItem.Exists(); @@ -971,31 +966,12 @@ bool CFileItem::IsPicture() const return false; } -bool CFileItem::IsInternetStream(const bool bStrictCheck /* = false */) const -{ - if (HasProperty("IsHTTPDirectory")) - return bStrictCheck; - - if (!m_strDynPath.empty()) - return URIUtils::IsInternetStream(m_strDynPath, bStrictCheck); - - return URIUtils::IsInternetStream(m_strPath, bStrictCheck); -} - -bool CFileItem::IsStreamedFilesystem() const -{ - if (!m_strDynPath.empty()) - return URIUtils::IsStreamedFilesystem(m_strDynPath); - - return URIUtils::IsStreamedFilesystem(m_strPath); -} - bool CFileItem::IsFileFolder(EFileFolderType types) const { EFileFolderType always_type = EFILEFOLDER_TYPE_ALWAYS; /* internet streams are not directly expanded */ - if(IsInternetStream()) + if (NETWORK::IsInternetStream(*this)) always_type = EFILEFOLDER_TYPE_ONCLICK; // strm files are not browsable @@ -1077,10 +1053,10 @@ bool CFileItem::IsDiscImage() const bool CFileItem::IsOpticalMediaFile() const { - if (IsDVDFile(*this, false, true)) + if (VIDEO::IsDVDFile(*this, false, true)) return true; - return IsBDFile(*this); + return VIDEO::IsBDFile(*this); } bool CFileItem::IsRAR() const @@ -1162,7 +1138,7 @@ bool CFileItem::IsBluray() const CFileItem item = CFileItem(VIDEO::UTILS::GetOpticalMediaPath(*this), false); - return IsBDFile(item); + return VIDEO::IsBDFile(item); } bool CFileItem::IsDVD() const @@ -1180,21 +1156,11 @@ bool CFileItem::IsNfs() const return URIUtils::IsNfs(m_strPath); } -bool CFileItem::IsOnLAN() const -{ - return URIUtils::IsOnLAN(m_strPath); -} - bool CFileItem::IsISO9660() const { return URIUtils::IsISO9660(m_strPath); } -bool CFileItem::IsRemote() const -{ - return URIUtils::IsRemote(m_strPath); -} - bool CFileItem::IsSmb() const { return URIUtils::IsSmb(m_strPath); @@ -1303,7 +1269,7 @@ void CFileItem::FillInDefaultIcon() // audio SetArt("icon", "DefaultAudio.png"); } - else if (IsVideo(*this)) + else if (VIDEO::IsVideo(*this)) { // video SetArt("icon", "DefaultVideo.png"); @@ -1480,7 +1446,7 @@ void CFileItem::UpdateMimeType(bool lookup /*= true*/) void CFileItem::SetMimeTypeForInternetFile() { - if (m_doContentLookup && IsInternetStream()) + if (m_doContentLookup && NETWORK::IsInternetStream(*this)) { SetMimeType(""); FillInMimeType(true); @@ -1497,7 +1463,7 @@ bool CFileItem::IsSamePath(const CFileItem *item) const if (item->HasProperty("item_start") || HasProperty("item_start")) return (item->GetProperty("item_start") == GetProperty("item_start")); // See if we have associated a bluray playlist - if (IsBlurayPlaylist(*this) || IsBlurayPlaylist(*item)) + if (VIDEO::IsBlurayPlaylist(*this) || VIDEO::IsBlurayPlaylist(*item)) return (GetDynPath() == item->GetDynPath()); return true; } @@ -1530,7 +1496,7 @@ bool CFileItem::IsSamePath(const CFileItem *item) const dbItem.SetProperty("item_start", GetProperty("item_start")); return dbItem.IsSamePath(item); } - if (IsVideoDb(*this) && HasVideoInfoTag()) + if (VIDEO::IsVideoDb(*this) && HasVideoInfoTag()) { CFileItem dbItem(GetVideoInfoTag()->m_strFileNameAndPath, false); if (HasProperty("item_start")) @@ -1544,7 +1510,7 @@ bool CFileItem::IsSamePath(const CFileItem *item) const dbItem.SetProperty("item_start", item->GetProperty("item_start")); return IsSamePath(&dbItem); } - if (IsVideoDb(*item) && item->HasVideoInfoTag()) + if (VIDEO::IsVideoDb(*item) && item->HasVideoInfoTag()) { CFileItem dbItem(item->GetVideoInfoTag()->m_strFileNameAndPath, false); if (item->HasProperty("item_start")) @@ -1695,7 +1661,7 @@ void CFileItem::MergeInfo(const CFileItem& item) SetLabel2(item.GetLabel2()); if (!item.GetArt().empty()) { - if (IsVideo(item)) + if (VIDEO::IsVideo(item)) AppendArt(item.GetArt()); else SetArt(item.GetArt()); @@ -1900,7 +1866,7 @@ void CFileItem::SetDynPath(const std::string &path) std::string CFileItem::GetBlurayPath() const { - if (IsBlurayPlaylist(*this)) + if (VIDEO::IsBlurayPlaylist(*this)) { CURL url(GetDynPath()); CURL url2(url.GetHostName()); // strip bluray:// @@ -2014,7 +1980,7 @@ std::string CFileItem::GetUserMusicThumb(bool alwaysCheckRemote /* = false */, b { if (m_strPath.empty() || StringUtils::StartsWithNoCase(m_strPath, "newsmartplaylist://") || StringUtils::StartsWithNoCase(m_strPath, "newplaylist://") || m_bIsShareOrDrive || - IsInternetStream() || URIUtils::IsUPnP(m_strPath) || + NETWORK::IsInternetStream(*this) || URIUtils::IsUPnP(m_strPath) || (URIUtils::IsFTP(m_strPath) && !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bFTPThumbs) || IsPlugin() || IsAddonsPath() || IsLibraryFolder() || IsParentFolder() || @@ -2034,7 +2000,10 @@ std::string CFileItem::GetUserMusicThumb(bool alwaysCheckRemote /* = false */, b } // if a folder, check for folder.jpg - if (m_bIsFolder && !IsFileFolder() && (!IsRemote() || alwaysCheckRemote || CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICFILES_FINDREMOTETHUMBS))) + if (m_bIsFolder && !IsFileFolder() && + (!NETWORK::IsRemote(*this) || alwaysCheckRemote || + CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool( + CSettings::SETTING_MUSICFILES_FINDREMOTETHUMBS))) { std::vector<CVariant> thumbs = CServiceBroker::GetSettingsComponent()->GetSettings()->GetList( CSettings::SETTING_MUSICLIBRARY_MUSICTHUMBS); @@ -2126,20 +2095,13 @@ std::string CFileItem::GetTBNFile() const bool CFileItem::SkipLocalArt() const { - return (m_strPath.empty() - || StringUtils::StartsWithNoCase(m_strPath, "newsmartplaylist://") - || StringUtils::StartsWithNoCase(m_strPath, "newplaylist://") - || m_bIsShareOrDrive - || IsInternetStream() - || URIUtils::IsUPnP(m_strPath) - || (URIUtils::IsFTP(m_strPath) && !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bFTPThumbs) - || IsPlugin() - || IsAddonsPath() - || IsLibraryFolder() - || IsParentFolder() - || IsLiveTV() - || IsPVRRecording() - || IsDVD()); + return (m_strPath.empty() || StringUtils::StartsWithNoCase(m_strPath, "newsmartplaylist://") || + StringUtils::StartsWithNoCase(m_strPath, "newplaylist://") || m_bIsShareOrDrive || + NETWORK::IsInternetStream(*this) || URIUtils::IsUPnP(m_strPath) || + (URIUtils::IsFTP(m_strPath) && + !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bFTPThumbs) || + IsPlugin() || IsAddonsPath() || IsLibraryFolder() || IsParentFolder() || IsLiveTV() || + IsPVRRecording() || IsDVD()); } std::string CFileItem::GetThumbHideIfUnwatched(const CFileItem* item) const @@ -2338,7 +2300,7 @@ std::string CFileItem::GetBaseMoviePath(bool bUseFolderNames) const std::string CFileItem::GetLocalFanart() const { - if (IsVideoDb(*this)) + if (VIDEO::IsVideoDb(*this)) { if (!HasVideoInfoTag()) return ""; // nothing can be done @@ -2369,15 +2331,11 @@ std::string CFileItem::GetLocalFanart() const } // no local fanart available for these - if (IsInternetStream() - || URIUtils::IsUPnP(strFile) - || URIUtils::IsBluray(strFile) - || IsLiveTV() - || IsPlugin() - || IsAddonsPath() - || IsDVD() - || (URIUtils::IsFTP(strFile) && !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bFTPThumbs) - || m_strPath.empty()) + if (NETWORK::IsInternetStream(*this) || URIUtils::IsUPnP(strFile) || + URIUtils::IsBluray(strFile) || IsLiveTV() || IsPlugin() || IsAddonsPath() || IsDVD() || + (URIUtils::IsFTP(strFile) && + !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bFTPThumbs) || + m_strPath.empty()) return ""; std::string strDir = URIUtils::GetDirectory(strFile); @@ -2424,7 +2382,7 @@ std::string CFileItem::GetLocalMetadataPath() const return m_strPath; std::string parent{}; - if (IsBlurayPlaylist(*this)) + if (VIDEO::IsBlurayPlaylist(*this)) parent = URIUtils::GetParentPath(GetBlurayPath()); else parent = URIUtils::GetParentPath(m_strPath); @@ -2516,7 +2474,7 @@ bool CFileItem::LoadGameTag() bool CFileItem::LoadDetails() { - if (IsVideoDb(*this)) + if (VIDEO::IsVideoDb(*this)) { if (HasVideoInfoTag()) return true; @@ -2576,7 +2534,7 @@ bool CFileItem::LoadDetails() return false; } - if (!IsPlayList() && IsVideo(*this)) + if (!IsPlayList() && VIDEO::IsVideo(*this)) { if (HasVideoInfoTag()) return true; @@ -2608,7 +2566,7 @@ bool CFileItem::LoadDetails() if (playlist->Load(GetPath()) && playlist->size() == 1) { const auto item{(*playlist)[0]}; - if (IsVideo(*item)) + if (VIDEO::IsVideo(*item)) { CVideoDatabase db; if (!db.Open()) @@ -2779,12 +2737,8 @@ std::string CFileItem::FindTrailer() const } // no local trailer available for these - if (IsInternetStream() - || URIUtils::IsUPnP(strFile) - || URIUtils::IsBluray(strFile) - || IsLiveTV() - || IsPlugin() - || IsDVD()) + if (NETWORK::IsInternetStream(*this) || URIUtils::IsUPnP(strFile) || + URIUtils::IsBluray(strFile) || IsLiveTV() || IsPlugin() || IsDVD()) return ""; std::string strDir = URIUtils::GetDirectory(strFile); diff --git a/xbmc/FileItem.h b/xbmc/FileItem.h index 0fe427a650..7083cf77e0 100644 --- a/xbmc/FileItem.h +++ b/xbmc/FileItem.h @@ -172,8 +172,6 @@ public: bool IsDeleted() const; bool IsGame() const; - bool IsInternetStream(const bool bStrictCheck = false) const; - bool IsStreamedFilesystem() const; bool IsPlayList() const; bool IsSmartPlayList() const; bool IsLibraryFolder() const; @@ -194,10 +192,8 @@ public: bool IsISO9660() const; bool IsDVD() const; bool IsOnDVD() const; - bool IsOnLAN() const; bool IsHD() const; bool IsNfs() const; - bool IsRemote() const; bool IsSmb() const; bool IsURL() const; bool IsStack() const; diff --git a/xbmc/FileItemList.cpp b/xbmc/FileItemList.cpp index de52c4d9b8..e14b9a6c61 100644 --- a/xbmc/FileItemList.cpp +++ b/xbmc/FileItemList.cpp @@ -17,6 +17,7 @@ #include "filesystem/StackDirectory.h" #include "filesystem/VideoDatabaseDirectory.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "settings/AdvancedSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" @@ -758,7 +759,7 @@ void CFileItemList::StackFolders() // only check known fast sources? // NOTES: // 1. rars and zips may be on slow sources? is this supposed to be allowed? - if (!item->IsRemote() || item->IsSmb() || item->IsNfs() || + if (!NETWORK::IsRemote(*item) || item->IsSmb() || item->IsNfs() || URIUtils::IsInRAR(item->GetPath()) || URIUtils::IsInZIP(item->GetPath()) || URIUtils::IsOnLAN(item->GetPath())) { diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index dea659099c..82cc638bee 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -7,6 +7,7 @@ */ #include "network/Network.h" +#include "network/NetworkFileItemClassify.h" #include "video/VideoFileItemClassify.h" #if defined(TARGET_DARWIN) #include <sys/param.h> @@ -93,7 +94,7 @@ using namespace MEDIA_DETECT; using namespace XFILE; using namespace PLAYLIST; using KODI::UTILITY::CDigest; -using namespace KODI::VIDEO; +using namespace KODI; #if !defined(TARGET_WINDOWS) unsigned int CUtil::s_randomSeed = time(NULL); @@ -2056,8 +2057,8 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st auto start = std::chrono::steady_clock::now(); CFileItem item(strMovie, false); - if ((item.IsInternetStream() && !URIUtils::IsOnLAN(item.GetDynPath())) || item.IsPlayList() || - item.IsLiveTV() || !IsVideo(item)) + if ((NETWORK::IsInternetStream(item) && !URIUtils::IsOnLAN(item.GetDynPath())) || + item.IsPlayList() || item.IsLiveTV() || !VIDEO::IsVideo(item)) return; CLog::Log(LOGDEBUG, "{}: Searching for subtitles...", __FUNCTION__); @@ -2346,8 +2347,8 @@ std::string CUtil::GetVobSubIdxFromSub(const std::string& vobSub) void CUtil::ScanForExternalAudio(const std::string& videoPath, std::vector<std::string>& vecAudio) { CFileItem item(videoPath, false); - if (item.IsInternetStream() || item.IsPlayList() || item.IsLiveTV() || item.IsPVR() || - !IsVideo(item)) + if (NETWORK::IsInternetStream(item) || item.IsPlayList() || item.IsLiveTV() || item.IsPVR() || + !VIDEO::IsVideo(item)) return; std::string strBasePath; diff --git a/xbmc/application/Application.cpp b/xbmc/application/Application.cpp index baa561879c..1f5c65f64e 100644 --- a/xbmc/application/Application.cpp +++ b/xbmc/application/Application.cpp @@ -61,6 +61,7 @@ #include "filesystem/DllLibCurl.h" #include "filesystem/File.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "video/VideoFileItemClassify.h" #ifdef HAS_FILESYSTEM_NFS #include "filesystem/NFSFile.h" @@ -2198,7 +2199,7 @@ bool CApplication::PlayMedia(CFileItem& item, const std::string& player, PLAYLIS return ProcessAndStartPlaylist(smartpl.GetName(), playlist, smartplPlaylistId); } } - else if (item.IsPlayList() || item.IsInternetStream()) + else if (item.IsPlayList() || NETWORK::IsInternetStream(item)) { // Not owner. Dialog auto-deletes itself. CGUIDialogCache* dlgCache = diff --git a/xbmc/application/ApplicationPlayerCallback.cpp b/xbmc/application/ApplicationPlayerCallback.cpp index 258a528225..955de21f34 100644 --- a/xbmc/application/ApplicationPlayerCallback.cpp +++ b/xbmc/application/ApplicationPlayerCallback.cpp @@ -21,9 +21,9 @@ #include "guilib/GUIWindowManager.h" #include "guilib/StereoscopicsManager.h" #include "interfaces/AnnouncementManager.h" -#include "interfaces/json-rpc/JSONUtils.h" #include "interfaces/python/XBPython.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "profiles/ProfileManager.h" #include "settings/AdvancedSettings.h" #include "settings/MediaSettings.h" @@ -39,7 +39,6 @@ #include <memory> using namespace KODI; -using namespace KODI::VIDEO; CApplicationPlayerCallback::CApplicationPlayerCallback() { @@ -59,8 +58,9 @@ void CApplicationPlayerCallback::OnPlayBackStarted(const CFileItem& file) std::shared_ptr<CFileItem> itemCurrentFile; // check if VideoPlayer should set file item stream details from its current streams - const bool isBlu_dvd_image_or_stream = (URIUtils::IsBluray(file.GetPath()) || IsDVDFile(file) || - file.IsDiscImage() || file.IsInternetStream()); + const bool isBlu_dvd_image_or_stream = URIUtils::IsBluray(file.GetPath()) || + VIDEO::IsDVDFile(file) || file.IsDiscImage() || + NETWORK::IsInternetStream(file); const bool hasNoStreamDetails = (!file.HasVideoInfoTag() || !file.GetVideoInfoTag()->HasStreamDetails()); @@ -85,7 +85,7 @@ void CApplicationPlayerCallback::OnPlayBackStarted(const CFileItem& file) * This should speed up player startup for files on internet filesystems (eg. webdav) and * increase performance on low powered systems (Atom/ARM). */ - if (IsVideo(file) || file.IsGame()) + if (VIDEO::IsVideo(file) || file.IsGame()) { CServiceBroker::GetJobManager()->PauseJobs(); } @@ -133,7 +133,7 @@ void CApplicationPlayerCallback::OnPlayerCloseFile(const CFileItem& file, if ((MUSIC::IsAudio(fileItem) && advancedSettings->m_audioPlayCountMinimumPercent > 0 && percent >= advancedSettings->m_audioPlayCountMinimumPercent) || - (IsVideo(fileItem) && advancedSettings->m_videoPlayCountMinimumPercent > 0 && + (VIDEO::IsVideo(fileItem) && advancedSettings->m_videoPlayCountMinimumPercent > 0 && percent >= advancedSettings->m_videoPlayCountMinimumPercent)) { playCountUpdate = true; diff --git a/xbmc/cdrip/CDDARipJob.cpp b/xbmc/cdrip/CDDARipJob.cpp index 61726a5c42..3063a91e65 100644 --- a/xbmc/cdrip/CDDARipJob.cpp +++ b/xbmc/cdrip/CDDARipJob.cpp @@ -22,6 +22,7 @@ #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" +#include "network/NetworkFileItemClassify.h" #include "settings/AdvancedSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" @@ -37,6 +38,7 @@ using namespace ADDON; using namespace MUSIC_INFO; using namespace XFILE; +using namespace KODI; using namespace KODI::CDRIP; CCDDARipJob::CCDDARipJob(const std::string& input, @@ -66,7 +68,7 @@ bool CCDDARipJob::DoWork() // if we are ripping to a samba share, rip it to hd first and then copy it to the share CFileItem file(m_output, false); - if (file.IsRemote()) + if (NETWORK::IsRemote(file)) m_output = SetupTempFile(); if (m_output.empty()) @@ -115,7 +117,7 @@ bool CCDDARipJob::DoWork() encoder.reset(); reader.Close(); - if (file.IsRemote() && !cancelled && result == 2) + if (NETWORK::IsRemote(file) && !cancelled && result == 2) { // copy the ripped track to the share if (!CFile::Copy(m_output, file.GetPath())) diff --git a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp index 65dfc539de..9989176bb4 100644 --- a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp +++ b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp @@ -15,6 +15,7 @@ #include "ServiceBroker.h" #include "filesystem/StackDirectory.h" #include "guilib/Texture.h" +#include "network/NetworkFileItemClassify.h" #include "pictures/Picture.h" #include "settings/AdvancedSettings.h" #include "settings/SettingsComponent.h" @@ -262,7 +263,7 @@ bool CDVDFileInfo::CanExtract(const CFileItem& fileItem) URIUtils::IsPVRRecording(fileItem.GetDynPath()) || // plugin path not fully resolved URIUtils::IsPlugin(fileItem.GetDynPath()) || URIUtils::IsUPnP(fileItem.GetPath()) || - fileItem.IsInternetStream() || VIDEO::IsDiscStub(fileItem) || fileItem.IsPlayList()) + NETWORK::IsInternetStream(fileItem) || VIDEO::IsDiscStub(fileItem) || fileItem.IsPlayList()) return false; // mostly can't extract from discs and files from discs. diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp index 2b65938437..888c7477b5 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp @@ -9,6 +9,7 @@ #include "DVDFactoryInputStream.h" #include "DVDInputStream.h" +#include "network/NetworkFileItemClassify.h" #ifdef HAVE_LIBBLURAY #include "DVDInputStreamBluray.h" #endif @@ -139,7 +140,7 @@ std::shared_ptr<CDVDInputStream> CDVDFactoryInputStream::CreateInputStream(IVide CFileItem finalFileitem(fileitem); - if (finalFileitem.IsInternetStream()) + if (NETWORK::IsInternetStream(finalFileitem)) { if (finalFileitem.ContentLookup()) { diff --git a/xbmc/cores/VideoPlayer/VideoPlayer.cpp b/xbmc/cores/VideoPlayer/VideoPlayer.cpp index b43fe8c622..78e9cc3cdc 100644 --- a/xbmc/cores/VideoPlayer/VideoPlayer.cpp +++ b/xbmc/cores/VideoPlayer/VideoPlayer.cpp @@ -17,6 +17,7 @@ #include "DVDDemuxers/DVDFactoryDemuxer.h" #include "DVDInputStreams/DVDFactoryInputStream.h" #include "DVDInputStreams/DVDInputStream.h" +#include "network/NetworkFileItemClassify.h" #if defined(HAVE_LIBBLURAY) #include "DVDInputStreams/DVDInputStreamBluray.h" #endif @@ -46,6 +47,7 @@ #include "input/actions/Action.h" #include "input/actions/ActionIDs.h" #include "messaging/ApplicationMessenger.h" +#include "network/NetworkFileItemClassify.h" #include "settings/AdvancedSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" @@ -68,6 +70,7 @@ #include <mutex> #include <utility> +using namespace KODI; using namespace std::chrono_literals; //------------------------------------------------------------------------------ @@ -999,7 +1002,7 @@ void CVideoPlayer::OpenDefaultStreams(bool reset) CloseStream(m_CurrentAudioID3, false); // disable demux streams - if (m_item.IsRemote() && m_pDemuxer) + if (NETWORK::IsRemote(m_item) && m_pDemuxer) { for (auto &stream : m_SelectionStreams.m_Streams) { diff --git a/xbmc/cores/paplayer/AudioDecoder.cpp b/xbmc/cores/paplayer/AudioDecoder.cpp index a960776287..96075fd67e 100644 --- a/xbmc/cores/paplayer/AudioDecoder.cpp +++ b/xbmc/cores/paplayer/AudioDecoder.cpp @@ -17,11 +17,14 @@ #include "music/tags/MusicInfoTag.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" +#include "utils/URIUtils.h" #include "utils/log.h" #include <cmath> #include <mutex> +using namespace KODI; + CAudioDecoder::CAudioDecoder() { m_codec = NULL; @@ -75,7 +78,7 @@ bool CAudioDecoder::Create(const CFileItem &file, int64_t seekOffset) filecache = settings->GetInt(CSettings::SETTING_CACHE_HARDDISK); else if ( file.IsOnDVD() ) filecache = settings->GetInt(CSettings::SETTING_CACHEAUDIO_DVDROM); - else if (file.IsOnLAN()) + else if (URIUtils::IsOnLAN(file.GetPath())) filecache = settings->GetInt(CSettings::SETTING_CACHEAUDIO_LAN); // create our codec diff --git a/xbmc/cores/playercorefactory/PlayerSelectionRule.cpp b/xbmc/cores/playercorefactory/PlayerSelectionRule.cpp index 423b6f1643..3bee50aa06 100644 --- a/xbmc/cores/playercorefactory/PlayerSelectionRule.cpp +++ b/xbmc/cores/playercorefactory/PlayerSelectionRule.cpp @@ -12,12 +12,12 @@ #include "ServiceBroker.h" #include "URL.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" #include "utils/RegExp.h" #include "utils/StreamDetails.h" #include "utils/StringUtils.h" -#include "utils/XBMCTinyXML.h" #include "utils/XMLUtils.h" #include "utils/log.h" #include "video/VideoFileItemClassify.h" @@ -124,9 +124,9 @@ void CPlayerSelectionRule::GetPlayers(const CFileItem& item, std::vector<std::st return; if (m_tGame >= 0 && (m_tGame > 0) != item.IsGame()) return; - if (m_tInternetStream >= 0 && (m_tInternetStream > 0) != item.IsInternetStream()) + if (m_tInternetStream >= 0 && (m_tInternetStream > 0) != NETWORK::IsInternetStream(item)) return; - if (m_tRemote >= 0 && (m_tRemote > 0) != item.IsRemote()) + if (m_tRemote >= 0 && (m_tRemote > 0) != NETWORK::IsRemote(item)) return; if (m_tBD >= 0 && (m_tBD > 0) != (VIDEO::IsBDFile(item) && item.IsOnDVD())) @@ -207,5 +207,3 @@ void CPlayerSelectionRule::GetPlayers(const CFileItem& item, std::vector<std::st players.push_back(m_playerName); } } - - diff --git a/xbmc/filesystem/SourcesDirectory.cpp b/xbmc/filesystem/SourcesDirectory.cpp index 4f95b39b21..166861e323 100644 --- a/xbmc/filesystem/SourcesDirectory.cpp +++ b/xbmc/filesystem/SourcesDirectory.cpp @@ -16,6 +16,7 @@ #include "guilib/TextureManager.h" #include "media/MediaLockState.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "profiles/ProfileManager.h" #include "settings/MediaSourceSettings.h" #include "storage/MediaManager.h" @@ -75,7 +76,7 @@ bool CSourcesDirectory::GetDirectory(const VECSOURCES &sources, CFileItemList &i else if (VIDEO::IsVideoDb(*pItem) || MUSIC::IsMusicDb(*pItem) || pItem->IsPlugin() || pItem->IsPath("musicsearch://")) strIcon = "DefaultFolder.png"; - else if (pItem->IsRemote()) + else if (NETWORK::IsRemote(*pItem)) strIcon = "DefaultNetwork.png"; else if (pItem->IsISO9660()) strIcon = "DefaultDVDRom.png"; diff --git a/xbmc/guilib/guiinfo/MusicGUIInfo.cpp b/xbmc/guilib/guiinfo/MusicGUIInfo.cpp index 6edae7a808..cb246febda 100644 --- a/xbmc/guilib/guiinfo/MusicGUIInfo.cpp +++ b/xbmc/guilib/guiinfo/MusicGUIInfo.cpp @@ -25,6 +25,7 @@ #include "music/MusicInfoLoader.h" #include "music/MusicThumbLoader.h" #include "music/tags/MusicInfoTag.h" +#include "network/NetworkFileItemClassify.h" #include "playlists/PlayList.h" #include "settings/AdvancedSettings.h" #include "settings/SettingsComponent.h" @@ -40,7 +41,8 @@ bool CMusicGUIInfo::InitCurrentItem(CFileItem *item) { const auto& components = CServiceBroker::GetAppComponents(); const auto appPlayer = components.GetComponent<CApplicationPlayer>(); - if (item && (MUSIC::IsAudio(*item) || (item->IsInternetStream() && appPlayer->IsPlayingAudio()))) + if (item && + (MUSIC::IsAudio(*item) || (NETWORK::IsInternetStream(*item) && appPlayer->IsPlayingAudio()))) { CLog::Log(LOGDEBUG, "CMusicGUIInfo::InitCurrentItem({})", item->GetPath()); @@ -50,7 +52,7 @@ bool CMusicGUIInfo::InitCurrentItem(CFileItem *item) tag->SetLoaded(true); // find a thumb for this file. - if (item->IsInternetStream() && !MUSIC::IsMusicDb(*item)) + if (NETWORK::IsInternetStream(*item) && !MUSIC::IsMusicDb(*item)) { if (!g_application.m_strPlayListFile.empty()) { diff --git a/xbmc/guilib/guiinfo/VideoGUIInfo.cpp b/xbmc/guilib/guiinfo/VideoGUIInfo.cpp index 9e440b2539..6bec6186b7 100644 --- a/xbmc/guilib/guiinfo/VideoGUIInfo.cpp +++ b/xbmc/guilib/guiinfo/VideoGUIInfo.cpp @@ -26,6 +26,7 @@ #include "guilib/guiinfo/GUIInfo.h" #include "guilib/guiinfo/GUIInfoHelper.h" #include "guilib/guiinfo/GUIInfoLabels.h" +#include "network/NetworkFileItemClassify.h" #include "playlists/PlayList.h" #include "settings/AdvancedSettings.h" #include "settings/SettingUtils.h" @@ -66,7 +67,7 @@ bool CVideoGUIInfo::InitCurrentItem(CFileItem *item) if (item && VIDEO::IsVideo(*item)) { // special case where .strm is used to start an audio stream - if (item->IsInternetStream() && m_appPlayer->IsPlayingAudio()) + if (NETWORK::IsInternetStream(*item) && m_appPlayer->IsPlayingAudio()) return false; CLog::Log(LOGDEBUG, "CVideoGUIInfo::InitCurrentItem({})", CURL::GetRedacted(item->GetPath())); @@ -79,7 +80,7 @@ bool CVideoGUIInfo::InitCurrentItem(CFileItem *item) } // find a thumb for this stream - if (item->IsInternetStream()) + if (NETWORK::IsInternetStream(*item)) { if (!g_application.m_strPlayListFile.empty()) { diff --git a/xbmc/music/MusicInfoLoader.cpp b/xbmc/music/MusicInfoLoader.cpp index e49b511ad4..a6bff1a36e 100644 --- a/xbmc/music/MusicInfoLoader.cpp +++ b/xbmc/music/MusicInfoLoader.cpp @@ -21,6 +21,7 @@ #include "music/MusicFileItemClassify.h" #include "music/tags/MusicInfoTag.h" #include "music/tags/MusicInfoTagLoaderFactory.h" +#include "network/NetworkFileItemClassify.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" #include "utils/Archive.h" @@ -75,7 +76,7 @@ void CMusicInfoLoader::OnLoaderStart() bool CMusicInfoLoader::LoadAdditionalTagInfo(CFileItem* pItem) { if (!pItem || (pItem->m_bIsFolder && !MUSIC::IsAudio(*pItem)) || pItem->IsPlayList() || - pItem->IsNFO() || pItem->IsInternetStream()) + pItem->IsNFO() || NETWORK::IsInternetStream(*pItem)) return false; if (pItem->GetProperty("hasfullmusictag") == "true") @@ -152,7 +153,7 @@ bool CMusicInfoLoader::LoadItemCached(CFileItem* pItem) pItem->IsSmartPlayList() || StringUtils::StartsWithNoCase(pItem->GetPath(), "newplaylist://") || StringUtils::StartsWithNoCase(pItem->GetPath(), "newsmartplaylist://") || pItem->IsNFO() || - (pItem->IsInternetStream() && !MUSIC::IsMusicDb(*pItem))) + (NETWORK::IsInternetStream(*pItem) && !MUSIC::IsMusicDb(*pItem))) return false; // Get thumb for item @@ -170,7 +171,7 @@ bool CMusicInfoLoader::LoadItemLookup(CFileItem* pItem) pItem->IsPlayList() || pItem->IsSmartPlayList() || // StringUtils::StartsWithNoCase(pItem->GetPath(), "newplaylist://") || // StringUtils::StartsWithNoCase(pItem->GetPath(), "newsmartplaylist://") || // - pItem->IsNFO() || (pItem->IsInternetStream() && !MUSIC::IsMusicDb(*pItem))) + pItem->IsNFO() || (NETWORK::IsInternetStream(*pItem) && !MUSIC::IsMusicDb(*pItem))) return false; if ((!pItem->HasMusicInfoTag() || !pItem->GetMusicInfoTag()->Loaded()) && MUSIC::IsAudio(*pItem)) diff --git a/xbmc/music/MusicUtils.cpp b/xbmc/music/MusicUtils.cpp index bac6901bf0..c3e6b71625 100644 --- a/xbmc/music/MusicUtils.cpp +++ b/xbmc/music/MusicUtils.cpp @@ -31,6 +31,7 @@ #include "music/MusicDbUrl.h" #include "music/MusicFileItemClassify.h" #include "music/tags/MusicInfoTag.h" +#include "network/NetworkFileItemClassify.h" #include "playlists/PlayList.h" #include "playlists/PlayListFactory.h" #include "profiles/ProfileManager.h" @@ -601,7 +602,7 @@ void CAsyncGetItemsForPlaylist::GetItemsForPlaylist(const std::shared_ptr<CFileI GetItemsForPlaylist((*playList)[i]); } } - else if (item->IsInternetStream() && !MUSIC::IsMusicDb(*item)) + else if (NETWORK::IsInternetStream(*item) && !MUSIC::IsMusicDb(*item)) { // just queue the internet stream, it will be expanded on play m_queuedItems.Add(item); diff --git a/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp b/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp index b5e3567bda..523b0bf233 100644 --- a/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp +++ b/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp @@ -19,6 +19,7 @@ #include "addons/ExtsMimeSupportList.h" #include "addons/addoninfo/AddonType.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" @@ -33,7 +34,7 @@ CMusicInfoTagLoaderFactory::~CMusicInfoTagLoaderFactory() = default; IMusicInfoTagLoader* CMusicInfoTagLoaderFactory::CreateLoader(const CFileItem& item) { // dont try to read the tags for streams & shoutcast - if (item.IsInternetStream()) + if (NETWORK::IsInternetStream(item)) return NULL; if (MUSIC::IsMusicDb(item)) diff --git a/xbmc/music/windows/GUIWindowMusicBase.cpp b/xbmc/music/windows/GUIWindowMusicBase.cpp index 3ebcc46f86..5ace8dcfe4 100644 --- a/xbmc/music/windows/GUIWindowMusicBase.cpp +++ b/xbmc/music/windows/GUIWindowMusicBase.cpp @@ -24,6 +24,7 @@ #include "application/ApplicationComponents.h" #include "application/ApplicationPlayer.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "video/VideoFileItemClassify.h" #ifdef HAS_CDDA_RIPPER #include "cdrip/CDDARipper.h" @@ -711,7 +712,7 @@ bool CGUIWindowMusicBase::OnPlayMedia(int iItem, const std::string &player) g_partyModeManager.AddUserSongs(playlistTemp, !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICPLAYER_QUEUEBYDEFAULT)); return true; } - else if (!pItem->IsPlayList() && !pItem->IsInternetStream()) + else if (!pItem->IsPlayList() && !NETWORK::IsInternetStream(*pItem)) { // single music file - if we get here then we have autoplaynextitem turned off or queuebydefault // turned on, but we still want to use the playlist player in order to handle more queued items // following etc. diff --git a/xbmc/music/windows/GUIWindowMusicNav.cpp b/xbmc/music/windows/GUIWindowMusicNav.cpp index 3f6cd7508f..46e1fab725 100644 --- a/xbmc/music/windows/GUIWindowMusicNav.cpp +++ b/xbmc/music/windows/GUIWindowMusicNav.cpp @@ -33,6 +33,7 @@ #include "music/MusicLibraryQueue.h" #include "music/dialogs/GUIDialogInfoProviderSettings.h" #include "music/tags/MusicInfoTag.h" +#include "network/NetworkFileItemClassify.h" #include "playlists/PlayList.h" #include "playlists/PlayListFactory.h" #include "profiles/ProfileManager.h" @@ -612,7 +613,8 @@ void CGUIWindowMusicNav::GetContextButtons(int itemNumber, CContextButtons &butt // Scan button for real folders containing files when navigating within music sources. // Blacklist the bespoke Kodi protocols as to many valid external protocols to whitelist if (m_vecItems->GetContent() == "files" && // Other content not scanned to library - !inPlaylists && !m_vecItems->IsInternetStream() && // Not playlists locations or streams + !inPlaylists && + !NETWORK::IsInternetStream(*m_vecItems) && // Not playlists locations or streams !item->IsPath("add") && !item->IsParentFolder() && // Not ".." and "Add items item->m_bIsFolder && // Folders only, but playlists can be folders too !URIUtils::IsLibraryContent(item->GetPath()) && // database folder or .xsp files diff --git a/xbmc/network/CMakeLists.txt b/xbmc/network/CMakeLists.txt index 147af290b6..2060605761 100644 --- a/xbmc/network/CMakeLists.txt +++ b/xbmc/network/CMakeLists.txt @@ -4,6 +4,7 @@ set(SOURCES DNSNameCache.cpp EventServer.cpp GUIDialogNetworkSetup.cpp Network.cpp + NetworkFileItemClassify.cpp NetworkServices.cpp Socket.cpp TCPServer.cpp @@ -18,6 +19,7 @@ set(HEADERS DNSNameCache.h EventServer.h GUIDialogNetworkSetup.h Network.h + NetworkFileItemClassify.h NetworkServices.h Socket.h TCPServer.h diff --git a/xbmc/network/NetworkFileItemClassify.cpp b/xbmc/network/NetworkFileItemClassify.cpp new file mode 100644 index 0000000000..ed4bd77be6 --- /dev/null +++ b/xbmc/network/NetworkFileItemClassify.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005-2020 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "network/NetworkFileItemClassify.h" + +#include "FileItem.h" +#include "utils/URIUtils.h" + +namespace KODI::NETWORK +{ + +bool IsInternetStream(const CFileItem& item, const bool bStrictCheck /* = false */) +{ + if (item.HasProperty("IsHTTPDirectory")) + return bStrictCheck; + + if (!item.GetDynPath().empty()) + return URIUtils::IsInternetStream(item.GetDynPath(), bStrictCheck); + + return URIUtils::IsInternetStream(item.GetPath(), bStrictCheck); +} + +bool IsRemote(const CFileItem& item) +{ + return URIUtils::IsRemote(item.GetPath()); +} + +bool IsStreamedFilesystem(const CFileItem& item) +{ + if (!item.GetDynPath().empty()) + return URIUtils::IsStreamedFilesystem(item.GetDynPath()); + + return URIUtils::IsStreamedFilesystem(item.GetPath()); +} + +} // namespace KODI::NETWORK diff --git a/xbmc/network/NetworkFileItemClassify.h b/xbmc/network/NetworkFileItemClassify.h new file mode 100644 index 0000000000..5a96a98253 --- /dev/null +++ b/xbmc/network/NetworkFileItemClassify.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +class CFileItem; + +namespace KODI::NETWORK +{ + +//! \brief Check whether an item is a an internet stream. +bool IsInternetStream(const CFileItem& item, const bool bStrictCheck = false); + +//! \brief Check whether an item is on a remote location. +bool IsRemote(const CFileItem& item); + +//! \brief Check whether an item is on a streamed filesystem. +bool IsStreamedFilesystem(const CFileItem& item); +} // namespace KODI::NETWORK diff --git a/xbmc/network/test/CMakeLists.txt b/xbmc/network/test/CMakeLists.txt index 05eb260c0b..b075775736 100644 --- a/xbmc/network/test/CMakeLists.txt +++ b/xbmc/network/test/CMakeLists.txt @@ -1,4 +1,5 @@ -set(SOURCES TestNetwork.cpp) +set(SOURCES TestNetwork.cpp + TestNetworkFileItemClassify.cpp) if(MICROHTTPD_FOUND) list(APPEND SOURCES TestWebServer.cpp) diff --git a/xbmc/network/test/TestNetworkFileItemClassify.cpp b/xbmc/network/test/TestNetworkFileItemClassify.cpp new file mode 100644 index 0000000000..13dbd44c72 --- /dev/null +++ b/xbmc/network/test/TestNetworkFileItemClassify.cpp @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "FileItem.h" +#include "URL.h" +#include "filesystem/StackDirectory.h" +#include "network/NetworkFileItemClassify.h" + +#include <array> +#include <string> + +#include <gtest/gtest.h> + +using namespace KODI; + +namespace +{ + +struct SimpleDefinition +{ + SimpleDefinition(const std::string& path, bool folder, bool res) : item(path, folder), result(res) + { + } + + CFileItem item; + bool result; +}; + +} // namespace + +struct InternetStreamDefinition +{ + InternetStreamDefinition(const std::string& path, bool folder, bool strict, bool res) + : item(path, folder), strictCheck(strict), result(res) + { + } + + CFileItem item; + bool strictCheck; + bool result; +}; + +class InternetStreamTest : public testing::WithParamInterface<InternetStreamDefinition>, + public testing::Test +{ +}; + +TEST_P(InternetStreamTest, IsInternetStream) +{ + EXPECT_EQ(NETWORK::IsInternetStream(GetParam().item, GetParam().strictCheck), GetParam().result); +} + +const auto inetstream_tests = std::array{ + InternetStreamDefinition{"/home/user/test.disc", false, false, false}, + InternetStreamDefinition{"/home/user/test.disc", true, true, false}, + InternetStreamDefinition{"http://some.where/foo", false, false, true}, + InternetStreamDefinition{"http://some.where/foo", false, true, true}, + InternetStreamDefinition{"http://some.where/foo", true, false, true}, + InternetStreamDefinition{"http://some.where/foo", true, true, true}, + InternetStreamDefinition{"https://some.where/foo", false, false, true}, + InternetStreamDefinition{"https://some.where/foo", false, true, true}, + InternetStreamDefinition{"https://some.where/foo", true, false, true}, + InternetStreamDefinition{"https://some.where/foo", true, true, true}, + InternetStreamDefinition{"tcp://some.where/foo", false, false, true}, + InternetStreamDefinition{"tcp://some.where/foo", false, true, true}, + InternetStreamDefinition{"tcp://some.where/foo", true, false, true}, + InternetStreamDefinition{"tcp://some.where/foo", true, true, true}, + InternetStreamDefinition{"udp://some.where/foo", false, false, true}, + InternetStreamDefinition{"udp://some.where/foo", false, true, true}, + InternetStreamDefinition{"udp://some.where/foo", true, false, true}, + InternetStreamDefinition{"udp://some.where/foo", true, true, true}, + InternetStreamDefinition{"rtp://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtp://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtp://some.where/foo", true, false, true}, + InternetStreamDefinition{"rtp://some.where/foo", true, true, true}, + InternetStreamDefinition{"sdp://some.where/foo", false, false, true}, + InternetStreamDefinition{"sdp://some.where/foo", false, true, true}, + InternetStreamDefinition{"sdp://some.where/foo", true, false, true}, + InternetStreamDefinition{"sdp://some.where/foo", true, true, true}, + InternetStreamDefinition{"mms://some.where/foo", false, false, true}, + InternetStreamDefinition{"mms://some.where/foo", false, true, true}, + InternetStreamDefinition{"mms://some.where/foo", true, false, true}, + InternetStreamDefinition{"mms://some.where/foo", true, true, true}, + InternetStreamDefinition{"mmst://some.where/foo", false, false, true}, + InternetStreamDefinition{"mmst://some.where/foo", false, true, true}, + InternetStreamDefinition{"mmst://some.where/foo", true, false, true}, + InternetStreamDefinition{"mmst://some.where/foo", true, true, true}, + InternetStreamDefinition{"mmsh://some.where/foo", false, false, true}, + InternetStreamDefinition{"mmsh://some.where/foo", false, true, true}, + InternetStreamDefinition{"mmsh://some.where/foo", true, false, true}, + InternetStreamDefinition{"mmsh://some.where/foo", true, true, true}, + InternetStreamDefinition{"rtsp://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtsp://some.where/foo", false, true, true}, + InternetStreamDefinition{"rtsp://some.where/foo", true, false, true}, + InternetStreamDefinition{"rtsp://some.where/foo", true, true, true}, + InternetStreamDefinition{"rtmp://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtmp://some.where/foo", false, true, true}, + InternetStreamDefinition{"rtmp://some.where/foo", true, false, true}, + InternetStreamDefinition{"rtmp://some.where/foo", true, true, true}, + InternetStreamDefinition{"rtmpt://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtmpt://some.where/foo", false, true, true}, + InternetStreamDefinition{"rtmpt://some.where/foo", true, false, true}, + InternetStreamDefinition{"rtmpt://some.where/foo", true, true, true}, + InternetStreamDefinition{"rtmpe://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtmpe://some.where/foo", false, true, true}, + InternetStreamDefinition{"rtmpe://some.where/foo", true, false, true}, + InternetStreamDefinition{"rtmpe://some.where/foo", true, true, true}, + InternetStreamDefinition{"rtmpte://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtmpte://some.where/foo", false, true, true}, + InternetStreamDefinition{"rtmpte://some.where/foo", true, false, true}, + InternetStreamDefinition{"rtmpte://some.where/foo", true, true, true}, + InternetStreamDefinition{"rtmps://some.where/foo", false, false, true}, + InternetStreamDefinition{"rtmps://some.where/foo", false, true, true}, + InternetStreamDefinition{"rtmps://some.where/foo", true, false, true}, + InternetStreamDefinition{"rtmps://some.where/foo", true, true, true}, + InternetStreamDefinition{"shout://some.where/foo", false, false, true}, + InternetStreamDefinition{"shout://some.where/foo", false, true, true}, + InternetStreamDefinition{"shout://some.where/foo", true, false, true}, + InternetStreamDefinition{"shout://some.where/foo", true, true, true}, + InternetStreamDefinition{"rss://some.where/foo", false, false, true}, + InternetStreamDefinition{"rss://some.where/foo", false, true, true}, + InternetStreamDefinition{"rss://some.where/foo", true, false, true}, + InternetStreamDefinition{"rss://some.where/foo", true, true, true}, + InternetStreamDefinition{"rsss://some.where/foo", false, false, true}, + InternetStreamDefinition{"rsss://some.where/foo", false, true, true}, + InternetStreamDefinition{"rsss://some.where/foo", true, false, true}, + InternetStreamDefinition{"rsss://some.where/foo", true, true, true}, + InternetStreamDefinition{"upnp://some.where/foo", false, false, false}, + InternetStreamDefinition{"upnp://some.where/foo", true, false, false}, + InternetStreamDefinition{"upnp://some.where/foo", false, true, true}, + InternetStreamDefinition{"upnp://some.where/foo", true, true, true}, + InternetStreamDefinition{"ftp://some.where/foo", false, false, false}, + InternetStreamDefinition{"ftp://some.where/foo", true, false, false}, + InternetStreamDefinition{"ftp://some.where/foo", false, true, true}, + InternetStreamDefinition{"ftp://some.where/foo", true, true, true}, + InternetStreamDefinition{"sftp://some.where/foo", false, false, false}, + InternetStreamDefinition{"sftp://some.where/foo", true, false, false}, + InternetStreamDefinition{"sftp://some.where/foo", false, true, true}, + InternetStreamDefinition{"sftp://some.where/foo", true, true, true}, + InternetStreamDefinition{"ssh://some.where/foo", false, false, false}, + InternetStreamDefinition{"ssh://some.where/foo", true, false, false}, + InternetStreamDefinition{"ssh://some.where/foo", false, true, true}, + InternetStreamDefinition{"ssh://some.where/foo", true, true, true}, + InternetStreamDefinition{"ssh://some.where/foo", true, true, true}, +}; + +INSTANTIATE_TEST_SUITE_P(TestNetworkFileItemClassify, + InternetStreamTest, + testing::ValuesIn(inetstream_tests)); + +TEST(TestNetworkWorkFileItemClassify, InternetStreamStacks) +{ + std::string stackPath; + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"/home/foo/somthing.avi", "/home/bar/else.mkv"}, stackPath)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, false), false)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, true), false)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, false), true)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, true), true)); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"https://home/foo/somthing.avi", "https://home/bar/else.mkv"}, stackPath)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, false), false)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, true), false)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, false), true)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, true), true)); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"ftp://home/foo/somthing.avi", "ftp://home/bar/else.mkv"}, stackPath)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, false), false)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, true), false)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, false), true)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, true), true)); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"ftp://home/foo/somthing.avi", "/home/bar/else.mkv"}, stackPath)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, false), false)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, true), false)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, false), true)); + EXPECT_TRUE(NETWORK::IsInternetStream(CFileItem(stackPath, true), true)); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"/home/foo/somthing.avi", "ftp://home/bar/else.mkv"}, stackPath)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, false), false)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, true), false)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, false), true)); + EXPECT_FALSE(NETWORK::IsInternetStream(CFileItem(stackPath, true), true)); +} + +class RemoteTest : public testing::WithParamInterface<SimpleDefinition>, public testing::Test +{ +}; + +TEST_P(RemoteTest, IsRemote) +{ + EXPECT_EQ(NETWORK::IsRemote(GetParam().item), GetParam().result); +} + +const auto remote_tests = std::array{ + SimpleDefinition{"cdda://1", false, false}, + SimpleDefinition{"cdda://1", true, false}, + SimpleDefinition{"iso9660://some.file", false, false}, + SimpleDefinition{"cdda://some.file", true, false}, + SimpleDefinition{"special://home/foo.xml", false, false}, + SimpleDefinition{"special://home", true, false}, + SimpleDefinition{"zip://" + CURL::Encode("/home/foo/bar.zip"), true, false}, + SimpleDefinition{"zip://" + CURL::Encode("https://some.where/yo.zip"), true, true}, + SimpleDefinition{"addons://plugins", true, false}, + SimpleDefinition{"sources://music", true, false}, + SimpleDefinition{"videodb://1/2", true, false}, + SimpleDefinition{"musicdb://1/2", true, false}, + SimpleDefinition{"library://movies/titles", true, false}, + SimpleDefinition{"plugin://plugin.video.yo", true, false}, + SimpleDefinition{"androidapp://cool.app", true, false}, + SimpleDefinition{"/home/foo/bar", true, false}, + SimpleDefinition{"https://127.0.0.1/bar", true, false}, + SimpleDefinition{"https://some.where/bar", true, true}, +}; + +INSTANTIATE_TEST_SUITE_P(TestNetworkFileItemClassify, RemoteTest, testing::ValuesIn(remote_tests)); + +class StreamedFilesystemTest : public testing::WithParamInterface<SimpleDefinition>, + public testing::Test +{ +}; + +TEST_P(StreamedFilesystemTest, IsStreamedFilesystem) +{ + EXPECT_EQ(NETWORK::IsStreamedFilesystem(GetParam().item), GetParam().result); +} + +const auto streamedfs_tests = std::array{ + SimpleDefinition{"/home/user/test.disc", false, false}, + SimpleDefinition{"/home/user/test.disc", true, false}, + SimpleDefinition{"http://some.where/foo", false, true}, + SimpleDefinition{"http://some.where/foo", true, true}, + SimpleDefinition{"https://some.where/foo", false, true}, + SimpleDefinition{"https://some.where/foo", true, true}, + SimpleDefinition{"ftp://some.where/foo", false, true}, + SimpleDefinition{"ftp://some.where/foo", true, true}, + SimpleDefinition{"sftp://some.where/foo", false, true}, + SimpleDefinition{"sftp://some.where/foo", true, true}, + SimpleDefinition{"ssh://some.where/foo", false, true}, + SimpleDefinition{"ssh://some.where/foo", true, true}, + SimpleDefinition{"ssh://some.where/foo", true, true}, +}; + +INSTANTIATE_TEST_SUITE_P(TestNetworkFileItemClassify, + StreamedFilesystemTest, + testing::ValuesIn(streamedfs_tests)); + +TEST(TestNetworkWorkFileItemClassify, StreamedFilesystemStacks) +{ + std::string stackPath; + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"/home/foo/somthing.avi", "/home/bar/else.mkv"}, stackPath)); + EXPECT_FALSE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, false))); + EXPECT_FALSE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, true))); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"https://home/foo/somthing.avi", "https://home/bar/else.mkv"}, stackPath)); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, false))); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, true))); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"shout://home/foo/somthing.avi", "shout://home/bar/else.mkv"}, stackPath)); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, false))); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, true))); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"ftp://home/foo/somthing.avi", "ftp://home/bar/else.mkv"}, stackPath)); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, false))); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, true))); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"ftp://home/foo/somthing.avi", "/home/bar/else.mkv"}, stackPath)); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, false))); + EXPECT_TRUE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, true))); + + EXPECT_TRUE(XFILE::CStackDirectory::ConstructStackPath( + {"/home/foo/somthing.avi", "ftp://home/bar/else.mkv"}, stackPath)); + EXPECT_FALSE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, false))); + EXPECT_FALSE(NETWORK::IsStreamedFilesystem(CFileItem(stackPath, true))); +} diff --git a/xbmc/pictures/PictureInfoLoader.cpp b/xbmc/pictures/PictureInfoLoader.cpp index 14a880bcec..507834e5bd 100644 --- a/xbmc/pictures/PictureInfoLoader.cpp +++ b/xbmc/pictures/PictureInfoLoader.cpp @@ -12,6 +12,7 @@ #include "FileItemList.h" #include "PictureInfoTag.h" #include "ServiceBroker.h" +#include "network/NetworkFileItemClassify.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" #include "video/VideoFileItemClassify.h" @@ -55,7 +56,7 @@ bool CPictureInfoLoader::LoadItem(CFileItem* pItem) bool CPictureInfoLoader::LoadItemCached(CFileItem* pItem) { if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() || - pItem->IsInternetStream() || VIDEO::IsVideo(*pItem)) + NETWORK::IsInternetStream(*pItem) || VIDEO::IsVideo(*pItem)) return false; if (pItem->HasPictureInfoTag()) @@ -79,7 +80,7 @@ bool CPictureInfoLoader::LoadItemLookup(CFileItem* pItem) m_pProgressCallback->SetProgressAdvance(); if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() || - pItem->IsInternetStream() || VIDEO::IsVideo(*pItem)) + NETWORK::IsInternetStream(*pItem) || VIDEO::IsVideo(*pItem)) return false; if (pItem->HasPictureInfoTag()) diff --git a/xbmc/playlists/PlayListFactory.cpp b/xbmc/playlists/PlayListFactory.cpp index dc45bcce2d..4bae13dd27 100644 --- a/xbmc/playlists/PlayListFactory.cpp +++ b/xbmc/playlists/PlayListFactory.cpp @@ -9,6 +9,7 @@ #include "PlayListFactory.h" #include "FileItem.h" +#include "network/NetworkFileItemClassify.h" #include "playlists/PlayListB4S.h" #include "playlists/PlayListM3U.h" #include "playlists/PlayListPLS.h" @@ -19,6 +20,7 @@ #include "utils/StringUtils.h" #include "utils/URIUtils.h" +using namespace KODI; using namespace PLAYLIST; CPlayList* CPlayListFactory::Create(const std::string& filename) @@ -29,7 +31,7 @@ CPlayList* CPlayListFactory::Create(const std::string& filename) CPlayList* CPlayListFactory::Create(const CFileItem& item) { - if (item.IsInternetStream()) + if (NETWORK::IsInternetStream(item)) { // Ensure the MIME type has been retrieved for http:// and shout:// streams if (item.GetMimeType().empty()) @@ -71,7 +73,8 @@ CPlayList* CPlayListFactory::Create(const CFileItem& item) std::string extension = URIUtils::GetExtension(path); StringUtils::ToLower(extension); - if (extension == ".m3u" || (extension == ".m3u8" && !item.IsInternetStream()) || extension == ".strm") + if (extension == ".m3u" || (extension == ".m3u8" && !NETWORK::IsInternetStream(item)) || + extension == ".strm") return new CPlayListM3U(); if (extension == ".pls") @@ -120,7 +123,7 @@ bool CPlayListFactory::IsPlaylist(const CFileItem& item) */ // online m3u8 files are hls:// -- do not treat as playlist - if (item.IsInternetStream() && item.IsType(".m3u8")) + if (NETWORK::IsInternetStream(item) && item.IsType(".m3u8")) return false; if(strMimeType == "audio/x-pn-realaudio" diff --git a/xbmc/video/VideoThumbLoader.cpp b/xbmc/video/VideoThumbLoader.cpp index 3522043a21..cc14f55f2f 100644 --- a/xbmc/video/VideoThumbLoader.cpp +++ b/xbmc/video/VideoThumbLoader.cpp @@ -22,6 +22,7 @@ #include "guilib/StereoscopicsManager.h" #include "music/MusicDatabase.h" #include "music/tags/MusicInfoTag.h" +#include "network/NetworkFileItemClassify.h" #include "settings/AdvancedSettings.h" #include "settings/SettingUtils.h" #include "settings/Settings.h" @@ -524,7 +525,7 @@ std::string CVideoThumbLoader::GetLocalArt(const CFileItem &item, const std::str settings ? settings->GetInt(CSettings::SETTING_FILECACHE_BUFFERMODE) == CACHE_BUFFER_MODE_ALL : false; - if (item.m_bIsFolder && (item.IsStreamedFilesystem() || cacheAll)) + if (item.m_bIsFolder && (NETWORK::IsStreamedFilesystem(item) || cacheAll)) { CFileItemList items; // Dummy list CDirectory::GetDirectory(item.GetPath(), items, "", DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_READ_CACHE | DIR_FLAG_NO_FILE_INFO); diff --git a/xbmc/video/guilib/VideoGUIUtils.cpp b/xbmc/video/guilib/VideoGUIUtils.cpp index 36464cae95..8cadb0e755 100644 --- a/xbmc/video/guilib/VideoGUIUtils.cpp +++ b/xbmc/video/guilib/VideoGUIUtils.cpp @@ -24,6 +24,7 @@ #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" #include "music/MusicFileItemClassify.h" +#include "network/NetworkFileItemClassify.h" #include "playlists/PlayList.h" #include "playlists/PlayListFactory.h" #include "profiles/ProfileManager.h" @@ -295,7 +296,7 @@ void CAsyncGetItemsForPlaylist::GetItemsForPlaylist(const std::shared_ptr<CFileI // just queue the playlist, it will be expanded on play m_queuedItems.Add(item); } - else if (item->IsInternetStream()) + else if (NETWORK::IsInternetStream(*item)) { // just queue the internet stream, it will be expanded on play m_queuedItems.Add(item); diff --git a/xbmc/video/windows/GUIWindowVideoBase.cpp b/xbmc/video/windows/GUIWindowVideoBase.cpp index 6a9f1faecf..50da6ba3b8 100644 --- a/xbmc/video/windows/GUIWindowVideoBase.cpp +++ b/xbmc/video/windows/GUIWindowVideoBase.cpp @@ -37,6 +37,7 @@ #include "input/actions/ActionIDs.h" #include "messaging/helpers/DialogOKHelper.h" #include "music/dialogs/GUIDialogMusicInfo.h" +#include "network/NetworkFileItemClassify.h" #include "playlists/PlayList.h" #include "playlists/PlayListFactory.h" #include "profiles/ProfileManager.h" @@ -1231,8 +1232,9 @@ bool CGUIWindowVideoBase::GetDirectory(const std::string &strDirectory, CFileIte bool CGUIWindowVideoBase::StackingAvailable(const CFileItemList &items) { CURL url(items.GetPath()); - return !(items.IsPlugin() || items.IsAddonsPath() || items.IsRSS() || items.IsInternetStream() || - VIDEO::IsVideoDb(items) || url.IsProtocol("playlistvideo")); + return !(items.IsPlugin() || items.IsAddonsPath() || items.IsRSS() || + NETWORK::IsInternetStream(items) || VIDEO::IsVideoDb(items) || + url.IsProtocol("playlistvideo")); } void CGUIWindowVideoBase::GetGroupedItems(CFileItemList &items) diff --git a/xbmc/windows/GUIMediaWindow.cpp b/xbmc/windows/GUIMediaWindow.cpp index 62cf70e6d0..f764b671c5 100644 --- a/xbmc/windows/GUIMediaWindow.cpp +++ b/xbmc/windows/GUIMediaWindow.cpp @@ -24,6 +24,7 @@ #include "addons/addoninfo/AddonType.h" #include "application/Application.h" #include "messaging/ApplicationMessenger.h" +#include "network/NetworkFileItemClassify.h" #if defined(TARGET_ANDROID) #include "platform/android/activity/XBMCApp.h" #endif @@ -76,8 +77,8 @@ #define PLUGIN_REFRESH_DELAY 200 using namespace ADDON; +using namespace KODI; using namespace KODI::MESSAGING; -using namespace KODI::VIDEO; using namespace std::chrono_literals; namespace @@ -1500,7 +1501,7 @@ bool CGUIMediaWindow::OnPlayMedia(int iItem, const std::string &player) CLog::Log(LOGDEBUG, "{} {}", __FUNCTION__, CURL::GetRedacted(pItem->GetPath())); bool bResult = false; - if (pItem->IsInternetStream() || pItem->IsPlayList()) + if (NETWORK::IsInternetStream(*pItem) || pItem->IsPlayList()) bResult = g_application.PlayMedia(*pItem, player, m_guiState->GetPlaylist()); else bResult = g_application.PlayFile(*pItem, player); |