Display only blocked countries when queueing

This commit is contained in:
Joscha 2018-08-17 18:21:07 +00:00
parent 2f2672ce10
commit 26f317c250

View file

@ -47,6 +47,28 @@ class YouTube:
return videos return videos
class Playlist: class Playlist:
COUNTRIES = { # according to en.wikipedia.org/wiki/ISO_3166-1_alpha-2, 2018-08-17 18:12:15 UTC
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU",
"AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL",
"BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC",
"CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV",
"CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
"EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD",
"GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT",
"GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM",
"IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH",
"KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK",
"LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH",
"MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW",
"MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR",
"NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR",
"PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC",
"SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS",
"ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL",
"TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY",
"UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA",
"ZM", "ZW"
}
COMMON_COUNTRIES = {"DE", "FI", "FR", "GB", "IT", "JP", "NL", "PT", "US"} COMMON_COUNTRIES = {"DE", "FI", "FR", "GB", "IT", "JP", "NL", "PT", "US"}
def __init__(self): def __init__(self):
@ -77,12 +99,10 @@ class Playlist:
blocked = None blocked = None
if video.blocked is not None: if video.blocked is not None:
action = "Blocked"
blocked = set(video.blocked) blocked = set(video.blocked)
#lines.append(f"Blocked in {', '.join(video.blocked)}.") #lines.append(f"Blocked in {', '.join(video.blocked)}.")
if video.allowed is not None: if video.allowed is not None:
action = "Only viewable" blocked = Playlist.COUNTRIES - set(video.allowed)
blocked = set(video.allowed)
#lines.append(f"Only viewable in {', '.join(video.allowed)}.") #lines.append(f"Only viewable in {', '.join(video.allowed)}.")
if blocked is not None: if blocked is not None:
common = sorted(blocked & Playlist.COMMON_COUNTRIES) common = sorted(blocked & Playlist.COMMON_COUNTRIES)
@ -90,13 +110,17 @@ class Playlist:
if common: if common:
if uncommon: if uncommon:
text = f"{action} in {', '.join(common)} and {len(uncommon)} other countries." text = f"Blocked in {', '.join(common)} and {len(uncommon)} other "
text += "country." if len(uncommon) == 1 else "countries."
else: else:
text = f"{action} in {', '.join(common)}." text = f"Blocked in {', '.join(common)}."
elif len(uncommon) <= 10: lines.append(text)
text = f"{action} in {', '.join(uncommon)}." elif uncommon:
if len(uncommon) <= 10:
text = f"Blocked in {', '.join(uncommon)}."
else: else:
text = f"{action} in {len(uncommon)} countries." text = f"Blocked in {len(uncommon)} "
text += "country." if len(uncommon) == 1 else "countries."
lines.append(text) lines.append(text)
return lines return lines