Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
StreamSelWin: properly treat 'und' lang as <undefined>
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Szymaniak committed Jul 10, 2019
1 parent ec121d6 commit cbf0130
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions subsync/gui/streamselwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ def __init__(self, parent, streams, types):
self.m_textSelType.Show(enableTypeSelection)
self.m_choiceSelType.Show(enableTypeSelection)

langs = set(s.lang.lower() for ss in streams for s in ss.streams.values() if s.type in types)
langs = set(canonizeLang(s.lang) for ss in streams for s in ss.streams.values() if s.type in types)
self.m_choiceSelLang.Append(_('auto'), None)
if langs & set(['', 'und']):
if '' in langs:
langs.discard('')
langs.discard('und')
self.m_choiceSelLang.Append(_('<undefined>'), '')

self.m_choiceSelLang.addSortedLangs({getLanguageName(l): l for l in langs})
Expand Down Expand Up @@ -93,14 +92,21 @@ def findStream(ss, types, lang, title):
streams = []
for type in types:
# we will try streams that have lang set first
streams += [ (no, s) for no, s in items if s.type == type and s.lang ]
streams += [ (no, s) for no, s in items if s.type == type and not s.lang ]
streams += [ (no, s) for no, s in items if s.type == type and canonizeLang(s.lang) ]
streams += [ (no, s) for no, s in items if s.type == type and not canonizeLang(s.lang) ]

if lang is not None:
streams = [ ss for ss in streams if ss[1].lang.lower() == lang ]
streams = [ ss for ss in streams if canonizeLang(ss[1].lang) == lang ]

if title is not None:
streams = [ ss for ss in streams if ss[1].title == title ]

if streams:
return streams[0][0]


def canonizeLang(lang):
lang = lang.lower()
if lang != 'und':
return lang
return ''

0 comments on commit cbf0130

Please sign in to comment.