Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:MythTV/mythtv

  • Loading branch information...
commit f404b65f5556f96f2b856af6ae228562ab5b5de8 2 parents 36cdbfd + 12823e7
@nriendeau nriendeau authored
View
55 mythtv/bindings/python/MythTV/tmdb3/scripts/populate_locale.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#-----------------------
+# Name: populate_locale.py Helper for grabbing ISO639 and ISO3316 data
+# Python Library
+# Author: Raymond Wagner
+#-----------------------
+
+import lxml.html
+import sys
+import os
+
+def sanitize(name):
+ name = ' '.join(name.split())
+ return name
+
+fpath = os.path.join(os.getcwd(), __file__) if not __file__.startswith('/') else __file__
+fpath = os.path.join(fpath.rsplit('/',2)[0], 'tmdb3/locales.py')
+
+fd = open(fpath, 'r')
+while True:
+ line = fd.readline()
+ if len(line) == 0:
+ print "code endpoint not found, aborting!"
+ sys.exit(1)
+ if line.startswith('########'):
+ endpt = fd.tell()
+ break
+
+fd = open(fpath, 'a')
+fd.seek(endpt)
+fd.truncate()
+fd.write('\n')
+
+root = lxml.html.parse('http://www.loc.gov/standards/iso639-2/php/English_list.php')
+for row in root.getroot().getchildren()[3].getchildren()[2].getchildren()[0]\
+ .getchildren()[0].getchildren()[9]:
+ if row.getchildren()[0].tag == "th":
+ # skip header
+ continue
+ if row.getchildren()[-1].text == u"\xa0":
+ # skip empty 639-1 code
+ continue
+ name, _, _, iso639_2, iso639_1 = [t.text for t in row]
+
+ fd.write('Language("{0}", "{1}", u"{2}")\n'.format(iso639_1, iso639_2, sanitize(name).encode('utf8')))
+
+root = lxml.html.parse('http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm').getroot()
+for row in root.get_element_by_id('tc_list'):
+ if row.tag == 'thead':
+ # skip header
+ continue
+ name, _, alpha2 = [t.text if t.text else t.getchildren()[0].tail for t in row]
+ fd.write('Country("{0}", u"{1}")\n'.format(alpha2, sanitize(name).encode('utf8')))
+
View
1  mythtv/bindings/python/MythTV/tmdb3/tmdb3/__init__.py
@@ -3,5 +3,6 @@
from tmdb_api import Configuration, searchMovie, searchPerson, Person, \
Movie, Collection, __version__
from request import set_key, set_cache
+from locales import get_locale, set_locale
from tmdb_exceptions import *
View
585 mythtv/bindings/python/MythTV/tmdb3/tmdb3/locales.py
@@ -0,0 +1,585 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#-----------------------
+# Name: locales.py Stores locale information for filtering results
+# Python Library
+# Author: Raymond Wagner
+#-----------------------
+
+import locale
+
+syslocale = None
+
+class LocaleBase( object ):
+ __slots__ = ['__immutable']
+ _stored = {}
+ fallthrough = False
+
+ def __init__(self, *keys):
+ for key in keys:
+ self._stored[key.lower()] = self
+ self.__immutable = True
+
+ def __setattr__(self, key, value):
+ if getattr(self, '__immutable', False):
+ raise NotImplementedError(self.__class__.__name__ +
+ ' does not support modification.')
+ super(LocaleBase, self).__setattr__(key, value)
+
+ def __delattr__(self, key):
+ if getattr(self, '__immutable', False):
+ raise NotImplementedError(self.__class__.__name__ +
+ ' does not support modification.')
+ super(LocaleBase, self).__delattr__(key)
+
+ @classmethod
+ def getstored(cls, key):
+ if key is None:
+ return None
+ try:
+ return cls._stored[key.lower()]
+ except:
+ raise TMDBLocaleError("'{0}' is not a known valid {1} code.".format(key, cls.__name__))
+
+class Language( LocaleBase ):
+ __slots__ = ['ISO639_1', 'ISO639_2', 'ISO639_2B', 'englishname',
+ 'nativename']
+ _stored = {}
+
+ def __init__(self, iso1, iso2, ename):
+ self.ISO639_1 = iso1
+ self.ISO639_2 = iso2
+# self.ISO639_2B = iso2b
+ self.englishname = ename
+# self.nativename = nname
+ super(Language, self).__init__(iso1, iso2)
+
+ def __str__(self):
+ return self.ISO639_1
+
+ def __repr__(self):
+ return u"<Language '{0.englishname}' ({0.ISO639_1})>".format(self)
+
+class Country( LocaleBase ):
+ __slots__ = ['alpha2', 'name']
+ _stored = {}
+
+ def __init__(self, alpha2, name):
+ self.alpha2 = alpha2
+ self.name = name
+ super(Country, self).__init__(alpha2)
+
+ def __str__(self):
+ return self.alpha2
+
+ def __repr__(self):
+ return u"<Country '{0.name}' ({0.alpha2})>".format(self)
+
+class Locale( LocaleBase ):
+ __slots__ = ['language', 'country']
+
+ def __init__(self, language, country):
+ self.language = Language.getstored(language)
+ self.country = Country.getstored(country)
+
+ def __repr__(self):
+ return u"<Locale {0.language}_{0.country}>".format(self)
+
+def set_locale(language=None, country=None, fallthrough=False):
+ global syslocale
+ LocaleBase.fallthrough = fallthrough
+
+ if (not language) or (not country):
+ dat = None
+ if syslocale is not None:
+ dat = (str(syslocale.language), str(syslocale.country))
+ else:
+ res = locale.getdefaultlocale()[0]
+ if (res is None) or ('_' not in res):
+ dat = ('en', 'US')
+ else:
+ dat = res.split('_')
+ if language is None:
+ language = dat[0]
+ if country is None:
+ country = dat[1]
+ syslocale = Locale(language, country)
+
+def get_locale(language=None, country=None):
+ global syslocale
+ if language and country:
+ return Locale(language, country)
+ if syslocale is None:
+ return Locale(None, None)
+ return syslocale
+
+######## AUTOGENERATED LANGUAGE AND COUNTRY DATA BELOW HERE #########
+
+Language("ab", "abk", u"Abkhazian")
+Language("aa", "aar", u"Afar")
+Language("af", "afr", u"Afrikaans")
+Language("ak", "aka", u"Akan")
+Language("sq", "alb/sqi", u"Albanian")
+Language("am", "amh", u"Amharic")
+Language("ar", "ara", u"Arabic")
+Language("an", "arg", u"Aragonese")
+Language("hy", "arm/hye", u"Armenian")
+Language("as", "asm", u"Assamese")
+Language("av", "ava", u"Avaric")
+Language("ae", "ave", u"Avestan")
+Language("ay", "aym", u"Aymara")
+Language("az", "aze", u"Azerbaijani")
+Language("bm", "bam", u"Bambara")
+Language("ba", "bak", u"Bashkir")
+Language("eu", "baq/eus", u"Basque")
+Language("be", "bel", u"Belarusian")
+Language("bn", "ben", u"Bengali")
+Language("bh", "bih", u"Bihari languages")
+Language("bi", "bis", u"Bislama")
+Language("nb", "nob", u"Bokmål, Norwegian")
+Language("bs", "bos", u"Bosnian")
+Language("br", "bre", u"Breton")
+Language("bg", "bul", u"Bulgarian")
+Language("my", "bur/mya", u"Burmese")
+Language("es", "spa", u"Castilian")
+Language("ca", "cat", u"Catalan")
+Language("km", "khm", u"Central Khmer")
+Language("ch", "cha", u"Chamorro")
+Language("ce", "che", u"Chechen")
+Language("ny", "nya", u"Chewa")
+Language("ny", "nya", u"Chichewa")
+Language("zh", "chi/zho", u"Chinese")
+Language("za", "zha", u"Chuang")
+Language("cu", "chu", u"Church Slavic")
+Language("cu", "chu", u"Church Slavonic")
+Language("cv", "chv", u"Chuvash")
+Language("kw", "cor", u"Cornish")
+Language("co", "cos", u"Corsican")
+Language("cr", "cre", u"Cree")
+Language("hr", "hrv", u"Croatian")
+Language("cs", "cze/ces", u"Czech")
+Language("da", "dan", u"Danish")
+Language("dv", "div", u"Dhivehi")
+Language("dv", "div", u"Divehi")
+Language("nl", "dut/nld", u"Dutch")
+Language("dz", "dzo", u"Dzongkha")
+Language("en", "eng", u"English")
+Language("eo", "epo", u"Esperanto")
+Language("et", "est", u"Estonian")
+Language("ee", "ewe", u"Ewe")
+Language("fo", "fao", u"Faroese")
+Language("fj", "fij", u"Fijian")
+Language("fi", "fin", u"Finnish")
+Language("nl", "dut/nld", u"Flemish")
+Language("fr", "fre/fra", u"French")
+Language("ff", "ful", u"Fulah")
+Language("gd", "gla", u"Gaelic")
+Language("gl", "glg", u"Galician")
+Language("lg", "lug", u"Ganda")
+Language("ka", "geo/kat", u"Georgian")
+Language("de", "ger/deu", u"German")
+Language("ki", "kik", u"Gikuyu")
+Language("el", "gre/ell", u"Greek, Modern (1453-)")
+Language("kl", "kal", u"Greenlandic")
+Language("gn", "grn", u"Guarani")
+Language("gu", "guj", u"Gujarati")
+Language("ht", "hat", u"Haitian")
+Language("ht", "hat", u"Haitian Creole")
+Language("ha", "hau", u"Hausa")
+Language("he", "heb", u"Hebrew")
+Language("hz", "her", u"Herero")
+Language("hi", "hin", u"Hindi")
+Language("ho", "hmo", u"Hiri Motu")
+Language("hu", "hun", u"Hungarian")
+Language("is", "ice/isl", u"Icelandic")
+Language("io", "ido", u"Ido")
+Language("ig", "ibo", u"Igbo")
+Language("id", "ind", u"Indonesian")
+Language("ia", "ina", u"Interlingua (International Auxiliary Language Association)")
+Language("ie", "ile", u"Interlingue")
+Language("iu", "iku", u"Inuktitut")
+Language("ik", "ipk", u"Inupiaq")
+Language("ga", "gle", u"Irish")
+Language("it", "ita", u"Italian")
+Language("ja", "jpn", u"Japanese")
+Language("jv", "jav", u"Javanese")
+Language("kl", "kal", u"Kalaallisut")
+Language("kn", "kan", u"Kannada")
+Language("kr", "kau", u"Kanuri")
+Language("ks", "kas", u"Kashmiri")
+Language("kk", "kaz", u"Kazakh")
+Language("ki", "kik", u"Kikuyu")
+Language("rw", "kin", u"Kinyarwanda")
+Language("ky", "kir", u"Kirghiz")
+Language("kv", "kom", u"Komi")
+Language("kg", "kon", u"Kongo")
+Language("ko", "kor", u"Korean")
+Language("kj", "kua", u"Kuanyama")
+Language("ku", "kur", u"Kurdish")
+Language("kj", "kua", u"Kwanyama")
+Language("ky", "kir", u"Kyrgyz")
+Language("lo", "lao", u"Lao")
+Language("la", "lat", u"Latin")
+Language("lv", "lav", u"Latvian")
+Language("lb", "ltz", u"Letzeburgesch")
+Language("li", "lim", u"Limburgan")
+Language("li", "lim", u"Limburger")
+Language("li", "lim", u"Limburgish")
+Language("ln", "lin", u"Lingala")
+Language("lt", "lit", u"Lithuanian")
+Language("lu", "lub", u"Luba-Katanga")
+Language("lb", "ltz", u"Luxembourgish")
+Language("mk", "mac/mkd", u"Macedonian")
+Language("mg", "mlg", u"Malagasy")
+Language("ms", "may/msa", u"Malay")
+Language("ml", "mal", u"Malayalam")
+Language("dv", "div", u"Maldivian")
+Language("mt", "mlt", u"Maltese")
+Language("gv", "glv", u"Manx")
+Language("mi", "mao/mri", u"Maori")
+Language("mr", "mar", u"Marathi")
+Language("mh", "mah", u"Marshallese")
+Language("ro", "rum/ron", u"Moldavian")
+Language("ro", "rum/ron", u"Moldovan")
+Language("mn", "mon", u"Mongolian")
+Language("na", "nau", u"Nauru")
+Language("nv", "nav", u"Navaho")
+Language("nv", "nav", u"Navajo")
+Language("nd", "nde", u"Ndebele, North")
+Language("nr", "nbl", u"Ndebele, South")
+Language("ng", "ndo", u"Ndonga")
+Language("ne", "nep", u"Nepali")
+Language("nd", "nde", u"North Ndebele")
+Language("se", "sme", u"Northern Sami")
+Language("no", "nor", u"Norwegian")
+Language("nb", "nob", u"Norwegian Bokmål")
+Language("nn", "nno", u"Norwegian Nynorsk")
+Language("ii", "iii", u"Nuosu")
+Language("ny", "nya", u"Nyanja")
+Language("nn", "nno", u"Nynorsk, Norwegian")
+Language("ie", "ile", u"Occidental")
+Language("oc", "oci", u"Occitan (post 1500)")
+Language("oj", "oji", u"Ojibwa")
+Language("cu", "chu", u"Old Bulgarian")
+Language("cu", "chu", u"Old Church Slavonic")
+Language("cu", "chu", u"Old Slavonic")
+Language("or", "ori", u"Oriya")
+Language("om", "orm", u"Oromo")
+Language("os", "oss", u"Ossetian")
+Language("os", "oss", u"Ossetic")
+Language("pi", "pli", u"Pali")
+Language("pa", "pan", u"Panjabi")
+Language("ps", "pus", u"Pashto")
+Language("fa", "per/fas", u"Persian")
+Language("pl", "pol", u"Polish")
+Language("pt", "por", u"Portuguese")
+Language("pa", "pan", u"Punjabi")
+Language("ps", "pus", u"Pushto")
+Language("qu", "que", u"Quechua")
+Language("ro", "rum/ron", u"Romanian")
+Language("rm", "roh", u"Romansh")
+Language("rn", "run", u"Rundi")
+Language("ru", "rus", u"Russian")
+Language("sm", "smo", u"Samoan")
+Language("sg", "sag", u"Sango")
+Language("sa", "san", u"Sanskrit")
+Language("sc", "srd", u"Sardinian")
+Language("gd", "gla", u"Scottish Gaelic")
+Language("sr", "srp", u"Serbian")
+Language("sn", "sna", u"Shona")
+Language("ii", "iii", u"Sichuan Yi")
+Language("sd", "snd", u"Sindhi")
+Language("si", "sin", u"Sinhala")
+Language("si", "sin", u"Sinhalese")
+Language("sk", "slo/slk", u"Slovak")
+Language("sl", "slv", u"Slovenian")
+Language("so", "som", u"Somali")
+Language("st", "sot", u"Sotho, Southern")
+Language("nr", "nbl", u"South Ndebele")
+Language("es", "spa", u"Spanish")
+Language("su", "sun", u"Sundanese")
+Language("sw", "swa", u"Swahili")
+Language("ss", "ssw", u"Swati")
+Language("sv", "swe", u"Swedish")
+Language("tl", "tgl", u"Tagalog")
+Language("ty", "tah", u"Tahitian")
+Language("tg", "tgk", u"Tajik")
+Language("ta", "tam", u"Tamil")
+Language("tt", "tat", u"Tatar")
+Language("te", "tel", u"Telugu")
+Language("th", "tha", u"Thai")
+Language("bo", "tib/bod", u"Tibetan")
+Language("ti", "tir", u"Tigrinya")
+Language("to", "ton", u"Tonga (Tonga Islands)")
+Language("ts", "tso", u"Tsonga")
+Language("tn", "tsn", u"Tswana")
+Language("tr", "tur", u"Turkish")
+Language("tk", "tuk", u"Turkmen")
+Language("tw", "twi", u"Twi")
+Language("ug", "uig", u"Uighur")
+Language("uk", "ukr", u"Ukrainian")
+Language("ur", "urd", u"Urdu")
+Language("ug", "uig", u"Uyghur")
+Language("uz", "uzb", u"Uzbek")
+Language("ca", "cat", u"Valencian")
+Language("ve", "ven", u"Venda")
+Language("vi", "vie", u"Vietnamese")
+Language("vo", "vol", u"Volapük")
+Language("wa", "wln", u"Walloon")
+Language("cy", "wel/cym", u"Welsh")
+Language("fy", "fry", u"Western Frisian")
+Language("wo", "wol", u"Wolof")
+Language("xh", "xho", u"Xhosa")
+Language("yi", "yid", u"Yiddish")
+Language("yo", "yor", u"Yoruba")
+Language("za", "zha", u"Zhuang")
+Language("zu", "zul", u"Zulu")
+Country("AF", u"AFGHANISTAN")
+Country("AX", u"ÅLAND ISLANDS")
+Country("AL", u"ALBANIA")
+Country("DZ", u"ALGERIA")
+Country("AS", u"AMERICAN SAMOA")
+Country("AD", u"ANDORRA")
+Country("AO", u"ANGOLA")
+Country("AI", u"ANGUILLA")
+Country("AQ", u"ANTARCTICA")
+Country("AG", u"ANTIGUA AND BARBUDA")
+Country("AR", u"ARGENTINA")
+Country("AM", u"ARMENIA")
+Country("AW", u"ARUBA")
+Country("AU", u"AUSTRALIA")
+Country("AT", u"AUSTRIA")
+Country("AZ", u"AZERBAIJAN")
+Country("BS", u"BAHAMAS")
+Country("BH", u"BAHRAIN")
+Country("BD", u"BANGLADESH")
+Country("BB", u"BARBADOS")
+Country("BY", u"BELARUS")
+Country("BE", u"BELGIUM")
+Country("BZ", u"BELIZE")
+Country("BJ", u"BENIN")
+Country("BM", u"BERMUDA")
+Country("BT", u"BHUTAN")
+Country("BO", u"BOLIVIA, PLURINATIONAL STATE OF")
+Country("BQ", u"BONAIRE, SINT EUSTATIUS AND SABA")
+Country("BA", u"BOSNIA AND HERZEGOVINA")
+Country("BW", u"BOTSWANA")
+Country("BV", u"BOUVET ISLAND")
+Country("BR", u"BRAZIL")
+Country("IO", u"BRITISH INDIAN OCEAN TERRITORY")
+Country("BN", u"BRUNEI DARUSSALAM")
+Country("BG", u"BULGARIA")
+Country("BF", u"BURKINA FASO")
+Country("BI", u"BURUNDI")
+Country("KH", u"CAMBODIA")
+Country("CM", u"CAMEROON")
+Country("CA", u"CANADA")
+Country("CV", u"CAPE VERDE")
+Country("KY", u"CAYMAN ISLANDS")
+Country("CF", u"CENTRAL AFRICAN REPUBLIC")
+Country("TD", u"CHAD")
+Country("CL", u"CHILE")
+Country("CN", u"CHINA")
+Country("CX", u"CHRISTMAS ISLAND")
+Country("CC", u"COCOS (KEELING) ISLANDS")
+Country("CO", u"COLOMBIA")
+Country("KM", u"COMOROS")
+Country("CG", u"CONGO")
+Country("CD", u"CONGO, THE DEMOCRATIC REPUBLIC OF THE")
+Country("CK", u"COOK ISLANDS")
+Country("CR", u"COSTA RICA")
+Country("CI", u"CÔTE D'IVOIRE")
+Country("HR", u"CROATIA")
+Country("CU", u"CUBA")
+Country("CW", u"CURAÇAO")
+Country("CY", u"CYPRUS")
+Country("CZ", u"CZECH REPUBLIC")
+Country("DK", u"DENMARK")
+Country("DJ", u"DJIBOUTI")
+Country("DM", u"DOMINICA")
+Country("DO", u"DOMINICAN REPUBLIC")
+Country("EC", u"ECUADOR")
+Country("EG", u"EGYPT")
+Country("SV", u"EL SALVADOR")
+Country("GQ", u"EQUATORIAL GUINEA")
+Country("ER", u"ERITREA")
+Country("EE", u"ESTONIA")
+Country("ET", u"ETHIOPIA")
+Country("FK", u"FALKLAND ISLANDS (MALVINAS)")
+Country("FO", u"FAROE ISLANDS")
+Country("FJ", u"FIJI")
+Country("FI", u"FINLAND")
+Country("FR", u"FRANCE")
+Country("GF", u"FRENCH GUIANA")
+Country("PF", u"FRENCH POLYNESIA")
+Country("TF", u"FRENCH SOUTHERN TERRITORIES")
+Country("GA", u"GABON")
+Country("GM", u"GAMBIA")
+Country("GE", u"GEORGIA")
+Country("DE", u"GERMANY")
+Country("GH", u"GHANA")
+Country("GI", u"GIBRALTAR")
+Country("GR", u"GREECE")
+Country("GL", u"GREENLAND")
+Country("GD", u"GRENADA")
+Country("GP", u"GUADELOUPE")
+Country("GU", u"GUAM")
+Country("GT", u"GUATEMALA")
+Country("GG", u"GUERNSEY")
+Country("GN", u"GUINEA")
+Country("GW", u"GUINEA-BISSAU")
+Country("GY", u"GUYANA")
+Country("HT", u"HAITI")
+Country("HM", u"HEARD ISLAND AND MCDONALD ISLANDS")
+Country("VA", u"HOLY SEE (VATICAN CITY STATE)")
+Country("HN", u"HONDURAS")
+Country("HK", u"HONG KONG")
+Country("HU", u"HUNGARY")
+Country("IS", u"ICELAND")
+Country("IN", u"INDIA")
+Country("ID", u"INDONESIA")
+Country("IR", u"IRAN, ISLAMIC REPUBLIC OF")
+Country("IQ", u"IRAQ")
+Country("IE", u"IRELAND")
+Country("IM", u"ISLE OF MAN")
+Country("IL", u"ISRAEL")
+Country("IT", u"ITALY")
+Country("JM", u"JAMAICA")
+Country("JP", u"JAPAN")
+Country("JE", u"JERSEY")
+Country("JO", u"JORDAN")
+Country("KZ", u"KAZAKHSTAN")
+Country("KE", u"KENYA")
+Country("KI", u"KIRIBATI")
+Country("KP", u"KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF")
+Country("KR", u"KOREA, REPUBLIC OF")
+Country("KW", u"KUWAIT")
+Country("KG", u"KYRGYZSTAN")
+Country("LA", u"LAO PEOPLE'S DEMOCRATIC REPUBLIC")
+Country("LV", u"LATVIA")
+Country("LB", u"LEBANON")
+Country("LS", u"LESOTHO")
+Country("LR", u"LIBERIA")
+Country("LY", u"LIBYA")
+Country("LI", u"LIECHTENSTEIN")
+Country("LT", u"LITHUANIA")
+Country("LU", u"LUXEMBOURG")
+Country("MO", u"MACAO")
+Country("MK", u"MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF")
+Country("MG", u"MADAGASCAR")
+Country("MW", u"MALAWI")
+Country("MY", u"MALAYSIA")
+Country("MV", u"MALDIVES")
+Country("ML", u"MALI")
+Country("MT", u"MALTA")
+Country("MH", u"MARSHALL ISLANDS")
+Country("MQ", u"MARTINIQUE")
+Country("MR", u"MAURITANIA")
+Country("MU", u"MAURITIUS")
+Country("YT", u"MAYOTTE")
+Country("MX", u"MEXICO")
+Country("FM", u"MICRONESIA, FEDERATED STATES OF")
+Country("MD", u"MOLDOVA, REPUBLIC OF")
+Country("MC", u"MONACO")
+Country("MN", u"MONGOLIA")
+Country("ME", u"MONTENEGRO")
+Country("MS", u"MONTSERRAT")
+Country("MA", u"MOROCCO")
+Country("MZ", u"MOZAMBIQUE")
+Country("MM", u"MYANMAR")
+Country("NA", u"NAMIBIA")
+Country("NR", u"NAURU")
+Country("NP", u"NEPAL")
+Country("NL", u"NETHERLANDS")
+Country("NC", u"NEW CALEDONIA")
+Country("NZ", u"NEW ZEALAND")
+Country("NI", u"NICARAGUA")
+Country("NE", u"NIGER")
+Country("NG", u"NIGERIA")
+Country("NU", u"NIUE")
+Country("NF", u"NORFOLK ISLAND")
+Country("MP", u"NORTHERN MARIANA ISLANDS")
+Country("NO", u"NORWAY")
+Country("OM", u"OMAN")
+Country("PK", u"PAKISTAN")
+Country("PW", u"PALAU")
+Country("PS", u"PALESTINIAN TERRITORY, OCCUPIED")
+Country("PA", u"PANAMA")
+Country("PG", u"PAPUA NEW GUINEA")
+Country("PY", u"PARAGUAY")
+Country("PE", u"PERU")
+Country("PH", u"PHILIPPINES")
+Country("PN", u"PITCAIRN")
+Country("PL", u"POLAND")
+Country("PT", u"PORTUGAL")
+Country("PR", u"PUERTO RICO")
+Country("QA", u"QATAR")
+Country("RE", u"RÉUNION")
+Country("RO", u"ROMANIA")
+Country("RU", u"RUSSIAN FEDERATION")
+Country("RW", u"RWANDA")
+Country("BL", u"SAINT BARTHÉLEMY")
+Country("SH", u"SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA")
+Country("KN", u"SAINT KITTS AND NEVIS")
+Country("LC", u"SAINT LUCIA")
+Country("MF", u"SAINT MARTIN (FRENCH PART)")
+Country("PM", u"SAINT PIERRE AND MIQUELON")
+Country("VC", u"SAINT VINCENT AND THE GRENADINES")
+Country("WS", u"SAMOA")
+Country("SM", u"SAN MARINO")
+Country("ST", u"SAO TOME AND PRINCIPE")
+Country("SA", u"SAUDI ARABIA")
+Country("SN", u"SENEGAL")
+Country("RS", u"SERBIA")
+Country("SC", u"SEYCHELLES")
+Country("SL", u"SIERRA LEONE")
+Country("SG", u"SINGAPORE")
+Country("SX", u"SINT MAARTEN (DUTCH PART)")
+Country("SK", u"SLOVAKIA")
+Country("SI", u"SLOVENIA")
+Country("SB", u"SOLOMON ISLANDS")
+Country("SO", u"SOMALIA")
+Country("ZA", u"SOUTH AFRICA")
+Country("GS", u"SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS")
+Country("SS", u"SOUTH SUDAN")
+Country("ES", u"SPAIN")
+Country("LK", u"SRI LANKA")
+Country("SD", u"SUDAN")
+Country("SR", u"SURINAME")
+Country("SJ", u"SVALBARD AND JAN MAYEN")
+Country("SZ", u"SWAZILAND")
+Country("SE", u"SWEDEN")
+Country("CH", u"SWITZERLAND")
+Country("SY", u"SYRIAN ARAB REPUBLIC")
+Country("TW", u"TAIWAN, PROVINCE OF CHINA")
+Country("TJ", u"TAJIKISTAN")
+Country("TZ", u"TANZANIA, UNITED REPUBLIC OF")
+Country("TH", u"THAILAND")
+Country("TL", u"TIMOR-LESTE")
+Country("TG", u"TOGO")
+Country("TK", u"TOKELAU")
+Country("TO", u"TONGA")
+Country("TT", u"TRINIDAD AND TOBAGO")
+Country("TN", u"TUNISIA")
+Country("TR", u"TURKEY")
+Country("TM", u"TURKMENISTAN")
+Country("TC", u"TURKS AND CAICOS ISLANDS")
+Country("TV", u"TUVALU")
+Country("UG", u"UGANDA")
+Country("UA", u"UKRAINE")
+Country("AE", u"UNITED ARAB EMIRATES")
+Country("GB", u"UNITED KINGDOM")
+Country("US", u"UNITED STATES")
+Country("UM", u"UNITED STATES MINOR OUTLYING ISLANDS")
+Country("UY", u"URUGUAY")
+Country("UZ", u"UZBEKISTAN")
+Country("VU", u"VANUATU")
+Country("VE", u"VENEZUELA, BOLIVARIAN REPUBLIC OF")
+Country("VN", u"VIET NAM")
+Country("VG", u"VIRGIN ISLANDS, BRITISH")
+Country("VI", u"VIRGIN ISLANDS, U.S.")
+Country("WF", u"WALLIS AND FUTUNA")
+Country("EH", u"WESTERN SAHARA")
+Country("YE", u"YEMEN")
+Country("ZM", u"ZAMBIA")
+Country("ZW", u"ZIMBABWE")
View
3  mythtv/bindings/python/MythTV/tmdb3/tmdb3/request.py
@@ -52,7 +52,8 @@ def __init__(self, url, **kwargs):
"""Return a request object, using specified API path and arguments."""
kwargs['api_key'] = self.api_key
self._url = url.lstrip('/')
- self._kwargs = kwargs
+ self._kwargs = dict([(kwa,kwv) for kwa,kwv in kwargs.items()
+ if kwv is not None])
url = '{0}{1}?{2}'.format(self._base_url, self._url,
urllib.urlencode(kwargs))
urllib2.Request.__init__(self, url)
View
73 mythtv/bindings/python/MythTV/tmdb3/tmdb3/tmdb_api.py
@@ -22,7 +22,7 @@
Preliminary API specifications can be found at
http://help.themoviedb.org/kb/api/about-3"""
-__version__="v0.3.7"
+__version__="v0.4.1"
# 0.1.0 Initial development
# 0.2.0 Add caching mechanism for API queries
# 0.2.1 Temporary work around for broken search paging
@@ -34,10 +34,13 @@
# 0.3.5 Add methods for grabbing current, popular, and top rated movies
# 0.3.6 Rework paging mechanism
# 0.3.7 Generalize caching mechanism, and allow controllability
+# 0.4.0 Add full locale support (language and country) and optional fall through
+# 0.4.1 Add custom classmethod for dealing with IMDB movie IDs
from request import set_key, Request
from util import Datapoint, Datalist, Datadict, Element
from pager import PagedRequest
+from locales import get_locale, set_locale
from tmdb_exceptions import *
import json
@@ -53,21 +56,19 @@ def _populate(self):
return Request('configuration')
Configuration = Configuration()
-def searchMovie(query, language='en', adult=False):
+def searchMovie(query, locale=None, adult=False):
return MovieSearchResult(
Request('search/movie', query=query, include_adult=adult),
- language=language)
+ locale=locale)
class MovieSearchResult( PagedRequest ):
"""Stores a list of search matches."""
- def __init__(self, request, language=None):
- if language:
- super(MovieSearchResult, self).__init__(
- request.new(language=language),
- lambda x: Movie(raw=x, language=language))
- else:
- super(MovieSearchResult, self).__init__(request,
- lambda x: Movie(raw=x))
+ def __init__(self, request, locale=None):
+ if locale is None:
+ locale = get_locale()
+ super(MovieSearchResult, self).__init__(
+ request.new(language=locale.language),
+ lambda x: Movie(raw=x, locale=locale))
def __repr__(self):
return u"<Search Results: {0}>".format(self._request._kwargs['query'])
@@ -78,13 +79,15 @@ def searchPerson(query):
class PeopleSearchResult( PagedRequest ):
"""Stores a list of search matches."""
def __init__(self, request):
- super(PeopleSearchResults, self).__init__(res)
+ super(PeopleSearchResults, self).__init__(request,
+ lambda x: Person(raw=x))
def __repr__(self):
return u"<Search Results: {0}>".format(self.request._kwargs['query'])
class Image( Element ):
- filename = Datapoint('file_path', initarg=1, handler=lambda x: x.lstrip('/'))
+ filename = Datapoint('file_path', initarg=1,
+ handler=lambda x: x.lstrip('/'))
aspectratio = Datapoint('aspect_ratio')
height = Datapoint('height')
width = Datapoint('width')
@@ -135,7 +138,7 @@ def __repr__(self):
def _populate(self):
return Request('person/{0}'.format(self.id))
def _populate_credits(self):
- return Request('person/{0}/credits'.format(self.id), language=self._lang)
+ return Request('person/{0}/credits'.format(self.id), language=self._locale.language)
def _populate_images(self):
return Request('person/{0}/images'.format(self.id))
@@ -219,16 +222,31 @@ def latest(cls):
return cls(raw=req.readJSON())
@classmethod
- def nowplaying(cls, language='en'):
- return MovieSearchResult(Request('movie/now-playing'), language=language)
+ def nowplaying(cls, locale=None):
+ return MovieSearchResult(Request('movie/now-playing'), locale=locale)
+
+ @classmethod
+ def mostpopular(cls, locale=None):
+ return MovieSearchResult(Request('movie/popular'), locale=locale)
@classmethod
- def mostpopular(cls, language='en'):
- return MovieSearchResult(Request('movie/popular'), language=language)
+ def toprated(cls, locale=None):
+ return MovieSearchResult(Request('movie/top-rated'), locale=locale)
@classmethod
- def toprated(cls, language='en'):
- return MovieSearchResult(Request('movie/top-rated'), language=language)
+ def fromIMDB(cls, imdbid, locale=None):
+ try:
+ # assume string
+ if not imdbid.startswith('tt'):
+ imdbid = "tt{0:0>7}".format(imdbid)
+ except AttributeError:
+ # assume integer
+ imdbid = "tt{0:0>7}".format(imdbid)
+ if locale is None:
+ locale = get_locale()
+ movie = cls(imdbid, locale=locale)
+ movie._populate()
+ return movie
id = Datapoint('id', initarg=1)
title = Datapoint('title')
@@ -239,7 +257,7 @@ def toprated(cls, language='en'):
budget = Datapoint('budget')
revenue = Datapoint('revenue')
releasedate = Datapoint('release_date', handler=lambda x: \
- datetime.datetime.strptime(x, '%Y-%m-%d'))
+ datetime.datetime.strptime(x, '%Y-%m-%d'))
homepage = Datapoint('homepage')
imdb = Datapoint('imdb_id')
@@ -251,26 +269,27 @@ def toprated(cls, language='en'):
votes = Datapoint('vote_count')
adult = Datapoint('adult')
- collection = Datapoint('belongs_to_collection', handler=lambda x: Collection(raw=x))
+ collection = Datapoint('belongs_to_collection', handler=lambda x: \
+ Collection(raw=x))
genres = Datalist('genres', handler=Genre)
studios = Datalist('production_companies', handler=Studio)
countries = Datalist('production_countries', handler=Country)
languages = Datalist('spoken_languages', handler=Language)
def _populate(self):
- return Request('movie/{0}'.format(self.id), language=self._lang)
+ return Request('movie/{0}'.format(self.id), language=self._locale.language)
def _populate_titles(self):
- return Request('movie/{0}/alternative_titles'.format(self.id))
+ return Request('movie/{0}/alternative_titles'.format(self.id), country=self._locale.country)
def _populate_cast(self):
return Request('movie/{0}/casts'.format(self.id))
def _populate_images(self):
- return Request('movie/{0}/images'.format(self.id), language=self._lang)
+ return Request('movie/{0}/images'.format(self.id), language=self._locale.language)
def _populate_keywords(self):
return Request('movie/{0}/keywords'.format(self.id))
def _populate_releases(self):
return Request('movie/{0}/releases'.format(self.id))
def _populate_trailers(self):
- return Request('movie/{0}/trailers'.format(self.id), language=self._lang)
+ return Request('movie/{0}/trailers'.format(self.id), language=self._locale.language)
def _populate_translations(self):
return Request('movie/{0}/translations'.format(self.id))
@@ -333,7 +352,7 @@ class Collection( Element ):
members = Datalist('parts', handler=Movie, sort='releasedate')
def _populate(self):
- return Request('collection/{0}'.format(self.id), language=self._lang)
+ return Request('collection/{0}'.format(self.id), language=self._locale.language)
def __repr__(self):
return u"<{0.__class__.__name__} '{0.name}'>".format(self).encode('utf-8')
View
4 mythtv/bindings/python/MythTV/tmdb3/tmdb3/tmdb_exceptions.py
@@ -21,6 +21,7 @@ class TMDBError( Exception ):
ImageSizeError = 80
HTTPError = 90
Offline = 100
+ LocaleError = 110
def __init__(self, msg=None, errno=0):
self.errno = errno
@@ -76,3 +77,6 @@ class TMDBHTTPError( TMDBError ):
class TMDBOffline( TMDBError ):
pass
+class TMDBLocaleError( TMDBError ):
+ pass
+
View
48 mythtv/bindings/python/MythTV/tmdb3/tmdb3/util.py
@@ -7,6 +7,7 @@
#-----------------------
from copy import copy
+from locales import get_locale
class Poller( object ):
"""
@@ -42,18 +43,41 @@ def __call__(self):
# retrieve data from callable function, and apply
if not callable(self.func):
raise RuntimeError('Poller object called without a source function')
- self.apply(self.func().readJSON())
+ req = self.func()
+ if (('language' in req._kwargs) or ('country' in req._kwargs)) \
+ and self.inst._locale.fallthrough:
+ # request specifies a locale filter, and fallthrough is enabled
+ # run a first pass with specified filter
+ if not self.apply(req.readJSON(), False):
+ return
+ # if first pass results in missed data, run a second pass to
+ # fill in the gaps
+ self.apply(req.new(language=None, country=None).readJSON())
+ # re-apply the filtered first pass data over top the second
+ # unfiltered set. this is to work around the issue that the
+ # properties have no way of knowing when they should or
+ # should not overwrite existing data. the cache engine will
+ # take care of the duplicate query
+ self.apply(req.readJSON())
def apply(self, data, set_nones=True):
# apply data directly, bypassing callable function
+ unfilled = False
for k,v in self.lookup.items():
- if k in data:
+ if (k in data) and (data[k] is not None):
+ # argument received data, populate it
setattr(self.inst, v, data[k])
elif set_nones:
+ # argument did not receive data, so fill it with None
+ # to indicate such and prevent a repeat scan
setattr(self.inst, v, None)
- # else leave attribute empty, allowing it to later trigger a poll
- # to get data if requested. this is intended for use when
- # initializing a class with raw data
+ else:
+ # argument does not need data, so ignore it allowing it to
+ # trigger a later poll. this is intended for use when
+ # initializing a class with raw data, or when performing a
+ # first pass through when performing locale fall through
+ unfilled = True
+ return unfilled
class Data( object ):
"""
@@ -104,7 +128,7 @@ def __set__(self, inst, value):
else:
value = self.default
if isinstance(value, Element):
- value._lang = inst._lang
+ value._locale = inst._locale
inst._data[self.field] = value
def sethandler(self, handler):
@@ -153,7 +177,7 @@ def __set__(self, inst, value):
for val in value:
val = self.handler(val)
if isinstance(val, Element):
- val._lang = inst._lang
+ val._locale = inst._locale
data.append(val)
if self.sort:
data.sort(key=lambda x: getattr(x, self.sort))
@@ -203,7 +227,7 @@ def __set__(self, inst, value):
for val in value:
val = self.handler(val)
if isinstance(val, Element):
- val._lang = inst._lang
+ val._locale = inst._locale
data[self.getkey(val)] = val
inst._data[self.field] = data
@@ -280,8 +304,10 @@ def __new__(mcs, name, bases, attrs):
def __call__(cls, *args, **kwargs):
obj = cls.__new__(cls)
- if 'language' in kwargs:
- obj._lang = kwargs['language']
+ if 'locale' in kwargs:
+ obj._locale = kwargs['locale']
+ else:
+ obj._locale = get_locale()
obj._data = {}
if 'raw' in kwargs:
@@ -294,7 +320,7 @@ def __call__(cls, *args, **kwargs):
# defined by the Data definitions
if len(args) != len(cls._InitArgs):
raise TypeError('__init__() takes exactly {0} arguments ({1} given)'\
- .format(len(cls._InitArgs)+1), len(args)+1)
+ .format(len(cls._InitArgs)+1, len(args)+1))
for a,v in zip(cls._InitArgs, args):
setattr(obj, a, v)
Please sign in to comment.
Something went wrong with that request. Please try again.