0
# Data Container Classes
1
2
Core classes for representing and manipulating IMDb data objects with dictionary-like access and specialized methods for movies, people, characters, and companies.
3
4
## Base Container Functionality
5
6
All IMDb data classes inherit from `_Container`, providing consistent dictionary-like access patterns and common functionality across all data types.
7
8
### Common Container Methods
9
10
All container classes (Movie, Person, Character, Company) share these methods:
11
12
```python { .api }
13
def keys():
14
"""Return list of available data keys."""
15
16
def values():
17
"""Return list of data values."""
18
19
def items():
20
"""Return list of (key, value) tuples."""
21
22
def get(key, default=None):
23
"""Get value for key with optional default."""
24
25
def __getitem__(key):
26
"""Dictionary-style access to data."""
27
28
def __setitem__(key, value):
29
"""Dictionary-style assignment of data."""
30
31
def __contains__(key):
32
"""Check if key exists in data."""
33
34
def summary():
35
"""Return formatted summary of the object."""
36
```
37
38
## Movie Class
39
40
Container for movie information with specialized movie-specific functionality.
41
42
```python { .api }
43
class Movie:
44
"""
45
Movie data container with dictionary-like access.
46
47
Attributes:
48
- movieID: str - Unique movie identifier
49
- accessSystem: str - Access system used to retrieve data
50
- myTitle: str - Personal title override
51
- default_info: tuple - Default information sets ('main', 'plot')
52
- keys_alias: dict - Mapping of alias keys to canonical keys
53
- current_info: list - Currently loaded information sets
54
"""
55
```
56
57
### Movie-Specific Methods
58
59
```python { .api }
60
def set_title(title):
61
"""
62
Set movie title.
63
64
Parameters:
65
- title: str - Movie title to set
66
"""
67
68
def getID():
69
"""
70
Return movie ID.
71
72
Returns:
73
str: Movie ID (movieID attribute)
74
"""
75
76
def isSameTitle(other):
77
"""
78
Compare titles with another movie.
79
80
Parameters:
81
- other: Movie - Another Movie object to compare
82
83
Returns:
84
bool: True if titles are considered the same
85
"""
86
87
def guessLanguage():
88
"""
89
Guess the language of the movie title.
90
91
Returns:
92
str: Detected language code
93
"""
94
95
def smartCanonicalTitle():
96
"""
97
Get canonical title representation.
98
99
Returns:
100
str: Canonical form of the movie title
101
"""
102
```
103
104
### Movie Data Structure
105
106
Movies contain extensive information organized by categories:
107
108
**Basic Information:**
109
- `'title'` - Movie title
110
- `'year'` - Release year
111
- `'kind'` - Type (movie, tv series, video game, etc.)
112
- `'rating'` - IMDb rating
113
- `'votes'` - Number of votes
114
- `'runtime'` - Duration information
115
116
**Cast and Crew:**
117
- `'cast'` - Main cast members
118
- `'director'` - Directors
119
- `'writer'` - Writers
120
- `'producer'` - Producers
121
- `'composer'` - Music composers
122
- `'cinematographer'` - Cinematographers
123
- `'editor'` - Film editors
124
125
**Content Information:**
126
- `'plot'` - Plot summaries
127
- `'genres'` - List of genres
128
- `'languages'` - Languages
129
- `'countries'` - Production countries
130
- `'color info'` - Color/black & white information
131
132
**Usage Example:**
133
134
```python
135
from imdb import IMDb
136
137
ia = IMDb()
138
139
# Create and populate movie object
140
movie = ia.get_movie('0133093', info=['main', 'plot', 'full_credits'])
141
142
# Dictionary-like access
143
print(f"Title: {movie['title']}")
144
print(f"Year: {movie['year']}")
145
print(f"Rating: {movie['rating']}")
146
147
# Specialized movie methods
148
print(f"Movie ID: {movie.getID()}")
149
canonical_title = movie.smartCanonicalTitle()
150
print(f"Canonical title: {canonical_title}")
151
152
# Check available information
153
print(f"Available keys: {list(movie.keys())}")
154
print(f"Current info sets: {movie.current_info}")
155
156
# Summary
157
print(movie.summary())
158
```
159
160
## Person Class
161
162
Container for person information with specialized person-specific functionality.
163
164
```python { .api }
165
class Person:
166
"""
167
Person data container with dictionary-like access.
168
169
Attributes:
170
- personID: str - Unique person identifier
171
- accessSystem: str - Access system used to retrieve data
172
- myName: str - Personal name override
173
- billingPos: int - Position in cast billing
174
- default_info: tuple - Default information sets ('main', 'filmography', 'biography')
175
- keys_alias: dict - Mapping of alias keys to canonical keys
176
- current_info: list - Currently loaded information sets
177
"""
178
```
179
180
### Person-Specific Methods
181
182
```python { .api }
183
def set_name(name):
184
"""
185
Set person name.
186
187
Parameters:
188
- name: str - Person name to set
189
"""
190
191
def getID():
192
"""
193
Return person ID.
194
195
Returns:
196
str: Person ID (personID attribute)
197
"""
198
199
def isSameName(other):
200
"""
201
Compare names with another person.
202
203
Parameters:
204
- other: Person - Another Person object to compare
205
206
Returns:
207
bool: True if names are considered the same
208
"""
209
```
210
211
### Person Data Structure
212
213
**Basic Information:**
214
- `'name'` - Person's name
215
- `'birth date'` - Birth date
216
- `'birth name'` - Birth name
217
- `'height'` - Height information
218
- `'nick names'` - Nicknames
219
220
**Biographical Information:**
221
- `'mini biography'` - Biography text
222
- `'birth info'` - Birth details
223
- `'death date'` - Death date (if applicable)
224
- `'spouse'` - Spouse information
225
226
**Career Information:**
227
- `'filmography'` - Complete filmography by role type
228
229
**Usage Example:**
230
231
```python
232
from imdb import IMDb
233
234
ia = IMDb()
235
236
# Create and populate person object
237
person = ia.get_person('0000158', info=['main', 'filmography', 'biography'])
238
239
# Dictionary-like access
240
print(f"Name: {person['name']}")
241
print(f"Birth date: {person.get('birth date', 'N/A')}")
242
243
# Specialized person methods
244
print(f"Person ID: {person.getID()}")
245
246
# Biography access
247
if 'mini biography' in person:
248
bio = person['mini biography'][0]
249
print(f"Biography: {bio[:100]}...")
250
251
# Filmography access
252
if 'filmography' in person:
253
for role_type, movies in person['filmography'].items():
254
print(f"{role_type}: {len(movies)} credits")
255
256
print(person.summary())
257
```
258
259
## Character Class
260
261
Container for character information with specialized character-specific functionality.
262
263
```python { .api }
264
class Character:
265
"""
266
Character data container with dictionary-like access.
267
268
Attributes:
269
- characterID: str - Unique character identifier (may be None)
270
- accessSystem: str - Access system used to retrieve data
271
- myName: str - Personal name override
272
- default_info: tuple - Default information sets ('main', 'filmography', 'biography')
273
- keys_alias: dict - Mapping of alias keys to canonical keys
274
- current_info: list - Currently loaded information sets
275
"""
276
```
277
278
### Character-Specific Methods
279
280
```python { .api }
281
def set_name(name):
282
"""
283
Set character name.
284
285
Parameters:
286
- name: str - Character name to set
287
"""
288
289
def getID():
290
"""
291
Return character ID.
292
293
Returns:
294
str: Character ID (characterID attribute) or None
295
"""
296
297
def isSameName(other):
298
"""
299
Compare names with another character.
300
301
Parameters:
302
- other: Character - Another Character object to compare
303
304
Returns:
305
bool: True if names are considered the same
306
"""
307
```
308
309
**Usage Example:**
310
311
```python
312
from imdb import IMDb
313
314
ia = IMDb()
315
316
# Create and populate character object
317
character = ia.get_character('0000196', info=['main', 'filmography'])
318
319
# Dictionary-like access
320
print(f"Character: {character['name']}")
321
322
# Character-specific methods
323
char_id = character.getID()
324
print(f"Character ID: {char_id}")
325
326
print(character.summary())
327
```
328
329
## Company Class
330
331
Container for company information with specialized company-specific functionality.
332
333
```python { .api }
334
class Company:
335
"""
336
Company data container with dictionary-like access.
337
338
Attributes:
339
- companyID: str - Unique company identifier
340
- accessSystem: str - Access system used to retrieve data
341
- myName: str - Personal name override
342
- default_info: tuple - Default information sets ('main',)
343
- keys_alias: dict - Mapping of alias keys to canonical keys
344
- current_info: list - Currently loaded information sets
345
"""
346
```
347
348
### Company-Specific Methods
349
350
```python { .api }
351
def set_name(name):
352
"""
353
Set company name.
354
355
Parameters:
356
- name: str - Company name to set
357
"""
358
359
def getID():
360
"""
361
Return company ID.
362
363
Returns:
364
str: Company ID (companyID attribute)
365
"""
366
367
def isSameName(other):
368
"""
369
Compare names with another company.
370
371
Parameters:
372
- other: Company - Another Company object to compare
373
374
Returns:
375
bool: True if names are considered the same
376
"""
377
```
378
379
**Usage Example:**
380
381
```python
382
from imdb import IMDb
383
384
ia = IMDb()
385
386
# Create and populate company object
387
company = ia.get_company('0022125', info=['main'])
388
389
# Dictionary-like access
390
print(f"Company: {company['name']}")
391
print(f"Country: {company.get('country', 'N/A')}")
392
393
# Company-specific methods
394
company_id = company.getID()
395
print(f"Company ID: {company_id}")
396
397
print(company.summary())
398
```
399
400
## Container Integration and Updates
401
402
All container objects work seamlessly with the update system:
403
404
```python
405
from imdb import IMDb
406
407
ia = IMDb()
408
409
# Get objects with minimal information
410
movie = ia.search_movie('Inception')[0]
411
person = ia.search_person('Leonardo DiCaprio')[0]
412
413
# Update with additional information
414
ia.update(movie, info=['plot', 'full_credits'])
415
ia.update(person, info=['filmography', 'biography'])
416
417
# Check what information is loaded
418
print(f"Movie info: {movie.current_info}")
419
print(f"Person info: {person.current_info}")
420
421
# Access updated information
422
print(f"Movie plot: {movie.get('plot', ['N/A'])[0]}")
423
print(f"Person filmography keys: {list(person.get('filmography', {}).keys())}")
424
```
425
426
## Key Aliases and Data Access
427
428
All container classes support key aliases for easier data access:
429
430
```python
431
from imdb import IMDb
432
433
ia = IMDb()
434
435
# Get person with biography
436
person = ia.get_person('0000158', info=['biography'])
437
438
# These are equivalent due to key aliases
439
bio1 = person.get('mini biography')
440
bio2 = person.get('biography') # Alias
441
bio3 = person.get('bio') # Alias
442
443
print(f"All equivalent: {bio1 == bio2 == bio3}")
444
445
# Movie aliases
446
movie = ia.get_movie('0133093', info=['main'])
447
rating1 = movie.get('rating')
448
rating2 = movie.get('user rating') # Alias
449
450
print(f"Rating aliases work: {rating1 == rating2}")
451
```