From 590d6da3dafa5c9fcfb9e545be04dda00ff0d00f Mon Sep 17 00:00:00 2001 From: taxigps Date: Sat, 6 Nov 2021 16:52:30 +0800 Subject: [PATCH] [subtitle] load .sup subtitle like other external subtitles. --- xbmc/Util.cpp | 56 ------------------- xbmc/Util.h | 1 - .../DVDInputStreams/DVDFactoryInputStream.cpp | 1 - xbmc/cores/VideoPlayer/VideoPlayer.cpp | 53 +++++++++++++----- xbmc/network/upnp/UPnPInternal.cpp | 2 +- xbmc/platform/darwin/ios/Info.plist.in | 1 + xbmc/settings/AdvancedSettings.cpp | 2 +- .../dialogs/GUIDialogSubtitleSettings.cpp | 4 +- 8 files changed, 45 insertions(+), 75 deletions(-) diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index 420ce1853abfc..d36309736875c 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -2279,62 +2279,6 @@ std::string CUtil::GetVobSubIdxFromSub(const std::string& vobSub) return std::string(); } -void CUtil::ScanForExternalDemuxSub(const std::string& videoPath, std::vector& vecSubtitles) -{ - CFileItem item(videoPath, false); - if (item.IsInternetStream() - || item.IsPlayList() - || item.IsLiveTV() - || item.IsPVR() - || !item.IsVideo()) - return; - - std::string strBasePath; - std::string strSubtitle; - - GetVideoBasePathAndFileName(videoPath, strBasePath, strSubtitle); - - CFileItemList items; - const std::vector common_sub_dirs = { "subs", "subtitles", "vobsubs", "sub", "vobsub", "subtitle" }; - const std::string demuxSubExtensions = ".sup"; - GetItemsToScan(strBasePath, demuxSubExtensions, common_sub_dirs, items); - - const std::string customPath = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( - CSettings::SETTING_SUBTITLES_CUSTOMPATH); - - if (!CMediaSettings::GetInstance().GetAdditionalSubtitleDirectoryChecked() && - !customPath.empty()) // to avoid checking non-existent directories (network) every time.. - { - if (!CServiceBroker::GetNetwork().IsAvailable() && !URIUtils::IsHD(customPath)) - { - CLog::Log(LOGINFO, "CUtil::CacheSubtitles: disabling alternate subtitle directory for this " - "session, it's inaccessible"); - CMediaSettings::GetInstance().SetAdditionalSubtitleDirectoryChecked(-1); // disabled - } - else if (!CDirectory::Exists(customPath)) - { - CLog::Log(LOGINFO, "CUtil::CacheSubtitles: disabling alternate subtitle directory for this " - "session, it's nonexistent"); - CMediaSettings::GetInstance().SetAdditionalSubtitleDirectoryChecked(-1); // disabled - } - else - CMediaSettings::GetInstance().SetAdditionalSubtitleDirectoryChecked(1); - } - - if (CMediaSettings::GetInstance().GetAdditionalSubtitleDirectoryChecked() == 1) - { - std::string strPath2 = customPath; - URIUtils::AddSlashAtEnd(strPath2); - int flags = DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_NO_FILE_INFO; - CFileItemList moreItems; - CDirectory::GetDirectory(strPath2, moreItems, demuxSubExtensions, flags); - items.Append(moreItems); - } - - std::vector exts = StringUtils::Split(demuxSubExtensions, "|"); - ScanPathsForAssociatedItems(strSubtitle, items, exts, vecSubtitles); -} - void CUtil::ScanForExternalAudio(const std::string& videoPath, std::vector& vecAudio) { CFileItem item(videoPath, false); diff --git a/xbmc/Util.h b/xbmc/Util.h index 97986424ed0bf..908981fe80fef 100644 --- a/xbmc/Util.h +++ b/xbmc/Util.h @@ -87,7 +87,6 @@ class CUtil * \param[out] vecAudio A vector containing the full paths of all found external audio files. */ static void ScanForExternalAudio(const std::string& videoPath, std::vector& vecAudio); - static void ScanForExternalDemuxSub(const std::string& videoPath, std::vector& vecSubtitles); static int64_t ToInt64(uint32_t high, uint32_t low); static std::string GetNextFilename(const std::string &fn_template, int max); static std::string GetNextPathname(const std::string &path_template, int max); diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp index 255acc2a7faa1..55bbf69fbce24 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp @@ -44,7 +44,6 @@ std::shared_ptr CDVDFactoryInputStream::CreateInputStream(IVide std::vector filenames; filenames.push_back(file); CUtil::ScanForExternalAudio(file, filenames); - CUtil::ScanForExternalDemuxSub(file, filenames); if (filenames.size() >= 2) { return CreateInputStream(pPlayer, fileitem, filenames); diff --git a/xbmc/cores/VideoPlayer/VideoPlayer.cpp b/xbmc/cores/VideoPlayer/VideoPlayer.cpp index e10d2c21490d6..46dc2954b8879 100644 --- a/xbmc/cores/VideoPlayer/VideoPlayer.cpp +++ b/xbmc/cores/VideoPlayer/VideoPlayer.cpp @@ -4494,23 +4494,46 @@ int CVideoPlayer::AddSubtitleFile(const std::string& filename, const std::string { std::string ext = URIUtils::GetExtension(filename); std::string vobsubfile = subfilename; - if (ext == ".idx") + if (ext == ".idx" || ext == ".sup") { - if (vobsubfile.empty()) { - // find corresponding .sub (e.g. in case of manually selected .idx sub) - vobsubfile = CUtil::GetVobSubSubFromIdx(filename); + std::shared_ptr pDemux; + if (ext == ".idx") + { if (vobsubfile.empty()) + { + // find corresponding .sub (e.g. in case of manually selected .idx sub) + vobsubfile = CUtil::GetVobSubSubFromIdx(filename); + if (vobsubfile.empty()) + return -1; + } + + auto pDemuxVobsub = std::make_shared(); + if (!pDemuxVobsub->Open(filename, STREAM_SOURCE_NONE, vobsubfile)) return -1; + + m_SelectionStreams.Update(nullptr, pDemuxVobsub.get(), vobsubfile); + pDemux = pDemuxVobsub; } + else // .sup file + { + CFileItem item(filename, false); + std::shared_ptr pInput; + pInput = CDVDFactoryInputStream::CreateInputStream(nullptr, item); + if (!pInput || !pInput->Open()) + return -1; - auto v = std::make_shared(); - if (!v->Open(filename, STREAM_SOURCE_NONE, vobsubfile)) - return -1; - m_SelectionStreams.Update(NULL, v.get(), vobsubfile); + auto pDemuxFFmpeg = std::make_shared(); + if (!pDemuxFFmpeg->Open(pInput, false)) + return -1; + + m_SelectionStreams.Update(nullptr, pDemuxFFmpeg.get(), filename); + pDemux = pDemuxFFmpeg; + } - ExternalStreamInfo info = CUtil::GetExternalStreamDetailsFromFilename(m_item.GetDynPath(), vobsubfile); + ExternalStreamInfo info = + CUtil::GetExternalStreamDetailsFromFilename(m_item.GetDynPath(), filename); - for (auto sub : v->GetStreams()) + for (auto sub : pDemux->GetStreams()) { if (sub->type != STREAM_SUBTITLE) continue; @@ -4529,12 +4552,15 @@ int CVideoPlayer::AddSubtitleFile(const std::string& filename, const std::string if (static_cast(info.flag) != StreamFlags::FLAG_NONE) stream.flags = static_cast(info.flag); } + UpdateContent(); // the demuxer id is unique - m_subtitleDemuxerMap[v->GetDemuxerId()] = v; - return m_SelectionStreams.TypeIndexOf(STREAM_SUBTITLE, - m_SelectionStreams.Source(STREAM_SOURCE_DEMUX_SUB, filename), v->GetDemuxerId(), 0); + m_subtitleDemuxerMap[pDemux->GetDemuxerId()] = pDemux; + return m_SelectionStreams.TypeIndexOf( + STREAM_SUBTITLE, m_SelectionStreams.Source(STREAM_SOURCE_DEMUX_SUB, filename), + pDemux->GetDemuxerId(), 0); } + if(ext == ".sub") { // if this looks like vobsub file (i.e. .idx found), add it as such @@ -4542,6 +4568,7 @@ int CVideoPlayer::AddSubtitleFile(const std::string& filename, const std::string if (!vobsubidx.empty()) return AddSubtitleFile(vobsubidx, filename); } + SelectionStream s; s.source = m_SelectionStreams.Source(STREAM_SOURCE_TEXT, filename); s.type = STREAM_SUBTITLE; diff --git a/xbmc/network/upnp/UPnPInternal.cpp b/xbmc/network/upnp/UPnPInternal.cpp index 2087b866bdd00..2e5aa5f8794f3 100644 --- a/xbmc/network/upnp/UPnPInternal.cpp +++ b/xbmc/network/upnp/UPnPInternal.cpp @@ -659,7 +659,7 @@ BuildObject(CFileItem& item, /* Hardcoded check for extension is not the best way, but it can't be allowed to pass all subtitle extension (ex. rar or zip). There are the most popular extensions support by UPnP devices.*/ if (ext == "txt" || ext == "srt" || ext == "ssa" || ext == "ass" || ext == "sub" || - ext == "smi" || ext == "vtt") + ext == "smi" || ext == "vtt" || ext == "sup") { subtitles.push_back(filenames[i]); } diff --git a/xbmc/platform/darwin/ios/Info.plist.in b/xbmc/platform/darwin/ios/Info.plist.in index 7eefbabc77f74..434ee3058297b 100644 --- a/xbmc/platform/darwin/ios/Info.plist.in +++ b/xbmc/platform/darwin/ios/Info.plist.in @@ -395,6 +395,7 @@ aqt jss ass + sup vtt idx ifo diff --git a/xbmc/settings/AdvancedSettings.cpp b/xbmc/settings/AdvancedSettings.cpp index 59b6293e7ffc4..25d97f7a1f82d 100644 --- a/xbmc/settings/AdvancedSettings.cpp +++ b/xbmc/settings/AdvancedSettings.cpp @@ -410,7 +410,7 @@ void CAdvancedSettings::Initialize() m_musicExtensions = ".nsv|.m4a|.flac|.aac|.strm|.pls|.rm|.rma|.mpa|.wav|.wma|.ogg|.mp3|.mp2|.m3u|.gdm|.imf|.m15|.sfx|.uni|.ac3|.dts|.cue|.aif|.aiff|.wpl|.xspf|.ape|.mac|.mpc|.mp+|.mpp|.shn|.zip|.wv|.dsp|.xsp|.xwav|.waa|.wvs|.wam|.gcm|.idsp|.mpdsp|.mss|.spt|.rsd|.sap|.cmc|.cmr|.dmc|.mpt|.mpd|.rmt|.tmc|.tm8|.tm2|.oga|.url|.pxml|.tta|.rss|.wtv|.mka|.tak|.opus|.dff|.dsf|.m4b|.dtshd"; m_videoExtensions = ".m4v|.3g2|.3gp|.nsv|.tp|.ts|.ty|.strm|.pls|.rm|.rmvb|.mpd|.m3u|.m3u8|.ifo|.mov|.qt|.divx|.xvid|.bivx|.vob|.nrg|.img|.iso|.udf|.pva|.wmv|.asf|.asx|.ogm|.m2v|.avi|.bin|.dat|.mpg|.mpeg|.mp4|.mkv|.mk3d|.avc|.vp3|.svq3|.nuv|.viv|.dv|.fli|.flv|.001|.wpl|.xspf|.zip|.vdr|.dvr-ms|.xsp|.mts|.m2t|.m2ts|.evo|.ogv|.sdp|.avs|.rec|.url|.pxml|.vc1|.h264|.rcv|.rss|.mpls|.mpl|.webm|.bdmv|.bdm|.wtv|.trp|.f4v"; m_subtitlesExtensions = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.text|.ssa|.aqt|.jss|" - ".ass|.vtt|.idx|.ifo|.zip"; + ".ass|.vtt|.idx|.ifo|.zip|.sup"; m_discStubExtensions = ".disc"; // internal music extensions m_musicExtensions += "|.cdda"; diff --git a/xbmc/video/dialogs/GUIDialogSubtitleSettings.cpp b/xbmc/video/dialogs/GUIDialogSubtitleSettings.cpp index 19ea25246843c..ab0ec50fdef6c 100644 --- a/xbmc/video/dialogs/GUIDialogSubtitleSettings.cpp +++ b/xbmc/video/dialogs/GUIDialogSubtitleSettings.cpp @@ -126,10 +126,10 @@ std::string CGUIDialogSubtitleSettings::BrowseForSubtitle() } std::string strMask = - ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.vtt|.idx|.zip"; + ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.vtt|.idx|.zip|.sup"; if (g_application.GetCurrentPlayer() == "VideoPlayer") - strMask = ".srt|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa|.vtt|.txt"; + strMask = ".srt|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa|.vtt|.txt|.sup"; strMask += extras;