or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-features.mdcharacter-company-operations.mdconfig-utilities.mdcore-access.mddata-containers.mdindex.mdmovie-operations.mdperson-operations.md

config-utilities.mddocs/

0

# Configuration and Utilities

1

2

Configuration management, utility functions, and helper methods for customizing behavior and processing IMDb data with advanced text processing and data manipulation capabilities.

3

4

## Configuration Management

5

6

### Configuration Parser

7

8

Case-sensitive configuration parser for managing IMDb settings and preferences.

9

10

```python { .api }

11

class ConfigParserWithCase:

12

"""

13

Case-sensitive configuration parser for IMDb settings.

14

15

Inherits from configparser.ConfigParser but preserves key case sensitivity

16

and provides enhanced value processing.

17

"""

18

19

def __init__(defaults=None, confFile=None, *args, **kwds):

20

"""

21

Initialize the configuration parser.

22

23

Parameters:

24

- defaults: dict, optional - Default configuration values

25

- confFile: str/list, optional - Configuration file(s) to parse

26

"""

27

28

def get(section, option, *args, **kwds):

29

"""

30

Get configuration value with automatic type conversion.

31

32

Parameters:

33

- section: str - Configuration section name

34

- option: str - Option name (case-sensitive)

35

36

Returns:

37

Value with appropriate type (bool, int, str, None)

38

"""

39

40

def getDict(section):

41

"""

42

Get entire configuration section as dictionary.

43

44

Parameters:

45

- section: str - Section name

46

47

Returns:

48

dict: Section contents as key-value pairs

49

"""

50

51

def items(section, *args, **kwds):

52

"""

53

Get section items as list of tuples.

54

55

Parameters:

56

- section: str - Section name

57

58

Returns:

59

list: List of (key, value) tuples

60

"""

61

```

62

63

**Usage Example:**

64

65

```python

66

from imdb import ConfigParserWithCase

67

68

# Create configuration parser

69

config = ConfigParserWithCase()

70

71

# Manually set configuration

72

config.read_string("""

73

[imdbpy]

74

accessSystem = http

75

results = 30

76

reraiseExceptions = true

77

customOption = MyValue

78

""")

79

80

# Access configuration values

81

access_system = config.get('imdbpy', 'accessSystem')

82

results = config.get('imdbpy', 'results') # Automatically converted to int

83

reraise = config.get('imdbpy', 'reraiseExceptions') # Automatically converted to bool

84

85

print(f"Access System: {access_system}")

86

print(f"Results: {results} (type: {type(results)})")

87

print(f"Reraise: {reraise} (type: {type(reraise)})")

88

89

# Get section as dictionary

90

imdb_config = config.getDict('imdbpy')

91

print(f"Full config: {imdb_config}")

92

```

93

94

## Text Processing Utilities

95

96

### Name Processing

97

98

Comprehensive name processing and formatting utilities.

99

100

```python { .api }

101

def canonicalName(name):

102

"""

103

Convert person name to canonical format.

104

105

Parameters:

106

- name: str - Person name to convert

107

108

Returns:

109

str: Canonical form of the name

110

"""

111

112

def analyze_name(name, canonical=None):

113

"""

114

Parse person name into components.

115

116

Parameters:

117

- name: str - Name to analyze

118

- canonical: bool, optional - Whether to use canonical format

119

120

Returns:

121

dict: Name components (name, imdbIndex, etc.)

122

"""

123

124

def build_name(name_dict, canonical=None):

125

"""

126

Build formatted name from components.

127

128

Parameters:

129

- name_dict: dict - Name components dictionary

130

- canonical: bool, optional - Whether to use canonical format

131

132

Returns:

133

str: Formatted name string

134

"""

135

136

def normalizeName(name):

137

"""

138

Normalize name format for consistent processing.

139

140

Parameters:

141

- name: str - Name to normalize

142

143

Returns:

144

str: Normalized name

145

"""

146

```

147

148

### Title Processing

149

150

Movie title processing and formatting utilities.

151

152

```python { .api }

153

def canonicalTitle(title, lang=None, imdbIndex=None):

154

"""

155

Convert movie title to canonical format.

156

157

Parameters:

158

- title: str - Movie title to convert

159

- lang: str, optional - Language code

160

- imdbIndex: str, optional - IMDb index for disambiguation

161

162

Returns:

163

str: Canonical form of the title

164

"""

165

166

def analyze_title(title, canonical=None):

167

"""

168

Parse movie title into components.

169

170

Parameters:

171

- title: str - Title to analyze

172

- canonical: bool, optional - Whether to use canonical format

173

174

Returns:

175

dict: Title components (title, year, kind, imdbIndex, etc.)

176

"""

177

178

def build_title(title_dict, canonical=None, ptdf=0, appendKind=True):

179

"""

180

Build formatted title from components.

181

182

Parameters:

183

- title_dict: dict - Title components dictionary

184

- canonical: bool, optional - Whether to use canonical format

185

- ptdf: int - Plain Text Data File format flag

186

- appendKind: bool - Whether to append kind information

187

188

Returns:

189

str: Formatted title string

190

"""

191

```

192

193

### Company Name Processing

194

195

Company name processing utilities.

196

197

```python { .api }

198

def analyze_company_name(name, stripNotes=True):

199

"""

200

Parse company name into components.

201

202

Parameters:

203

- name: str - Company name to analyze

204

- stripNotes: bool - Whether to strip notes from name

205

206

Returns:

207

dict: Company name components

208

"""

209

210

def build_company_name(name_dict):

211

"""

212

Build formatted company name from components.

213

214

Parameters:

215

- name_dict: dict - Company name components dictionary

216

217

Returns:

218

str: Formatted company name

219

"""

220

221

def split_company_name_notes(name):

222

"""

223

Split company name and notes.

224

225

Parameters:

226

- name: str - Company name with potential notes

227

228

Returns:

229

tuple: (name, notes) tuple

230

"""

231

```

232

233

**Usage Example:**

234

235

```python

236

from imdb.utils import canonicalName, canonicalTitle, analyze_name, build_title

237

238

# Name processing

239

name = "Downey Jr., Robert"

240

canonical = canonicalName(name)

241

print(f"Canonical name: {canonical}")

242

243

# Name analysis

244

name_parts = analyze_name("Robert Downey Jr.")

245

print(f"Name parts: {name_parts}")

246

247

# Title processing

248

title = "The Matrix (1999)"

249

canonical_title = canonicalTitle(title)

250

print(f"Canonical title: {canonical_title}")

251

252

# Title building

253

title_dict = {'title': 'The Matrix', 'year': '1999', 'kind': 'movie'}

254

formatted_title = build_title(title_dict)

255

print(f"Built title: {formatted_title}")

256

```

257

258

## Data Processing Utilities

259

260

### Object Comparison

261

262

Comparison functions for IMDb objects.

263

264

```python { .api }

265

def cmpMovies(m1, m2):

266

"""

267

Compare two Movie objects.

268

269

Parameters:

270

- m1: Movie - First movie

271

- m2: Movie - Second movie

272

273

Returns:

274

int: Comparison result (-1, 0, 1)

275

"""

276

277

def cmpPeople(p1, p2):

278

"""

279

Compare two Person objects.

280

281

Parameters:

282

- p1: Person - First person

283

- p2: Person - Second person

284

285

Returns:

286

int: Comparison result (-1, 0, 1)

287

"""

288

289

def cmpCompanies(c1, c2):

290

"""

291

Compare two Company objects.

292

293

Parameters:

294

- c1: Company - First company

295

- c2: Company - Second company

296

297

Returns:

298

int: Comparison result (-1, 0, 1)

299

"""

300

```

301

302

### Data Structure Processing

303

304

Advanced data structure manipulation utilities.

305

306

```python { .api }

307

def flatten(seq, toDescend=None, yieldDictKeys=False, scalar=None):

308

"""

309

Flatten nested data structures.

310

311

Parameters:

312

- seq: Sequence to flatten

313

- toDescend: Types to descend into

314

- yieldDictKeys: bool - Whether to yield dictionary keys

315

- scalar: Scalar types to treat as terminal

316

317

Returns:

318

Generator yielding flattened elements

319

"""

320

321

def modifyStrings(obj, modFunct, titlesRefs, namesRefs, charactersRefs):

322

"""

323

Modify string references in objects.

324

325

Parameters:

326

- obj: Object to modify

327

- modFunct: Function to apply to strings

328

- titlesRefs: Title references dictionary

329

- namesRefs: Name references dictionary

330

- charactersRefs: Character references dictionary

331

332

Returns:

333

Modified object

334

"""

335

```

336

337

**Usage Example:**

338

339

```python

340

from imdb.utils import cmpMovies, flatten

341

342

# Compare movies

343

from imdb import IMDb

344

ia = IMDb()

345

346

movie1 = ia.search_movie('The Matrix')[0]

347

movie2 = ia.search_movie('The Matrix Reloaded')[0]

348

349

comparison = cmpMovies(movie1, movie2)

350

print(f"Movie comparison result: {comparison}")

351

352

# Flatten nested data

353

nested_data = [1, [2, 3], {'a': 4, 'b': [5, 6]}]

354

flattened = list(flatten(nested_data))

355

print(f"Flattened: {flattened}")

356

```

357

358

## Helper Functions and Utilities

359

360

### Container Base Class

361

362

Base class providing dictionary-like functionality for all IMDb objects.

363

364

```python { .api }

365

class _Container:

366

"""

367

Base container class with dictionary-like interface.

368

369

Provides common functionality for Movie, Person, Character, and Company classes

370

including data access, modification functions, and reference management.

371

"""

372

373

def keys():

374

"""Return list of available data keys."""

375

376

def values():

377

"""Return list of data values."""

378

379

def items():

380

"""Return list of (key, value) tuples."""

381

382

def get(key, default=None):

383

"""Get value for key with optional default."""

384

385

def set_mod_funct(modFunct):

386

"""Set string modification function."""

387

388

def clear_mod_funct():

389

"""Clear string modification function."""

390

391

def set_data(data, override=0):

392

"""Set object data."""

393

394

def add_to_current_info(info, keys=None, mainInfoset=None):

395

"""Add information set to current info tracking."""

396

```

397

398

### Linguistics and Language Processing

399

400

Language detection and processing utilities from the linguistics module.

401

402

```python { .api }

403

def guessLanguage(text):

404

"""

405

Guess the language of text.

406

407

Parameters:

408

- text: str - Text to analyze

409

410

Returns:

411

str: Detected language code

412

"""

413

```

414

415

**Usage Example:**

416

417

```python

418

from imdb.linguistics import guessLanguage

419

420

# Language detection

421

title1 = "Le Fabuleux Destin d'Amélie Poulain"

422

title2 = "Crouching Tiger, Hidden Dragon"

423

424

lang1 = guessLanguage(title1)

425

lang2 = guessLanguage(title2)

426

427

print(f"'{title1}' detected as: {lang1}")

428

print(f"'{title2}' detected as: {lang2}")

429

```

430

431

## CLI and Command-Line Utilities

432

433

### Command-Line Interface

434

435

Main CLI functionality accessible through the installed console script.

436

437

```python { .api }

438

def main():

439

"""

440

Main entry point for imdbpy command-line interface.

441

442

Provides interactive and command-line access to IMDb functionality

443

including search, retrieval, and data display operations.

444

"""

445

```

446

447

**Usage from Command Line:**

448

449

```bash

450

# Search for movies

451

imdbpy search movie "The Matrix"

452

453

# Get movie information

454

imdbpy get movie 0133093

455

456

# Search for people

457

imdbpy search person "Keanu Reeves"

458

459

# Get person information

460

imdbpy get person 0000206

461

462

# Get top charts

463

imdbpy top movies

464

imdbpy bottom movies

465

```

466

467

## Advanced Configuration

468

469

### Logging Configuration

470

471

Configure detailed logging for debugging and monitoring.

472

473

```python

474

import logging

475

from imdb import IMDb

476

477

# Configure logging level

478

logging.basicConfig(level=logging.DEBUG)

479

480

# Create IMDb instance with logging

481

ia = IMDb(loggingLevel=logging.DEBUG)

482

483

# Operations will now produce detailed logs

484

movies = ia.search_movie('The Matrix')

485

```

486

487

### Custom URL Configuration

488

489

Configure custom IMDb URLs for specialized environments.

490

491

```python

492

from imdb import IMDb

493

494

# Create instance with custom base URL

495

ia = IMDb(imdbURL_base='https://pro.imdb.com/')

496

497

# Set URLs after creation

498

ia.set_imdb_urls('https://www.imdb.com/')

499

500

# Access configured URL patterns

501

print(f"Base URL: {ia.urls['movie_base']}")

502

print(f"Movie URL pattern: {ia.urls['movie_main']}")

503

```

504

505

### Performance Configuration

506

507

Configure performance-related settings.

508

509

```python

510

from imdb import IMDb

511

512

# Configure result limits and performance settings

513

ia = IMDb(

514

results=50, # Default search results

515

keywordsResults=200, # Default keyword results

516

reraiseExceptions=False # Handle exceptions gracefully

517

)

518

519

# These settings affect all operations

520

movies = ia.search_movie('Matrix') # Returns up to 50 results

521

keywords = ia.search_keyword('action') # Returns up to 200 results

522

```