Skip to content

utils/l10n: fix langs without alpha_2 in pycountry #3518

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2021

Conversation

bastimeyer
Copy link
Member

Fixes #3517

  1. Replaces pycountry's generic languages.lookup call with several languages.get(attr=language) calls, where attr is alpha_2, alpha_3, bibliographic and name, in this order. Other attributes are probably not relevant for Streamlink. .get calls don't raise and just return None if the lookup fails. The order of attribute lookups prevents issue utils.l10n: fix pycountry language lookup #3057, where language.lookup("en") would return the "En" language instead of "English".
  2. To prevent the AttributeError from being raised when certain optional language attributes are missing, like alpha_2 for example, those will be read via getattr with an empty string as fallback (instead of None), which matches the data representation of iso639. alpha_3 and name attributes always exist.
curl -sSL 'https://raw.githubusercontent.com/flyingcircusio/pycountry/20.7.3/src/pycountry/databases/iso639-3.json' \
  | jq '.["639-3"][] | select(.alpha_3 == "des")'
{
  "alpha_3": "des",
  "name": "Desano",
  "scope": "I",
  "type": "L"
}

@bastimeyer bastimeyer added the bug label Jan 27, 2021
@bastimeyer bastimeyer requested a review from back-to January 27, 2021 03:43
@ghost
Copy link

ghost commented Jan 27, 2021

I applied this patch to both net-misc/streamlink-9999 and net-misc/streamlink-2.0.0 and I now can successfully watch Rai 1, Rai 2 and Rai 3 as well as Rainews 24. Thank you!

@gravyboat
Copy link
Member

Looks good @bastimeyer, thanks!

@gravyboat gravyboat merged commit 5bc29b1 into streamlink:master Jan 27, 2021
@bastimeyer bastimeyer deleted the fix/utils/l10n branch January 27, 2021 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

raise AttributeError with raiplay plugin
2 participants