Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add subtitles language and name extraction from filename and VideoPlayer.SubtitlesLanguage infolabel #1365

wants to merge 6 commits into


None yet
7 participants

pieh commented Sep 4, 2012

I added method to convert language string (being 2char code "en", 3char code "eng" or full language name "english") to 2char code: pieh/xbmc@4b9cc5d

And helper method to extract language and name from filename: pieh/xbmc@5789502
What I do there is specify few regexpes to match lang and name and try to pick up best from all matches. Fact that we know if string that is recognized as lang part is actual language (testing if we can convert it to 2char code) makes this pretty accurate. Builtin regexpes would propably need more love - not regexp wizard here.

I think that I could also add either white list for stream names (f.e. "Directors Commentary" as white list entry) to further increase accuracy of matches. Regexpes and white list name entries would be adjustable via advancedsettings.xml.

Added infolabel is on pike's request.

Here's example of how lang/name extraction is currently performing using my test case:

Util::ScanForExternalSubtitles: Searching for subtitles...
CUtil::ScanForExternalSubtitles: found subtitle file smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.Closed-caption.txt
CUtil::ScanForExternalSubtitles: found subtitle file smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.directors-comments-en.txt
CUtil::ScanForExternalSubtitles: found subtitle file smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.en.name_stuff.txt
CUtil::ScanForExternalSubtitles: found subtitle file smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.it.txt
CUtil::ScanForExternalSubtitles: found subtitle file smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.some_name.txt
CUtil::ScanForExternalSubtitles: found subtitle file smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.Spanish.txt
CUtil::ScanForExternalSubtitles: found subtitle file smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.txt
CUtil::ScanForExternalSubtitles: END (total time: 18 ms)
CUtil::GetExternalStreamNameAndLangFromFilename - Language = 'cc' / Name = 'Closed Caption' from smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.Closed-caption.txt
CUtil::GetExternalStreamNameAndLangFromFilename - Language = 'en' / Name = 'directors-comments' from smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.directors-comments-en.txt
CUtil::GetExternalStreamNameAndLangFromFilename - Language = 'en' / Name = 'name_stuff' from smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.en.name_stuff.txt
CUtil::GetExternalStreamNameAndLangFromFilename - Language = 'it' / Name = 'Italiano' from smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.it.txt
CUtil::GetExternalStreamNameAndLangFromFilename - Language = '' / Name = 'some_name' from smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.some_name.txt
CUtil::GetExternalStreamNameAndLangFromFilename - Language = 'es' / Name = 'Espanol' from smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.Spanish.txt
CUtil::GetExternalStreamNameAndLangFromFilename - Language = '' / Name = 'The.Dummy.Video.720p.X264.txt' from smb://KOMPUS/Videos/Dummy/The.Dummy.Video.720p.X264.txt

pieh added some commits Sep 2, 2012

@pieh pieh add subtitles extension list and allow to remove it using URIUtils::R…
@pieh pieh add method converting language string to 2char code
passed language string could be either other code or full language name
@pieh pieh add CUtil::GetExternalStreamNameAndLangFromFilename method to extract…
… stream language and name from filename
@pieh pieh use CUtil::GetExternalStreamNameAndLangFromFilename to determine exte…
…rnal subtitles's language and name
@pieh pieh dvdplayer: update current video settings when changing setting subtit…
…les stream to be sure we keep it synced (similiar to what we already do when we show/hide subtitles)
@pieh pieh add VideoPlayer.SubtitlesLanguage infolabel that returns full languag…
…e name of current subtitles, "unknown" localized string or empty string if subtitles are disabled or video isn't playing currently

Memphiz commented Sep 23, 2012

If i see it right it "only" provides the language as a guilabel. So worst thing that could happen when something is wrong here is that it dosn't show the right label for the subtitle right?

Didn't review the whole regexp stuff and so on, but in general it looks good to me.


pieh commented Sep 23, 2012

It wouln't act as infolabel only - determined language could be used to select external subtitles with prefered subtitles language feature. I didn't test yet if that actually work (but assuming that we add external subtitles before we select prefered subtitles it should work out of the box as we use stream language there). Was hoping to get some feedback about language/name extraction approach before i do more work on it.

Baswazz commented Dec 6, 2012

Is there any progress on this? Will it be merged into Frodo Final?


pieh commented Dec 7, 2012

We are in feature freeze, this certainly won't be merged before Frodo Final. There wasn't any progress on this since I opened PR, there is still TO-DO entry to code.


da-anda commented Jan 30, 2013

@pieh - you think you find some time to prepare this for the upcoming merge window? And could changes in this PR probably be used to fix audio and subtitle selection for blurays @Montellese ? This is currently not working.


pieh commented Jan 31, 2013

I will try to do some work on it, but can't promise anything ... Not sure if this has anything in common with bluray subtitles/audio (this PR will only try to extract language from external subtitle filename, I don't think bluray keep subtitles/audio tracks in seperate files?)


da-anda commented Jan 31, 2013

@pieh I talked with @Montellese about it in IRC a couple days ago and without looking at the reason for the bug in detail he said he could imagine that blurays use different language strings/labels and that this might be the reason for the auto-selection he implemented to fail. So with your CLangCodeExpander::ConvertToTwoCharCode this issue probably could be fixed (if it's the actual cause). That's why I pinged Montellese.


ace20022 commented Feb 1, 2013

The priority selection gets skipped for dvds (not sure about blurays).
The relevant piece of code is:

void CDVDPlayer::OpenDefaultStreams(bool reset)
  // bypass for DVDs. The DVD Navigator has already dictated which streams to open.
  if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))

fernandog commented Mar 4, 2013

Question for 13-gotham: with this, external subtitles will be considered a new stream? Will the video database have a new column to indicate that a movie/tv-show has a external subtitle? If so, skins can offer image labels and or filter to movies/tv-show that has subtitles.


ace20022 commented Mar 21, 2013

@pieh any news about this? Since blacks Video language script (http://forum.xbmc.org/showthread.php?tid=155693) gets include into skins, ext. subs language might rise on the wanted list. I've opened a pr to your repo some time ago proposing to store the info in the db. with that blacks script should work out of the box.

What's the status on this?

@pieh pieh closed this Jun 27, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment