[youtube] more descriptive geo-lock messages (with countries)
This commit is contained in:
parent
c10469c0a8
commit
0b5407d6ec
|
@ -4,7 +4,6 @@ from __future__ import unicode_literals
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
import os.path
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
@ -29,6 +28,7 @@ from ..utils import (
|
||||||
float_or_none,
|
float_or_none,
|
||||||
get_element_by_id,
|
get_element_by_id,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
|
list_geoblocked_countres,
|
||||||
mimetype2ext,
|
mimetype2ext,
|
||||||
parse_codecs,
|
parse_codecs,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
|
@ -1849,15 +1849,34 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||||
a_format.setdefault('http_headers', {})['Youtubedl-no-compression'] = 'True'
|
a_format.setdefault('http_headers', {})['Youtubedl-no-compression'] = 'True'
|
||||||
formats.append(a_format)
|
formats.append(a_format)
|
||||||
else:
|
else:
|
||||||
error_message = extract_unavailable_message()
|
error_message = None
|
||||||
|
error_desc = None
|
||||||
if not error_message:
|
if not error_message:
|
||||||
error_message = clean_html(try_get(
|
error_message = try_get(
|
||||||
player_response, lambda x: x['playabilityStatus']['reason'],
|
player_response, lambda x: x['playabilityStatus']['reason'],
|
||||||
compat_str))
|
compat_str)
|
||||||
|
error_desc = try_get(
|
||||||
|
player_response, lambda x: x['playabilityStatus']['errorScreen']['playerErrorMessageRenderer']['subreason']['runs'],
|
||||||
|
list)
|
||||||
|
if error_desc:
|
||||||
|
error_desc = ''.join(er['text'] for er in error_desc)
|
||||||
if not error_message:
|
if not error_message:
|
||||||
error_message = clean_html(
|
error_message = clean_html(
|
||||||
try_get(video_info, lambda x: x['reason'][0], compat_str))
|
try_get(video_info, lambda x: x['reason'][0], compat_str))
|
||||||
if error_message:
|
if error_message:
|
||||||
|
if error_desc \
|
||||||
|
and (error_desc == 'The uploader has not made this video available in your country.'
|
||||||
|
or ', who has blocked it on copyright grounds' in error_desc
|
||||||
|
or 'It is not available in your country.' in error_desc
|
||||||
|
or ', who has blocked it in your country on copyright grounds.' in error_desc):
|
||||||
|
raise ExtractorError(
|
||||||
|
list_geoblocked_countres(
|
||||||
|
self._search_regex(
|
||||||
|
r'<meta itemprop="regionsAllowed" content="((?:(?:[A-Z]{2},)*[A-Z]{2})?)">',
|
||||||
|
video_webpage, 'allowed region list').split(',')),
|
||||||
|
expected=True)
|
||||||
|
if error_message == 'Video unavailable' and error_desc:
|
||||||
|
raise ExtractorError(error_desc, expected=True)
|
||||||
raise ExtractorError(error_message, expected=True)
|
raise ExtractorError(error_message, expected=True)
|
||||||
raise ExtractorError('no conn, hlsvp, hlsManifestUrl or url_encoded_fmt_stream_map information found in video info')
|
raise ExtractorError('no conn, hlsvp, hlsManifestUrl or url_encoded_fmt_stream_map information found in video info')
|
||||||
|
|
||||||
|
|
|
@ -5725,3 +5725,284 @@ def clean_podcast_url(url):
|
||||||
st\.fm # https://podsights.com/docs/
|
st\.fm # https://podsights.com/docs/
|
||||||
)/e
|
)/e
|
||||||
)/''', '', url)
|
)/''', '', url)
|
||||||
|
|
||||||
|
|
||||||
|
# http://country.io/names.json
|
||||||
|
country_list = {
|
||||||
|
"BD": "Bangladesh",
|
||||||
|
"BE": "Belgium",
|
||||||
|
"BF": "Burkina Faso",
|
||||||
|
"BG": "Bulgaria",
|
||||||
|
"BA": "Bosnia and Herzegovina",
|
||||||
|
"BB": "Barbados",
|
||||||
|
"WF": "Wallis and Futuna",
|
||||||
|
"BL": "Saint Barthelemy",
|
||||||
|
"BM": "Bermuda",
|
||||||
|
"BN": "Brunei",
|
||||||
|
"BO": "Bolivia",
|
||||||
|
"BH": "Bahrain",
|
||||||
|
"BI": "Burundi",
|
||||||
|
"BJ": "Benin",
|
||||||
|
"BT": "Bhutan",
|
||||||
|
"JM": "Jamaica",
|
||||||
|
"BV": "Bouvet Island",
|
||||||
|
"BW": "Botswana",
|
||||||
|
"WS": "Samoa",
|
||||||
|
"BQ": "Bonaire, Saint Eustatius and Saba ",
|
||||||
|
"BR": "Brazil",
|
||||||
|
"BS": "Bahamas",
|
||||||
|
"JE": "Jersey",
|
||||||
|
"BY": "Belarus",
|
||||||
|
"BZ": "Belize",
|
||||||
|
"RU": "Russia",
|
||||||
|
"RW": "Rwanda",
|
||||||
|
"RS": "Serbia",
|
||||||
|
"TL": "East Timor",
|
||||||
|
"RE": "Reunion",
|
||||||
|
"TM": "Turkmenistan",
|
||||||
|
"TJ": "Tajikistan",
|
||||||
|
"RO": "Romania",
|
||||||
|
"TK": "Tokelau",
|
||||||
|
"GW": "Guinea-Bissau",
|
||||||
|
"GU": "Guam",
|
||||||
|
"GT": "Guatemala",
|
||||||
|
"GS": "South Georgia and the South Sandwich Islands",
|
||||||
|
"GR": "Greece",
|
||||||
|
"GQ": "Equatorial Guinea",
|
||||||
|
"GP": "Guadeloupe",
|
||||||
|
"JP": "Japan",
|
||||||
|
"GY": "Guyana",
|
||||||
|
"GG": "Guernsey",
|
||||||
|
"GF": "French Guiana",
|
||||||
|
"GE": "Georgia",
|
||||||
|
"GD": "Grenada",
|
||||||
|
"GB": "United Kingdom",
|
||||||
|
"GA": "Gabon",
|
||||||
|
"SV": "El Salvador",
|
||||||
|
"GN": "Guinea",
|
||||||
|
"GM": "Gambia",
|
||||||
|
"GL": "Greenland",
|
||||||
|
"GI": "Gibraltar",
|
||||||
|
"GH": "Ghana",
|
||||||
|
"OM": "Oman",
|
||||||
|
"TN": "Tunisia",
|
||||||
|
"JO": "Jordan",
|
||||||
|
"HR": "Croatia",
|
||||||
|
"HT": "Haiti",
|
||||||
|
"HU": "Hungary",
|
||||||
|
"HK": "Hong Kong",
|
||||||
|
"HN": "Honduras",
|
||||||
|
"HM": "Heard Island and McDonald Islands",
|
||||||
|
"VE": "Venezuela",
|
||||||
|
"PR": "Puerto Rico",
|
||||||
|
"PS": "Palestinian Territory",
|
||||||
|
"PW": "Palau",
|
||||||
|
"PT": "Portugal",
|
||||||
|
"SJ": "Svalbard and Jan Mayen",
|
||||||
|
"PY": "Paraguay",
|
||||||
|
"IQ": "Iraq",
|
||||||
|
"PA": "Panama",
|
||||||
|
"PF": "French Polynesia",
|
||||||
|
"PG": "Papua New Guinea",
|
||||||
|
"PE": "Peru",
|
||||||
|
"PK": "Pakistan",
|
||||||
|
"PH": "Philippines",
|
||||||
|
"PN": "Pitcairn",
|
||||||
|
"PL": "Poland",
|
||||||
|
"PM": "Saint Pierre and Miquelon",
|
||||||
|
"ZM": "Zambia",
|
||||||
|
"EH": "Western Sahara",
|
||||||
|
"EE": "Estonia",
|
||||||
|
"EG": "Egypt",
|
||||||
|
"ZA": "South Africa",
|
||||||
|
"EC": "Ecuador",
|
||||||
|
"IT": "Italy",
|
||||||
|
"VN": "Vietnam",
|
||||||
|
"SB": "Solomon Islands",
|
||||||
|
"ET": "Ethiopia",
|
||||||
|
"SO": "Somalia",
|
||||||
|
"ZW": "Zimbabwe",
|
||||||
|
"SA": "Saudi Arabia",
|
||||||
|
"ES": "Spain",
|
||||||
|
"ER": "Eritrea",
|
||||||
|
"ME": "Montenegro",
|
||||||
|
"MD": "Moldova",
|
||||||
|
"MG": "Madagascar",
|
||||||
|
"MF": "Saint Martin",
|
||||||
|
"MA": "Morocco",
|
||||||
|
"MC": "Monaco",
|
||||||
|
"UZ": "Uzbekistan",
|
||||||
|
"MM": "Myanmar",
|
||||||
|
"ML": "Mali",
|
||||||
|
"MO": "Macao",
|
||||||
|
"MN": "Mongolia",
|
||||||
|
"MH": "Marshall Islands",
|
||||||
|
"MK": "Macedonia",
|
||||||
|
"MU": "Mauritius",
|
||||||
|
"MT": "Malta",
|
||||||
|
"MW": "Malawi",
|
||||||
|
"MV": "Maldives",
|
||||||
|
"MQ": "Martinique",
|
||||||
|
"MP": "Northern Mariana Islands",
|
||||||
|
"MS": "Montserrat",
|
||||||
|
"MR": "Mauritania",
|
||||||
|
"IM": "Isle of Man",
|
||||||
|
"UG": "Uganda",
|
||||||
|
"TZ": "Tanzania",
|
||||||
|
"MY": "Malaysia",
|
||||||
|
"MX": "Mexico",
|
||||||
|
"IL": "Israel",
|
||||||
|
"FR": "France",
|
||||||
|
"IO": "British Indian Ocean Territory",
|
||||||
|
"SH": "Saint Helena",
|
||||||
|
"FI": "Finland",
|
||||||
|
"FJ": "Fiji",
|
||||||
|
"FK": "Falkland Islands",
|
||||||
|
"FM": "Micronesia",
|
||||||
|
"FO": "Faroe Islands",
|
||||||
|
"NI": "Nicaragua",
|
||||||
|
"NL": "Netherlands",
|
||||||
|
"NO": "Norway",
|
||||||
|
"NA": "Namibia",
|
||||||
|
"VU": "Vanuatu",
|
||||||
|
"NC": "New Caledonia",
|
||||||
|
"NE": "Niger",
|
||||||
|
"NF": "Norfolk Island",
|
||||||
|
"NG": "Nigeria",
|
||||||
|
"NZ": "New Zealand",
|
||||||
|
"NP": "Nepal",
|
||||||
|
"NR": "Nauru",
|
||||||
|
"NU": "Niue",
|
||||||
|
"CK": "Cook Islands",
|
||||||
|
"XK": "Kosovo",
|
||||||
|
"CI": "Ivory Coast",
|
||||||
|
"CH": "Switzerland",
|
||||||
|
"CO": "Colombia",
|
||||||
|
"CN": "China",
|
||||||
|
"CM": "Cameroon",
|
||||||
|
"CL": "Chile",
|
||||||
|
"CC": "Cocos Islands",
|
||||||
|
"CA": "Canada",
|
||||||
|
"CG": "Republic of the Congo",
|
||||||
|
"CF": "Central African Republic",
|
||||||
|
"CD": "Democratic Republic of the Congo",
|
||||||
|
"CZ": "Czech Republic",
|
||||||
|
"CY": "Cyprus",
|
||||||
|
"CX": "Christmas Island",
|
||||||
|
"CR": "Costa Rica",
|
||||||
|
"CW": "Curacao",
|
||||||
|
"CV": "Cape Verde",
|
||||||
|
"CU": "Cuba",
|
||||||
|
"SZ": "Swaziland",
|
||||||
|
"SY": "Syria",
|
||||||
|
"SX": "Sint Maarten",
|
||||||
|
"KG": "Kyrgyzstan",
|
||||||
|
"KE": "Kenya",
|
||||||
|
"SS": "South Sudan",
|
||||||
|
"SR": "Suriname",
|
||||||
|
"KI": "Kiribati",
|
||||||
|
"KH": "Cambodia",
|
||||||
|
"KN": "Saint Kitts and Nevis",
|
||||||
|
"KM": "Comoros",
|
||||||
|
"ST": "Sao Tome and Principe",
|
||||||
|
"SK": "Slovakia",
|
||||||
|
"KR": "South Korea",
|
||||||
|
"SI": "Slovenia",
|
||||||
|
"KP": "North Korea",
|
||||||
|
"KW": "Kuwait",
|
||||||
|
"SN": "Senegal",
|
||||||
|
"SM": "San Marino",
|
||||||
|
"SL": "Sierra Leone",
|
||||||
|
"SC": "Seychelles",
|
||||||
|
"KZ": "Kazakhstan",
|
||||||
|
"KY": "Cayman Islands",
|
||||||
|
"SG": "Singapore",
|
||||||
|
"SE": "Sweden",
|
||||||
|
"SD": "Sudan",
|
||||||
|
"DO": "Dominican Republic",
|
||||||
|
"DM": "Dominica",
|
||||||
|
"DJ": "Djibouti",
|
||||||
|
"DK": "Denmark",
|
||||||
|
"VG": "British Virgin Islands",
|
||||||
|
"DE": "Germany",
|
||||||
|
"YE": "Yemen",
|
||||||
|
"DZ": "Algeria",
|
||||||
|
"US": "United States",
|
||||||
|
"UY": "Uruguay",
|
||||||
|
"YT": "Mayotte",
|
||||||
|
"UM": "United States Minor Outlying Islands",
|
||||||
|
"LB": "Lebanon",
|
||||||
|
"LC": "Saint Lucia",
|
||||||
|
"LA": "Laos",
|
||||||
|
"TV": "Tuvalu",
|
||||||
|
"TW": "Taiwan",
|
||||||
|
"TT": "Trinidad and Tobago",
|
||||||
|
"TR": "Turkey",
|
||||||
|
"LK": "Sri Lanka",
|
||||||
|
"LI": "Liechtenstein",
|
||||||
|
"LV": "Latvia",
|
||||||
|
"TO": "Tonga",
|
||||||
|
"LT": "Lithuania",
|
||||||
|
"LU": "Luxembourg",
|
||||||
|
"LR": "Liberia",
|
||||||
|
"LS": "Lesotho",
|
||||||
|
"TH": "Thailand",
|
||||||
|
"TF": "French Southern Territories",
|
||||||
|
"TG": "Togo",
|
||||||
|
"TD": "Chad",
|
||||||
|
"TC": "Turks and Caicos Islands",
|
||||||
|
"LY": "Libya",
|
||||||
|
"VA": "Vatican",
|
||||||
|
"VC": "Saint Vincent and the Grenadines",
|
||||||
|
"AE": "United Arab Emirates",
|
||||||
|
"AD": "Andorra",
|
||||||
|
"AG": "Antigua and Barbuda",
|
||||||
|
"AF": "Afghanistan",
|
||||||
|
"AI": "Anguilla",
|
||||||
|
"VI": "U.S. Virgin Islands",
|
||||||
|
"IS": "Iceland",
|
||||||
|
"IR": "Iran",
|
||||||
|
"AM": "Armenia",
|
||||||
|
"AL": "Albania",
|
||||||
|
"AO": "Angola",
|
||||||
|
"AQ": "Antarctica",
|
||||||
|
"AS": "American Samoa",
|
||||||
|
"AR": "Argentina",
|
||||||
|
"AU": "Australia",
|
||||||
|
"AT": "Austria",
|
||||||
|
"AW": "Aruba",
|
||||||
|
"IN": "India",
|
||||||
|
"AX": "Aland Islands",
|
||||||
|
"AZ": "Azerbaijan",
|
||||||
|
"IE": "Ireland",
|
||||||
|
"ID": "Indonesia",
|
||||||
|
"UA": "Ukraine",
|
||||||
|
"QA": "Qatar",
|
||||||
|
"MZ": "Mozambique"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def list_countries():
|
||||||
|
return country_list.keys()
|
||||||
|
|
||||||
|
|
||||||
|
def list_geoblocked_countres(allowed_countries, reverse=False):
|
||||||
|
geoblocked = []
|
||||||
|
geounlocked = []
|
||||||
|
for country in list_countries():
|
||||||
|
if country in allowed_countries or (country not in allowed_countries and reverse is True):
|
||||||
|
geounlocked.append(country)
|
||||||
|
elif country not in allowed_countries or (country in allowed_countries and reverse is True):
|
||||||
|
geoblocked.append(country)
|
||||||
|
if len(geounlocked) == 0:
|
||||||
|
return 'This video is blocked in all countries'
|
||||||
|
if len(geoblocked) <= 10:
|
||||||
|
return 'This video is blocked in these countries: %s' % ', '.join(sorted(country_list[cnt] for cnt in geoblocked))
|
||||||
|
if len(geounlocked) <= 10:
|
||||||
|
geoblocked.sort()
|
||||||
|
return 'This video is only available in these countries: %s' % ', '.join(country_list[cnt] for cnt in geounlocked)
|
||||||
|
if len(geoblocked) >= len(geounlocked):
|
||||||
|
geounlocked.sort()
|
||||||
|
return 'This video is only available in these countries: %s' % ', '.join(geounlocked)
|
||||||
|
geoblocked.sort()
|
||||||
|
return 'This video is blocked in these countries: %s' % ', '.join(geoblocked)
|
||||||
|
|
Loading…
Reference in a new issue