1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
|
"""
parser.local package (imdb package).
This package provides the IMDbLocalAccessSystem class used to access
IMDb's data through a local installation.
the imdb.IMDb function will return an instance of this class when
called with the 'accessSystem' argument set to "local" or "files".
Copyright 2004-2006 Davide Alberani <da@erlug.linux.it>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
from __future__ import generators
import os
from stat import ST_SIZE
from imdb._exceptions import IMDbDataAccessError, IMDbError
from imdb.utils import analyze_title, analyze_name, re_episodes
from imdb.Person import Person
from imdb.Movie import Movie
from personParser import getFilmography, getBio, getAkaNames
from movieParser import getLabel, getMovieCast, getAkaTitles, parseMinusList, \
getPlot, getRatingData, getMovieMisc, getTaglines, \
getQuotes, getMovieLinks, getBusiness, getLiterature, \
getLaserdisc
from utils import getFullIndex, KeyFScan, latin2utf
from imdb.parser.common.locsql import IMDbLocalAndSqlAccessSystem, \
titleVariations, nameVariations
try:
from imdb.parser.common.cutils import get_episodes
except ImportError:
import warnings
warnings.warn('Unable to import the cutils.get_episodes function.'
' Retrieving episodes list of tv series will be'
' a bit slower.')
def get_episodes(movieID, indexFile, keyFile):
if movieID < 0:
raise IMDbDataAccessError, "movieID must be positive."
try:
ifile = open(indexFile, 'rb')
except IOError, e:
raise IMDbDataAccessError, str(e)
ifile.seek(4L*movieID, 0)
indexStr = ifile.read(4)
ifile.close()
if len(indexStr) != 4:
raise IMDbDataAccessError, \
"unable to read indexFile; movieID too high?"
kfIndex = 0L
for i in (0, 1, 2, 3):
kfIndex |= ord(indexStr[i]) << i*8L;
try:
kfile = open(keyFile, 'rt')
except IOError, e:
raise IMDbDataAccessError, str(e)
kfile.seek(kfIndex, 0)
seriesTitle = kfile.readline().split('|')[0].strip()
if seriesTitle[0:1] != '"' or seriesTitle[-1:] != ')':
return []
stLen = len(seriesTitle)
results = []
for line in kfile:
if not line.strip(): break
epsTitle, epsID = line.split('|')
if epsTitle[:stLen] != seriesTitle: break
if epsTitle[stLen+1] != '{' or epsTitle[-1] != '}':
break
results.append((int(epsID.strip(), 16), epsTitle))
kfile.close()
return results
try:
from imdb.parser.common.cutils import search_name
def _scan_names(keyFile, name1, name2, name3, results=0):
"""Scan the given file, using the cutils.search_name
C function, for name variations."""
# the search_name function in the cutils C module manages
# latin_1 encoded strings.
name1, name2, name3 = [x.encode('latin_1', 'replace')
for x in name1, name2, name3]
sn = search_name(keyFile, name1, name2, name3, results)
res = []
for x in sn:
tmpd = analyze_name(latin2utf(x[2]))
res.append((x[0], (x[1], tmpd)))
return res
except ImportError:
import warnings
warnings.warn('Unable to import the cutils.search_name function.'
' Searching names using the "local" data access system'
' will be REALLY slow.')
from imdb.parser.common.locsql import scan_names
def _readNamesKeyFile(keyFile):
"""Iterate over the given file, returning tuples suited for
the common.locsql.scan_names function."""
try: kf = open(keyFile, 'r')
except IOError, e: raise IMDbDataAccessError, str(e)
for line in kf:
ls = line.split('|')
if not ls[0]: continue
named = analyze_name(latin2utf(ls[0]))
yield (long(ls[1], 16), named)
kf.close()
def _scan_names(keyFile, name1, name2, name3, results=0):
"""Scan the given file, using the common.locsql.scan_names
pure-Python function, for name variations."""
return scan_names(_readNamesKeyFile(keyFile),
name1, name2, name3, results)
try:
from imdb.parser.common.cutils import search_title
def _scan_titles(keyFile, title1, title2, title3, results=0):
"""Scan the given file, using the cutils.search_title
C function, for title variations."""
title1, title2, title3 = [x.encode('latin_1', 'replace')
for x in title1, title2, title3]
st = search_title(keyFile, title1, title2, title3, results)
res = []
for x in st:
tmpd = analyze_title(latin2utf(x[2]))
res.append((x[0], (x[1], tmpd)))
return res
except ImportError:
import warnings
warnings.warn('Unable to import the cutils.search_title function.'
' Searching titles using the "local" data access system'
' will be REALLY slow.')
from imdb.parser.common.locsql import scan_titles
def _readTitlesKeyFile(keyFile, searchingEpisode=0, lenTitle=1):
"""Iterate over the given file, returning tuples suited for
the common.locsql.scan_titles function."""
STRING_MAXLENDIFFER = 0.7
lenTitle = float(lenTitle)
try: kf = open(keyFile, 'r')
except IOError, e: raise IMDbDataAccessError, str(e)
for line in kf:
ls = line.split('|')
t = ls[0]
if not t: continue
l_t = len(t)
if (lenTitle > l_t): threshold = l_t / lenTitle
else: threshold = lenTitle / l_t
# don't compare too different lenght strings.
if threshold < STRING_MAXLENDIFFER: continue
if searchingEpisode:
if t[-1] != '}': continue
elif t[-1] == '}': continue
titled = analyze_title(latin2utf(t))
yield (long(ls[1], 16), titled)
kf.close()
def _scan_titles(keyFile, title1, title2, title3, results=0):
"""Scan the given file, using the common.locsql.scan_titles
pure-Python function, for title variations."""
se = 0
if title3 and title3[-1] == '}': se = 1
return scan_titles(_readTitlesKeyFile(keyFile, searchingEpisode=se,
lenTitle=len(title3 or title1)),
title1, title2, title3, results)
class IMDbLocalAccessSystem(IMDbLocalAndSqlAccessSystem):
"""The class used to access IMDb's data through a local installation."""
accessSystem = 'local'
def __init__(self, dbDirectory, adultSearch=1, *arguments, **keywords):
"""Initialize the access system.
The directory with the files must be supplied.
"""
IMDbLocalAndSqlAccessSystem.__init__(self, *arguments, **keywords)
self.__db = os.path.expandvars(dbDirectory)
self.__db = os.path.expanduser(self.__db)
if hasattr(os.path, 'realpath'):
self.__db = os.path.realpath(self.__db)
self.__db = os.path.normpath(self.__db)
self.__db = self.__db + getattr(os.path, 'sep', '/')
self.__db = os.path.normcase(self.__db)
if not os.path.isdir(self.__db):
raise IMDbDataAccessError, '"%s" is not a directory' % self.__db
# These indices are used to quickly get the mopID
# for a given title/name.
self.__namesScan = KeyFScan('%snames.key' % self.__db)
self.__titlesScan = KeyFScan('%stitles.key' % self.__db)
self.do_adult_search(adultSearch)
def _getTitleID(self, title):
return self.__titlesScan.getID(title)
def _getNameID(self, name):
return self.__namesScan.getID(name)
def _get_lastID(self, indexF):
fsize = os.stat(indexF)[ST_SIZE]
return (fsize / 4) - 1
def get_lastMovieID(self):
"""Return the last movieID"""
return self._get_lastID('%stitles.index' % self.__db)
def get_lastPersonID(self):
"""Return the last personID"""
return self._get_lastID('%snames.index' % self.__db)
def _normalize_movieID(self, movieID):
"""Normalize the given movieID."""
try:
return int(movieID)
except (ValueError, OverflowError):
raise IMDbError, 'movieID "%s" can\'t be converted to integer' % \
movieID
def _normalize_personID(self, personID):
"""Normalize the given personID."""
try:
return int(personID)
except (ValueError, OverflowError):
raise IMDbError, 'personID "%s" can\'t be converted to integer' % \
personID
def _get_real_movieID(self, movieID):
"""Handle title aliases."""
rid = getFullIndex('%saka-titles.index' % self.__db, movieID,
kind='akatidx')
if rid is not None: return rid
return movieID
def _get_real_personID(self, personID):
"""Handle name aliases."""
rid = getFullIndex('%saka-names.index' % self.__db, personID,
kind='akanidx')
if rid is not None: return rid
return personID
def get_imdbMovieID(self, movieID):
"""Translate a movieID in an imdbID.
Try an Exact Primary Title search on IMDb;
return None if it's unable to get the imdbID.
"""
titline = getLabel(movieID, '%stitles.index' % self.__db,
'%stitles.key' % self.__db)
if titline is None: return None
return self.title2imdbID(titline)
def get_imdbPersonID(self, personID):
"""Translate a personID in an imdbID.
Try an Exact Primary Name search on IMDb;
return None if it's unable to get the imdbID.
"""
name = getLabel(personID, '%snames.index' % self.__db,
'%snames.key' % self.__db)
if name is None: return None
return self.name2imdbID(name)
def do_adult_search(self, doAdult):
"""If set to 0 or False, movies in the Adult category are not
shown in the results of a search."""
self.doAdult = doAdult
def _search_movie(self, title, results):
title = title.strip()
if not title: return []
# Search for these title variations.
title1, title2, title3 = titleVariations(title)
resultsST = results
if not self.doAdult: resultsST = 0
res = _scan_titles('%stitles.key' % self.__db,
title1, title2, title3, resultsST)
if self.doAdult and results > 0: res[:] = res[:results]
res[:] = [x[1] for x in res]
# Check for adult movies.
if not self.doAdult:
newlist = []
for entry in res:
genres = getMovieMisc(movieID=entry[0],
dataF='%s%s.data' % (self.__db, 'genres'),
indexF='%s%s.index' % (self.__db, 'genres'),
attrIF='%sattributes.index' % self.__db,
attrKF='%sattributes.key' % self.__db)
if 'Adult' not in genres: newlist.append(entry)
res[:] = newlist
if results > 0: res[:] = res[:results]
return res
def get_movie_main(self, movieID):
# Information sets provided by this method.
infosets = ('main', 'vote details')
tl = getLabel(movieID, '%stitles.index' % self.__db,
'%stitles.key' % self.__db)
# No title, no party.
if tl is None:
raise IMDbDataAccessError, 'unable to get movieID "%s"' % movieID
res = analyze_title(tl)
# Build the cast list.
actl = []
for castG in ('actors', 'actresses'):
midx = getFullIndex('%s%s.titles' % (self.__db, castG),
movieID, multi=1)
if midx is not None:
params = {'movieID': movieID,
'dataF': '%s%s.data' % (self.__db, castG),
'indexF': '%snames.index' % self.__db,
'keyF': '%snames.key' % self.__db,
'attrIF': '%sattributes.index' % self.__db,
'attrKF': '%sattributes.key' % self.__db,
'offsList': midx, 'doCast': 1}
actl += getMovieCast(**params)
if actl:
actl.sort()
res['cast'] = actl
# List of other workers.
works = ('writer', 'cinematographer', 'composer',
'costume-designer', 'director', 'editor', 'miscellaneou',
'producer', 'production-designer', 'cinematographer')
for i in works:
index = getFullIndex('%s%ss.titles' % (self.__db, i),
movieID, multi=1)
if index is not None:
params = {'movieID': movieID,
'dataF': '%s%s.data' % (self.__db, i),
'indexF': '%snames.index' % self.__db,
'keyF': '%snames.key' % self.__db,
'attrIF': '%sattributes.index' % self.__db,
'attrKF': '%sattributes.key' % self.__db,
'offsList': index}
name = key = i
if '-' in name:
name = name.replace('-', ' ')
elif name == 'miscellaneou':
name = 'miscellaneous crew'
key = 'miscellaneou'
elif name == 'writer':
params['doWriters'] = 1
params['dataF'] = '%s%ss.data' % (self.__db, key)
data = getMovieCast(**params)
if name == 'writer': data.sort()
res[name] = data
# Rating.
rt = self.get_movie_vote_details(movieID)['data']
if rt: res.update(rt)
# Various information.
miscInfo = (('runtimes', 'running-times'), ('color info', 'color-info'),
('genres', 'genres'), ('distributors', 'distributors'),
('languages', 'language'), ('certificates', 'certificates'),
('special effects companies', 'special-effects-companies'),
('sound mix', 'sound-mix'), ('tech info', 'technical'),
('production companies', 'production-companies'),
('countries', 'countries'))
for name, fname in miscInfo:
params = {'movieID': movieID,
'dataF': '%s%s.data' % (self.__db, fname),
'indexF': '%s%s.index' % (self.__db, fname),
'attrIF': '%sattributes.index' % self.__db,
'attrKF': '%sattributes.key' % self.__db}
data = getMovieMisc(**params)
if data: res[name] = data
if res.has_key('runtimes') and len(res['runtimes']) > 0:
rt = res['runtimes'][0]
episodes = re_episodes.findall(rt)
if episodes:
res['runtimes'][0] = re_episodes.sub('', rt)
res['number of episodes'] = episodes[0]
# AKA titles.
akas = getAkaTitles(movieID,
'%saka-titles.data' % self.__db,
'%stitles.index' % self.__db,
'%stitles.key' % self.__db,
'%sattributes.index' % self.__db,
'%sattributes.key' % self.__db)
if akas:
# normalize encoding.
for i in xrange(len(akas)):
ts = akas[i].split('::')
if len(ts) != 2: continue
t = ts[0]
n = ts[1]
nt = self._changeAKAencoding(n, t)
if nt is not None: akas[i] = '%s::%s' % (nt, n)
res['akas'] = akas
if res.get('kind') == 'episode':
# Things to do if this is a tv series episode.
episodeOf = res.get('episode of')
if episodeOf is not None:
parentSeries = Movie(data=res['episode of'],
accessSystem='local')
seriesID = self._getTitleID(parentSeries.get(
'long imdb canonical title'))
parentSeries.movieID = seriesID
res['episode of'] = parentSeries
if not res.get('year'):
year = getFullIndex('%smovies.data' % self.__db,
movieID, kind='moviedata', rindex=1)
if year: res['year'] = year
return {'data': res, 'info sets': infosets}
def get_movie_plot(self, movieID):
pl = getPlot(movieID, '%splot.index' % self.__db,
'%splot.data' % self.__db)
trefs, nrefs = self._extractRefs(pl)
if pl: return {'data': {'plot': pl},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_taglines(self, movieID):
tg = getTaglines(movieID, '%staglines.index' % self.__db,
'%staglines.data' % self.__db)
if tg: return {'data': {'taglines': tg}}
return {'data': {}}
def get_movie_keywords(self, movieID):
params = {'movieID': movieID,
'dataF': '%skeywords.data' % self.__db,
'indexF': '%skeywords.index' % self.__db,
'attrIF': '%sattributes.index' % self.__db,
'attrKF': '%sattributes.key' % self.__db}
kwds = getMovieMisc(**params)
if kwds: return {'data': {'keywords': kwds}}
return {'data': {}}
def get_movie_alternate_versions(self, movieID):
av = parseMinusList(movieID, '%salternate-versions.data' % self.__db,
'%salternate-versions.index' % self.__db)
trefs, nrefs = self._extractRefs(av)
if av: return {'data': {'alternate versions': av},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_crazy_credits(self, movieID):
cc = parseMinusList(movieID, '%scrazy-credits.data' % self.__db,
'%scrazy-credits.index' % self.__db)
trefs, nrefs = self._extractRefs(cc)
if cc: return {'data': {'crazy credits': cc},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_goofs(self, movieID):
goo = parseMinusList(movieID, '%sgoofs.data' % self.__db,
'%sgoofs.index' % self.__db)
trefs, nrefs = self._extractRefs(goo)
if goo: return {'data': {'goofs': goo},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_soundtrack(self, movieID):
goo = parseMinusList(movieID, '%ssoundtracks.data' % self.__db,
'%ssoundtracks.index' % self.__db)
trefs, nrefs = self._extractRefs(goo)
if goo: return {'data': {'soundtrack': goo},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_quotes(self, movieID):
mq = getQuotes(movieID, '%squotes.data' % self.__db,
'%squotes.index' % self.__db)
trefs, nrefs = self._extractRefs(mq)
if mq: return {'data': {'quotes': mq},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_release_dates(self, movieID):
params = {'movieID': movieID,
'dataF': '%srelease-dates.data' % self.__db,
'indexF': '%srelease-dates.index' % self.__db,
'attrIF': '%sattributes.index' % self.__db,
'attrKF': '%sattributes.key' % self.__db}
data = getMovieMisc(**params)
if data: return {'data': {'release dates': data}}
return {'data': {}}
def get_movie_vote_details(self, movieID):
data = getRatingData(movieID, '%sratings.data' % self.__db)
return {'data': data}
def get_movie_trivia(self, movieID):
triv = parseMinusList(movieID, '%strivia.data' % self.__db,
'%strivia.index' % self.__db)
trefs, nrefs = self._extractRefs(triv)
if triv: return {'data': {'trivia': triv},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_locations(self, movieID):
params = {'movieID': movieID,
'dataF': '%slocations.data' % self.__db,
'indexF': '%slocations.index' % self.__db,
'attrIF': '%sattributes.index' % self.__db,
'attrKF': '%sattributes.key' % self.__db}
data = getMovieMisc(**params)
if data: return {'data': {'locations': data}}
return {'data': {}}
def get_movie_connections(self, movieID):
mc = getMovieLinks(movieID, '%smovie-links.data' % self.__db,
'%stitles.index' % self.__db,
'%stitles.key' % self.__db)
if mc: return {'data': {'connections': mc}}
return {'data': {}}
def get_movie_business(self, movieID):
mb = getBusiness(movieID, '%sbusiness.index' % self.__db,
'%sbusiness.data' % self.__db)
trefs, nrefs = self._extractRefs(mb)
if mb: return {'data': {'business': mb},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def get_movie_literature(self, movieID):
ml = getLiterature(movieID, '%sliterature.index' % self.__db,
'%sliterature.data' % self.__db)
if ml: return {'data': {'literature': ml}}
return {'data': {}}
def get_movie_laserdisc(self, movieID):
ml = getLaserdisc(movieID, '%slaserdisc.index' % self.__db,
'%slaserdisc.data' % self.__db)
trefs, nrefs = self._extractRefs(ml)
if ml: return {'data': {'laserdisc': ml},
'titlesRefs': trefs, 'namesRefs': nrefs}
return {'data': {}}
def _buildEpisodes(self, eps_list, parentID):
episodes = {}
parentTitle = getLabel(parentID, '%stitles.index' % self.__db,
'%stitles.key' % self.__db)
parentSeries = Movie(title=parentTitle,
movieID=parentID, accessSystem='local')
for episodeID, episodeTitle in eps_list:
episodeTitle = unicode(episodeTitle, 'latin_1', 'replace')
data = analyze_title(episodeTitle, canonical=1)
m = Movie(data=data, movieID=episodeID, accessSystem='local')
m['episode of'] = parentSeries
if data.get('year') is None:
year = getFullIndex('%smovies.data' % self.__db,
key=episodeID, kind='moviedata', rindex=1)
if year: m['year'] = year
season = data.get('season', 'UNKNOWN')
if not episodes.has_key(season): episodes[season] = {}
ep_number = data.get('episode')
if ep_number is None:
ep_number = max((episodes[season].keys() or [0])) + 1
episodes[season][ep_number] = m
return episodes
def get_movie_episodes(self, movieID):
try:
me = get_episodes(movieID, '%stitles.index' % self.__db,
'%stitles.key' % self.__db)
except IOError, e:
raise IMDbDataAccessError, str(e)
if me:
return {'data': {'episodes': self._buildEpisodes(me, movieID)}}
return {'data': {}}
def _search_person(self, name, results):
name = name.strip()
if not name: return []
name1, name2, name3 = nameVariations(name)
resultsST = results
if not self.doAdult: resultsST = 0
res = _scan_names('%snames.key' % self.__db,
name1, name2, name3, resultsST)
if results > 0: res[:] = res[:results]
res[:] = [x[1] for x in res]
return res
def get_person_main(self, personID):
infosets = ('main', 'biography', 'other works')
nl = getLabel(personID, '%snames.index' % self.__db,
'%snames.key' % self.__db)
# No name, no party.
if nl is None:
raise IMDbDataAccessError, 'unable to get personID "%s"' % personID
res = analyze_name(nl)
res.update(getBio(personID, '%sbiographies.index' % self.__db,
'%sbiographies.data' % self.__db))
akas = getAkaNames(personID,
'%saka-names.data' % self.__db,
'%snames.index' % self.__db,
'%snames.key' % self.__db)
if akas: res['akas'] = akas
# XXX: horrible hack! The getBio() function is not able to
# retrieve the movieID!
# A cleaner solution, would be to NOT return Movies object
# at first, from the getBio() function.
# XXX: anyway, this is no more needed, since "guest appearances"
# are gone with the new tv series episodes support.
if res.has_key('notable tv guest appearances'):
nl = []
for m in res['notable tv guest appearances']:
movieID = self._getTitleID(m.get('long imdb canonical title'))
if movieID is None: continue
m.movieID = movieID
nl.append(m)
if nl:
nl.sort()
res['notable tv guest appearances'][:] = nl
else: del res['notable tv guest appearances']
trefs, nrefs = self._extractRefs(res)
return {'data': res, 'info sets': infosets,
'titlesRefs': trefs, 'namesRefs': nrefs}
def get_person_filmography(self, personID):
infosets = ('filmography', 'episodes')
res = {}
episodes = {}
works = ('actor', 'actresse', 'producer', 'writer',
'cinematographer', 'composer', 'costume-designer',
'director', 'editor', 'miscellaneou', 'production-designer')
for i in works:
index = getFullIndex('%s%ss.names' % (self.__db, i), personID)
if index is not None:
params = {'offset': index,
'indexF': '%stitles.index' % self.__db,
'keyF': '%stitles.key' % self.__db,
'attrIF': '%sattributes.index' % self.__db,
'attrKF': '%sattributes.key' % self.__db}
name = key = i
if '-' in name:
name = name.replace('-', ' ')
elif name == 'actresse':
name = 'actress'
params['doCast'] = 1
elif name == 'miscellaneou':
name = 'miscellaneous crew'
key = 'miscellaneou'
elif name == 'actor':
params['doCast'] = 1
elif name == 'writer':
params['doWriters'] = 1
params['dataF'] = '%s%ss.data' % (self.__db, key)
data = getFilmography(**params)
movies = []
eps = []
# Split normal titles from episodes.
for d in data:
if d.get('kind') != 'episode':
movies.append(d)
else:
eps.append(d)
movies.sort()
if movies:
res[name] = movies
for e in eps:
series = Movie(data=e['episode of'], accessSystem='local')
seriesID = self._getTitleID(series.get(
'long imdb canonical title'))
series.movieID = seriesID
if not e.get('year'):
year = getFullIndex('%smovies.data' % self.__db,
e.movieID, kind='moviedata',
rindex=1)
if year: e['year'] = year
if not e.currentRole and name not in ('actor', 'actress'):
if e.notes: e.notes = ' %s' % e.notes
e.notes = '[%s]%s' % (name, e.notes)
episodes.setdefault(series, []).append(e)
if episodes:
for k in episodes:
episodes[k].sort()
episodes[k].reverse()
res['episodes'] = episodes
return {'data': res, 'info sets': tuple(infosets)}
get_person_biography = get_person_main
get_person_other_works = get_person_main
get_person_episodes = get_person_filmography
|