openTracker /library/imdb/imdb.class.php

Language PHP Lines 1914
MD5 Hash a93d36f2a5e9b7c81c1aa28dbca14722
Repository https://github.com/hegylako/openTracker.git View Raw File View Project SPDX
   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
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
<?php

#############################################################################
# IMDBPHP                              (c) Giorgos Giagas & Itzchak Rehberg #
# written by Giorgos Giagas                                                 #
# extended & maintained by Itzchak Rehberg <izzysoft AT qumran DOT org>     #
# http://www.izzysoft.de/                                                   #
# ------------------------------------------------------------------------- #
# This program is free software; you can redistribute and/or modify it      #
# under the terms of the GNU General Public License (see doc/LICENSE)       #
#############################################################################

/* $Id: imdb.class.php 473 2011-10-11 13:14:56Z izzy $ */

require_once (dirname(__FILE__) . "/movie_base.class.php");

#=============================================================================
#=================================================[ The IMDB class itself ]===
#=============================================================================
/** Accessing IMDB information
 * @package openTracker
 * @class imdb
 * @extends movie_base
 * @author Georgos Giagas
 * @author Izzy (izzysoft AT qumran DOT org)
 * @copyright (c) 2002-2004 by Giorgos Giagas and (c) 2004-2009 by Itzchak Rehberg and IzzySoft
 * @version $Revision: 473 $ $Date: 2011-10-11 15:14:56 +0200 (Di, 11. Okt 2011) $
 */

class imdb extends movie_base {
    #======================================================[ Common functions ]===
    #-----------------------------------------------------------[ Constructor ]---
    /** Initialize the class
     * @constructor imdb
     * @param string id IMDBID to use for data retrieval
     */

    function __construct($id) {
        parent::__construct($id);
        $this->revision = preg_replace('|^.*?(\d+).*$|', '$1', '$Revision: 473 $');
        $this->setid($id);
    }

    #-------------------------------------------------------------[ Open Page ]---
    /** Define page urls
     * @method protected set_pagename
     * @param string wt internal name of the page
     * @return string urlname page URL
     */

    protected function set_pagename($wt) {
        switch ($wt) {
            case "Title" : $urlname = "/";
                break;
            case "TitleFoot" : $urlname = "/_ajax/iframe?component=footer";
                break;
            case "Credits" : $urlname = "/fullcredits";
                break;
            case "CrazyCredits": $urlname = "/crazycredits";
                break;
            case "Plot" : $urlname = "/plotsummary";
                break;
            case "Synopsis" : $urlname = "/synopsis";
                break;
            case "Taglines" : $urlname = "/taglines";
                break;
            case "Episodes" : $urlname = "/episodes";
                break;
            case "Quotes" : $urlname = "/quotes";
                break;
            case "Trailers" : $urlname = "/trailers";
                break;
            case "VideoSites" : $urlname = "/videosites";
                break;
            case "Goofs" : $urlname = "/goofs";
                break;
            case "Trivia" : $urlname = "/trivia";
                break;
            case "Soundtrack" : $urlname = "/soundtrack";
                break;
            case "MovieConnections" : $urlname = "/movieconnections";
                break;
            case "ExtReviews" : $urlname = "/externalreviews";
                break;
            case "ReleaseInfo" : $urlname = "/releaseinfo";
                break;
            case "CompanyCredits" : $urlname = "/companycredits";
                break;
            case "ParentalGuide" : $urlname = "/parentalguide";
                break;
            case "OfficialSites" : $urlname = "/officialsites";
                break;
            case "Keywords" : $urlname = "/keywords";
                break;
            case "Awards" : $urlname = "/awards";
                break;
            case "Locations" : $urlname = "/locations";
                break;
            default :
                $this->page[$wt] = "unknown page identifier";
                $this->debug_scalar("Unknown page identifier: $wt");
                return false;
        }
        return $urlname;
    }

    #-----------------------------------------------[ URL to movies main page ]---
    /** Set up the URL to the movie title page
     * @method main_url
     * @return string url full URL to the current movies main page
     */

    public function main_url() {
        return "http://" . $this->imdbsite . "/title/tt" . $this->imdbid() . "/";
    }

    #======================================================[ Title page infos ]===
    #-------------------------------------------[ Movie title (name) and year ]---
    /** Setup title and year properties
     * @method private title_year
     */

    private function title_year() {
        if ($this->page["Title"] == "")
            $this->openpage("Title");
        if (@preg_match('!<title>(IMDb\s*-\s*)?(.*) \((.*)(\d{4}|\?{4}).*\)(.*)(\s*-\s*IMDb)?</title>!', $this->page["Title"], $match)) {
            $this->main_title = $match[2];
            if ($match[3] == "????")
                $this->main_year = "";
            else
                $this->main_year = $match[4];
        }
    }

    /** Get movie title
     * @method title
     * @return string title movie title (name)
     * @see IMDB page / (TitlePage)
     */
    public function title() {
        if ($this->main_title == "")
            $this->title_year();
        return $this->main_title;
    }

    /** Get year
     * @method year
     * @return string year
     * @see IMDB page / (TitlePage)
     */
    public function year() {
        if ($this->main_year == -1)
            $this->title_year();
        return $this->main_year;
    }

    /** Get range of years for e.g. series spanning multiple years
     * @method yearspan
     * @return array yearspan [start,end] (if there was no range, start==end)
     * @see IMDB page / (TitlePage)
     */
    function yearspan() {
        if (empty($this->main_yearspan)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match('!<title>.*?\(.*?(\d{4})(\&ndash;|-)(\d{4}|\?{4}).*?</title>!i', $this->page['Title'], $match)) {
                $this->main_yearspan = array('start' => $match[1], 'end' => $match[3]);
            } else {
                $this->main_yearspan = array('start' => $this->year(), 'end' => $this->year());
            }
        }
        return $this->main_yearspan;
    }

    /** Get movie types (if any specified)
     * @method movieTypes
     * @return array [0..n] of strings (or empty array if no movie types specified)
     * @see IMDB page / (TitlePage)
     */
    public function movieTypes() {
        if (empty($this->main_movietypes)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (@preg_match("/\<title\>(.*)\<\/title\>/", $this->page["Title"], $match)) {
                if (preg_match_all('|\(([^\)]*)\)|', $match[1], $matches)) {
                    for ($i = 0; $i < count($matches[0]); ++$i)
                        if (!preg_match('|^\d{4}$|', $matches[1][$i]))
                            $this->main_movietypes[] = $matches[1][$i];
                }
            }
        }
        return $this->main_movietypes;
    }

    #---------------------------------------------------------------[ Runtime ]---
    /** Get general runtime
     * @method private runtime_all
     * @return string runtime complete runtime string, e.g. "150 min / USA:153 min (director's cut)"
     */

    private function runtime_all() {
        if ($this->main_runtime == "") {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (@preg_match('!Runtime:</h4>\s*(.*)\s*</div!ms', $this->page["Title"], $match))
                $this->main_runtime = $match[1];
        }
        return $this->main_runtime;
    }

    /** Get overall runtime (first one mentioned on title page)
     * @method runtime
     * @return mixed string runtime in minutes (if set), NULL otherwise
     * @see IMDB page / (TitlePage)
     */
    public function runtime() {
        if (empty($this->movieruntimes))
            $runarr = $this->runtimes();
        else
            $runarr = $this->movieruntimes;
        if (isset($runarr[0]["time"]))
            return $runarr[0]["time"];
        return NULL;
    }

    /** Retrieve language specific runtimes
     * @method runtimes
     * @return array runtimes (array[0..n] of array[time,country,comment])
     * @see IMDB page / (TitlePage)
     */
    public function runtimes() {
        if (empty($this->movieruntimes)) {
            if (empty($this->main_runtime))
                $rt = $this->runtime_all();
            if (preg_match_all("/[\/ ]*((\D*?):|)([\d]+?) min( \((.*?)\)|)/", $this->main_runtime, $matches)) {
                for ($i = 0; $i < count($matches[0]); ++$i)
                    $this->movieruntimes[] = array("time" => $matches[3][$i], "country" => $matches[2][$i], "comment" => $matches[5][$i]);
            } elseif (preg_match('!<div class="infobar">.*?(\d+)\s*min!ims', $this->page['Title'], $match)) {
                $this->movieruntimes[] = array('time' => $match[1], 'country' => '', 'comment' => '');
            }
        }
        return $this->movieruntimes;
    }

    #----------------------------------------------------------[ Aspect Ratio ]---
    /** Aspect Ratio of movie screen
     * @method aspect_ratio
     * @return string ratio
     * @see IMDB page / (TitlePage)
     */

    public function aspect_ratio() {
        if (empty($this->aspectratio)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            preg_match('!<h4 class="inline">Aspect Ratio:</h4>\s*(.*?)\s</div>!ims', $this->page["Title"], $match);
            $this->aspectratio = $match[1];
        }
        return $this->aspectratio;
    }

    #----------------------------------------------------------[ Movie Rating ]---
    /** Setup votes
     * @method private rate_vote
     */

    private function rate_vote() {
        if ($this->page["Title"] == "")
            $this->openpage("Title");
        if (preg_match('!<span itemprop="ratingValue">(\d{1,2}\.\d)!i', $this->page["Title"], $match)) {
            $this->main_rating = $match[1];
        } else {
            $this->main_rating = 0;
        }
        if (preg_match('!href="ratings"\s+title="([\d\,]+)!i', $this->page["Title"], $match)) {
            $this->main_votes = $match[1];
        } else {
            $this->main_votes = 0;
        }
    }

    /** Get movie rating
     * @method rating
     * @return string rating current rating as given by IMDB site
     * @see IMDB page / (TitlePage)
     */
    public function rating() {
        if ($this->main_rating == -1)
            $this->rate_vote();
        return $this->main_rating;
    }

    /** Return votes for this movie
     * @method votes
     * @return string votes count of votes for this movie
     * @see IMDB page / (TitlePage)
     */
    public function votes() {
        if ($this->main_votes == -1)
            $this->rate_vote();
        return $this->main_votes;
    }

    #------------------------------------------------------[ Movie Comment(s) ]---
    /** Get movie main comment (from title page)
     * @method comment
     * @return string comment full text of movie comment from the movies main page
     * @see IMDB page / (TitlePage)
     */

    public function comment() {
        // this stuff whent into a frame in 2011! _ajax/iframe?component=footer
        if ($this->main_comment == "") {
            if ($this->page["TitleFoot"] == "")
                $this->openpage("TitleFoot");
            if (@preg_match('!<div class\="user-comments">\s*(.*?)\s*<div class\="yn"!ms', $this->page["TitleFoot"], $match))
                $this->main_comment = preg_replace("/a href\=\"\//i", "a href=\"http://" . $this->imdbsite . "/", $match[1]);
            $this->main_comment = str_replace("http://i.media-imdb.com/images/showtimes", $this->imdb_img_url . "/showtimes", $this->main_comment);
        }
        return $this->main_comment;
    }

    /** Get movie main comment (from title page - split-up variant)
     * @method comment_split
     * @return array comment array[string title, string date, array author, string comment]; author: array[string url, string name]
     * @see IMDB page / (TitlePage)
     */
    public function comment_split() {
        if (empty($this->split_comment)) {
            if ($this->main_comment == "")
                $comm = $this->comment();
            if (@preg_match('!<strong>(.*?)</strong>.*<div class="comment-meta">\s*(.*?)\s*\|\s*by\s*(.*?)\s*&ndash;.*?<p>(.*?)</div!ims', $this->main_comment, $match)) {
                @preg_match('!href="(.*?)">(.*)</a!i', $match[3], $author);
                $this->split_comment = array("title" => $match[1], "date" => $match[2], "author" => array("url" => $author[1], "name" => $author[2]), "comment" => trim($match[4]));
            } elseif (@preg_match('!<div class="comment-meta">\s*(.{10,20})\s*\|\s*by\s*(.*?)\s*&ndash;.*?<div>\s*(.*?)\s*</div>!ims', $this->main_comment, $match)) {
                @preg_match('!href="(.*?)">(.*)</a!i', $match[2], $author);
                $this->split_comment = array('title' => '', 'date' => $match[1], 'author' => array("url" => $author[1], "name" => $author[2]), "comment" => trim($match[3]));
            }
        }
        return $this->split_comment;
    }

    #--------------------------------------------------------------[ Keywords ]---
    /** Get the keywords for the movie
     * @method keywords
     * @return array keywords
     * @see IMDB page / (TitlePage)
     */

    public function keywords() {
        if (empty($this->main_keywords)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match_all('!<a href\="/keyword/[\w\-]+">(.*?)</a>!', $this->page["Title"], $matches))
                $this->main_keywords = $matches[1];
        }
        return $this->main_keywords;
    }

    #--------------------------------------------------------[ Language Stuff ]---
    /** Get movies original language
     * @method language
     * @return string language
     * @brief There is not really a main language on the IMDB sites (yet), so this
     *  simply returns the first one
     * @see IMDB page / (TitlePage)
     */

    public function language() {
        if ($this->main_language == "") {
            if (empty($this->langs))
                $this->langs = $this->languages();
            if (isset($this->langs[0]))
                $this->main_language = $this->langs[0];
        }
        return $this->main_language;
    }

    /** Get all languages this movie is available in
     * @method languages
     * @return array languages (array[0..n] of strings)
     * @see IMDB page / (TitlePage)
     */
    public function languages() {
        if (empty($this->langs)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match_all('!<a href="/language/(.*?)">\s*(.*?)\s*</a>(\s+\((.*?)\)|)!m', $this->page["Title"], $matches))
                $this->langs = $matches[2];
            $mc = count($matches[2]);
            for ($i = 0; $i < $mc; $i++) {
                $this->langs_full[] = array('name' => $matches[2][$i], 'code' => $matches[1][$i], 'comment' => $matches[4][$i]);
            }
        }
        return $this->langs;
    }

    /** Get all languages this movie is available in, including details
     * @method languages_detailed
     * @return array languages (array[0..n] of array[string name, string code, string comment], code being the ISO-Code)
     * @see IMDB page / (TitlePage)
     */
    public function languages_detailed() {
        if (empty($this->langs_full))
            $foo = $this->languages();
        return $this->langs_full;
    }

    #--------------------------------------------------------------[ Genre(s) ]---
    /** Get the movies main genre
     *  Since IMDB.COM does not really now a "Main Genre", this simply means the
     *  first mentioned genre will be returned.
     * @method genre
     * @return string genre first of the genres listed on the movies main page
     * @brief There is not really a main genre on the IMDB sites (yet), so this
     *  simply returns the first one
     * @see IMDB page / (TitlePage)
     */

    public function genre() {
        if (empty($this->main_genre)) {
            if (empty($this->moviegenres))
                $genres = $this->genres();
            if (!empty($genres))
                $this->main_genre = $this->moviegenres[0];
        }
        return $this->main_genre;
    }

    /** Get all genres the movie is registered for
     * @method genres
     * @return array genres (array[0..n] of strings)
     * @see IMDB page / (TitlePage)
     */
    public function genres() {
        if (empty($this->moviegenres)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match_all("@<a href\=\"/genre/[\w\-]+\"\>(.*?)\</a>@", $this->page["Title"], $matches)) {
                $this->moviegenres = $matches[1];
            } elseif (preg_match('!<div class="infobar">(.*?)</div>!ims', $this->page['Title'], $match)) {
                if (preg_match_all('!href="/genre/.*?"\s*>(.*?)<!ims', $match[1], $matches)) {
                    $this->moviegenres = $matches[1];
                }
            }
        }
        return $this->moviegenres;
    }

    #----------------------------------------------------------[ Color format ]---
    /** Get colors
     * @method colors
     * @return array colors (array[0..1] of strings)
     * @see IMDB page / (TitlePage)
     */

    public function colors() {
        if (empty($this->moviecolors)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match_all("|/search/title\?colors=.*?>\s*(.*?)<|", $this->page["Title"], $matches))
                $this->moviecolors = $matches[1];
        }
        return $this->moviecolors;
    }

    #---------------------------------------------------------------[ Creator ]---
    /** Get the creator of a movie (most likely for seasons only)
     * @method creator
     * @return array creator (array[0..n] of array[name,imdb])
     * @see IMDB page / (TitlePage)
     */

    public function creator() {
        if (empty($this->main_creator)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (@preg_match("/Creator:\<\/h5\>\s*\n(.*?)(<\/div|<a class=\"tn15more)/ms", $this->page["Title"], $match)) {
                if (preg_match_all('|/name/nm(\d{7}).*?>(.*?)<|ims', $match[1], $matches)) {
                    for ($i = 0; $i < count($matches[0]); ++$i)
                        $this->main_creator[] = array('name' => $matches[2][$i], 'imdb' => $matches[1][$i]);
                }
            }
        }
        return $this->main_creator;
    }

    #---------------------------------------------------------------[ Tagline ]---
    /** Get the main tagline for the movie
     * @method tagline
     * @return string tagline
     * @see IMDB page / (TitlePage)
     */

    public function tagline() {
        if ($this->main_tagline == "") {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (@preg_match('!Taglines:</h4>\s*(.*?)\s*<!ims', $this->page["Title"], $match)) {
                $this->main_tagline = trim($match[1]);
            }
        }
        return $this->main_tagline;
    }

    #---------------------------------------------------------------[ Seasons ]---
    /** Get the number of seasons or 0 if not a series
     * @method seasons
     * @return int seasons number of seasons
     * @see IMDB page / (TitlePage)
     */

    public function seasons() {
        if ($this->seasoncount == -1) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match_all('|<a href="episodes#season-\d+">(\d+)</a>|Ui', $this->page["Title"], $matches)) {
                $this->seasoncount = $matches[1][0];
            } else {
                $this->seasoncount = 0;
            }
            if (preg_match_all('|<a href="episodes#season-unknown">unknown</a>|Ui', $this->page["Title"], $matches)) {
                $this->seasoncount += count($matches[0]);
            }
        }
        return $this->seasoncount;
    }

    #-----------------------------------------------[ Is it part of a serial? ]---
    /** Try to figure out if this is a movie or part of a serie
     * @method is_serial
     * @return boolean
     * @see IMDB page / (TitlePage)
     */

    public function is_serial() {
        if ($this->page["Title"] == "")
            $this->openpage("Title");
        return preg_match('|<h5>TV Series:</h5>|i', $this->page["Title"], $matches);
    }

    #--------------------------------------------------------[ Plot (Outline) ]---
    /** Get the main Plot outline for the movie
     * @method plotoutline
     * @param optional boolean fallback Fallback to storyline if we could not catch plotoutline? Default: FALSE
     * @return string plotoutline
     * @see IMDB page / (TitlePage)
     */

    public function plotoutline($fallback = FALSE) {
        if ($this->main_plotoutline == "") {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match('!<span class="rating-rating">.*?(<p>.*?)\s*<div!ims', $this->page['Title'], $match)) {
                $this->main_plotoutline = trim($match[1]);
            } elseif (preg_match('!<p itemprop="description">\s*(.*?)\s*</p>!ims', $this->page['Title'], $match)) {
                $this->main_plotoutline = trim($match[1]);
            } elseif ($fallback) {
                $this->main_plotoutline = $this->storyline();
            }
            if (preg_match('!<p>\s*(<p>.*</p>)\s*$!ims', $this->main_plotoutline, $tmp))
                $this->main_plotoutline = $tmp[1];
        }
        return $this->main_plotoutline;
    }

    /** Get the Storyline for the movie
     * @method storyline
     * @return string storyline
     * @see IMDB page / (TitlePage)
     */
    public function storyline() {
        if ($this->main_storyline == "") {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (@preg_match('!Storyline</h2>\s*\n*<?p?>?(.*?)<?/?p?<h4!ims', $this->page["Title"], $match)) {
                if (preg_match('!(.*?)<em class="nobr">Written by!ims', $match[1], $det))
                    $this->main_storyline = $det[1];
                elseif (preg_match('!(.*)\s</p>!ims', $match[1], $det))
                    $this->main_storyline = $det[1];
                elseif (preg_match('!(.*)\s<span class="see-more inline">!ims', $match[1], $det))
                    $this->main_storyline = $det[1];
                elseif (preg_match('!(.*)\s\|!ims', $match[1], $det))
                    $this->main_storyline = $det[1];
                else
                    $this->main_storyine = trim($match[1]);
            }
        }
        return $this->main_storyline;
    }

    #--------------------------------------------------------[ Photo specific ]---
    /** Setup cover photo (thumbnail and big variant)
     * @method private thumbphoto
     * @return boolean success (TRUE if found, FALSE otherwise)
     * @see IMDB page / (TitlePage)
     */

    private function thumbphoto() {
        if ($this->page["Title"] == "")
            $this->openpage("Title");
        preg_match("!id\=\"img_primary\">[^<]*<a[^<]+<img src\=\"(.+?)\"!i", $this->page["Title"], $match);
        if (empty($match[1]))
            return FALSE;
        $this->main_thumb = $match[1];
        preg_match('|(.*\._V1).*|iUs', $match[1], $mo);
        $this->main_photo = $mo[1];
        return true;
    }

    /** Get cover photo
     * @method photo
     * @param optional boolean thumb get the thumbnail (100x140, default) or the
     *        bigger variant (400x600 - FALSE)
     * @return mixed photo (string url if found, FALSE otherwise)
     * @see IMDB page / (TitlePage)
     */
    public function photo($thumb = true) {
        if (empty($this->main_photo))
            $this->thumbphoto();
        if (!$thumb && empty($this->main_photo))
            return false;
        if ($thumb && empty($this->main_thumb))
            return false;
        if ($thumb)
            return $this->main_thumb;
        return $this->main_photo;
    }

    /** Save the photo to disk
     * @method savephoto
     * @param string path where to store the file
     * @param optional boolean thumb get the thumbnail (100x140, default) or the
     *        bigger variant (400x600 - FALSE)
     * @return boolean success
     * @see IMDB page / (TitlePage)
     */
    public function savephoto($path, $thumb = true, $rerun = 0) {
        switch ($rerun) {
            case 2: $req = new MDB_Request('');
                break;
            case 1: $req = new MDB_Request('', '', !$this->trigger_referer);
                break;
            default: $req = new MDB_Request('', '', $this->trigger_referer);
                break;
        }
        $photo_url = $this->photo($thumb);
        if (!$photo_url)
            return FALSE;
        $req->setURL($photo_url);
        $req->sendRequest();
        if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0
                || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0
                || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) {
            $fp = $req->getResponseBody();
        } else {
            switch ($rerun) {
                case 2 :
                    $ctype = $req->getResponseHeader("Content-Type");
                    $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '$ctype'<BR>");
                    if (substr($ctype, 0, 4) == 'text')
                        $this->debug_scalar("Details: <PRE>" . $req->getResponseBody() . "</PRE>\n");
                    return FALSE;
                    break;
                case 1 :
                    $this->debug_scalar("<BR>Initiate third run for savephoto($path) on IMDBID " . $this->imdbID . "<BR>");
                    unset($req);
                    return $this->savephoto($path, $thumb, 2);
                    break;
                default:
                    $this->debug_scalar("<BR>Initiate second run for savephoto($path) on IMDBID " . $this->imdbID . "<BR>");
                    unset($req);
                    return $this->savephoto($path, $thumb, 1);
                    break;
            }
        }
        $fp2 = fopen($path, "w");
        if ((!$fp) || (!$fp2)) {
            $this->debug_scalar("image error at " . __FILE__ . " line " . __LINE__ . "...<BR>");
            return false;
        }
        fputs($fp2, $fp);
        return TRUE;
    }

    /** Get the URL for the movies cover photo
     * @method photo_localurl
     * @param optional boolean thumb get the thumbnail (100x140, default) or the
     *        bigger variant (400x600 - FALSE)
     * @return mixed url (string URL or FALSE if none)
     * @see IMDB page / (TitlePage)
     */
    public function photo_localurl($thumb = true) {
        if ($thumb)
            $ext = ""; else
            $ext = "_big";
        if (!is_dir($this->photodir)) {
            $this->debug_scalar("<BR>***ERROR*** The configured image directory does not exist!<BR>");
            return false;
        }
        $path = PATH_ROOT . "/images/imdb/" . $this->imdbid() . "${ext}.jpg";
        if (file_exists($path))
            return $this->photoroot . $this->imdbid() . "${ext}.jpg";


        if (!is_writable($this->photodir)) {
            $this->debug_scalar("<BR>***ERROR*** The configured image directory lacks write permission!<BR>");
            return false;
        }
        if ($this->savephoto($path, $thumb))
            return $this->photoroot . $this->imdbid() . "${ext}.jpg";
        else
            echo "Could not save file";

        return false;
    }

    /** Get URLs for the pictures on the main page
     * @method mainPictures
     * @return array [0..n] of [imgsrc, imglink, bigsrc], where<UL>
     *    <LI>imgsrc is the URL of the thumbnail IMG as displayed on main page</LI>
     *    <LI>imglink is the link to the <b><i>page</i></b> with the "big image"</LI>
     *    <LI>bigsrc is the URL of the "big size" image itself</LI>
     * @author moonface
     * @author izzy
     */
    public function mainPictures() {
        if ($this->page["Title"] == "")
            $this->openpage("Title");
        if (empty($this->main_pictures)) {
            preg_match('!<div class="mediastrip">\s*(.*?)\s*</div>!ims', $this->page["Title"], $match);
            if (@preg_match_all('!<a .*?href="(.*?)".*?<img.*?src="(.*?)"!ims', $match[1], $matches)) {
                for ($i = 0; $i < count($matches[0]); ++$i) {
                    $this->main_pictures[$i]["imgsrc"] = $matches[2][$i];
                    if (substr($matches[1][$i], 0, 4) != "http")
                        $matches[1][$i] = "http://" . $this->imdbsite . $matches[1][$i];
                    $this->main_pictures[$i]["imglink"] = $matches[1][$i];
                    preg_match('|(.*\._V1).*|iUs', $matches[2][$i], $big);
                    $ext = substr($matches[2][$i], -3);
                    $this->main_pictures[$i]["bigsrc"] = $big[1] . ".${ext}";
                }
            }
        }
        return $this->main_pictures;
    }

    #-------------------------------------------------[ Country of Production ]---
    /** Get country of production
     * @method country
     * @return array country (array[0..n] of string)
     * @see IMDB page / (TitlePage)
     */

    public function country() {
        if (empty($this->countries)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            $this->countries = array();
#    if (preg_match_all("/\/country\/\w+\"\>(.*?)<\/a/m",$this->page["Title"],$matches))
            if (preg_match_all('!/country/\w+"\s*>(.*?)<\/a!m', $this->page["Title"], $matches))
                for ($i = 0; $i < count($matches[0]); ++$i)
                    $this->countries[$i] = $matches[1][$i];
        }
        return $this->countries;
    }

    #------------------------------------------------------------[ Movie AKAs ]---
    /** Get movies alternative names
     * @method alsoknow
     * @return array aka array[0..n] of array[title,year,country,comment]; searching
     *         on akas.imdb.com will add "lang" (2-char language code) to the array
     *         for localized names, "country" may hold multiple countries separated
     *         by commas
     * @see IMDB page ReleaseInfo
     * @version Due to changes on the IMDB sites, neither the languages nor the year
     *          seems to be available anymore - so those array properties will always
     *          be empty, and kept for compatibility only (for a while, at least).
     *          Moreover, content has been moved from the title page to ReleaseInfo page.
     */

    public function alsoknow() {
        if (empty($this->akas)) {
            if ($this->page["ReleaseInfo"] == "")
                $this->openpage("ReleaseInfo");
            $ak_s = strpos($this->page["ReleaseInfo"], "<a name=\"akas\">");
            //if ($ak_s == 0) $ak_s = strpos ($this->page["ReleaseInfo"], "Alternativ:");
            if ($ak_s == 0)
                return array();
            $alsoknow_end = strpos($this->page["ReleaseInfo"], "</table>", $ak_s);
            $alsoknow_all = substr($this->page["ReleaseInfo"], $ak_s, $alsoknow_end - $ak_s);
            preg_match_all("@<td>(.*?)</td>@i", $alsoknow_all, $matches);
            for ($i = 0; $i < count($matches[1]); $i+=2) {
                $title = trim($matches[1][$i]);
                $countries = explode('/', $matches[1][$i + 1]);
                foreach ($countries as $country) {
                    $firstbracket = strpos($country, '(');
                    if ($firstbracket === false) {
                        $_country = trim($country);
                        $comment = '';
                    } else {
                        $_country = trim(substr($country, 0, $firstbracket));
                        preg_match_all("@\((.+?)\)@", $country, $matches3);
                        $comment = implode(', ', $matches3[1]);
                    }
                    $this->akas[] = array(
                        "title" => $title,
                        "year" => '',
                        "country" => $_country,
                        "comment" => $comment,
                        "lang" => ''
                    );
                }
            }
        }
        return $this->akas;
    }

    #---------------------------------------------------------[ Sound formats ]---
    /** Get sound formats
     * @method sound
     * @return array sound (array[0..n] of strings)
     * @see IMDB page / (TitlePage)
     */

    public function sound() {
        if (empty($this->sound)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match_all("|/search/title\?sound_mixes=.*?>\s*(.*?)<|", $this->page["Title"], $matches))
                $this->sound = $matches[1];
        }
        return $this->sound;
    }

    #-------------------------------------------------------[ MPAA / PG / FSK ]---
    /** Get the MPAA data (also known as PG or FSK)
     * @method mpaa
     * @return array mpaa (array[country]=rating)
     * @see IMDB page / (TitlePage)
     */

    public function mpaa() {
        if (empty($this->mpaas)) {
            if ($this->page["ParentalGuide"] == "")
                $this->openpage("ParentalGuide");
            if (preg_match_all("|/search/title\?certificates=.*?>\s*(.*?):(.*?)<|", $this->page["ParentalGuide"], $matches)) {
                $cc = count($matches[0]);
                for ($i = 0; $i < $cc; ++$i)
                    $this->mpaas[$matches[1][$i]] = $matches[2][$i];
            }
        }
        return $this->mpaas;
    }

    /** Get the MPAA data (also known as PG or FSK) - including historical data
     * @method mpaa_hist
     * @return array mpaa (array[country][0..n]=rating)
     * @see IMDB page / (TitlePage)
     */
    public function mpaa_hist() {
        if (empty($this->mpaas_hist)) {
            if ($this->page["ParentalGuide"] == "")
                $this->openpage("ParentalGuide");
            if (preg_match_all("|/search/title\?certificates=.*?>\s*(.*?):(.*?)<|", $this->page["ParentalGuide"], $matches)) {
                $cc = count($matches[0]);
                for ($i = 0; $i < $cc; ++$i)
                    $this->mpaas_hist[$matches[1][$i]][] = $matches[2][$i];
            }
        }
        return $this->mpaas_hist;
    }

    #----------------------------------------------------[ MPAA justification ]---
    /** Find out the reason for the MPAA rating
     * @method mpaa_reason
     * @return string reason why the movie was rated such
     * @see IMDB page / (TitlePage)
     */

    public function mpaa_reason() {
        if (empty($this->mpaa_justification)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (preg_match('!href="/mpaa">.*?</h4>\s*<span itemprop="contentRating">(.*?)</span!ims', $this->page["Title"], $match))
                $this->mpaa_justification = trim($match[1]);
        }
        return $this->mpaa_justification;
    }

    #------------------------------------------------------[ Production Notes ]---
    /** For not-yet completed movies, we can get the production state
     * @method prodNotes
     * @return array production notes [status,statnote,lastupdate[day,month,mon,year],more,note]
     * @see IMDB page / (TitlePage)
     */

    public function prodNotes() {
        if (empty($this->main_prodnotes)) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (!preg_match('!(<h2>Production Notes.*?)\s*</div!ims', $this->page["Title"], $match))
                return $this->main_prodnotes; // no info available
            if (preg_match('!<b>Status:\s*</b>\s*(.*?)\s*<br!ims', $match[1], $tmp))
                if (preg_match('!(.*?)\s*<span class="ghost">\|</span>\s*(.*)!ims', $tmp[1], $tmp2)) {
                    $status = trim($tmp2[1]);
                    $statnote = trim($tmp2[2]);
                } else {
                    $status = trim($tmp);
                    $statnote = '';
                }
            if (preg_match('!<b>Updated:\s*</b>\s*(\d+)\s*(\D+)\s+(\d{4})!ims', $match[1], $tmp))
                $update = array("day" => $tmp[1], "month" => $tmp[2], "mon" => $this->monthNo($tmp[2]), "year" => $tmp[3]);
            if (preg_match('!<b>More Info:\s*</b>\s*(.*)!ims', $match[1], $tmp))
                $more = preg_replace('!\s*onclick=".*?"!ims', '', trim($tmp[1]));
            $more = preg_replace('!href="/!ims', 'href="http://' . $this->imdbsite . '/', $more);
            if (preg_match('!<b>Note:\s*</b>\s*(.*?)</!ims', $match[1], $tmp))
                $note = trim($tmp[1]);
            $this->main_prodnotes = array("status" => $status, "statnote" => $statnote, "lastUpdate" => $update, "more" => $more, "note" => $note);
        }
        return $this->main_prodnotes;
    }

    #----------------------------------------------[ Position in the "Top250" ]---
    /** Find the position of a movie in the top 250 ranked movies
     * @method top250
     * @return int position a number between 1..250 if the movie is listed, 0 otherwise
     * @author abe
     * @see http://projects.izzysoft.de/trac/imdbphp/ticket/117
     */

    public function top250() {
        if ($this->main_top250 == -1) {
            if ($this->page["Title"] == "")
                $this->openpage("Title");
            if (@preg_match('!<a href="[^"]*/chart/top\?tt(.*?)"><strong>Top 250 #(.*?)</a>!i', $this->page["Title"], $match)) {
                $this->main_top250 = $match[2];
            } else {
                $this->main_top250 = 0;
            }
        }
        return $this->main_top250;
    }

    #=====================================================[ /plotsummary page ]===
    #--------------------------------------------------[ Full Plot (combined) ]---
    /** Get the movies plot(s)
     * @method plot
     * @return array plot (array[0..n] of strings)
     * @see IMDB page /plotsummary
     */

    public function plot() {
        if (empty($this->plot_plot)) {
            if ($this->page["Plot"] == "")
                $this->openpage("Plot");
            if ($this->page["Plot"] == "cannot open page")
                return array(); // no such page
            if (preg_match_all("/p class=\"plotpar\">(.*?)<\/p>/", str_replace("\n", " ", $this->page["Plot"]), $matches))
                for ($i = 0; $i < count($matches[0]); ++$i)
                    $this->plot_plot[$i] = preg_replace('/<a href=\"\/SearchPlotWriters/i', '<a href="http://' . $this->imdbsite . '/SearchPlotWriters/', $matches[1][$i]);
        }
        return $this->plot_plot;
    }

    #-----------------------------------------------------[ Full Plot (split) ]---
    /** Get the movie plot(s) - split-up variant
     * @method plot_split
     * @return array array[0..n] of array[string plot,array author] - where author consists of string name and string url
     * @see IMDB page /plotsummary
     */

    public function plot_split() {
        if (empty($this->split_plot)) {
            if (empty($this->plot_plot))
                $plots = $this->plot();
            for ($i = 0; $i < count($this->plot_plot); ++$i) {
                if (preg_match("/(.*?)<i>.*<a href=\"(.*?)\">(.*?)<\/a>/", $this->plot_plot[$i], $match))
                    $this->split_plot[] = array("plot" => $match[1], "author" => array("name" => $match[3], "url" => $match[2]));
            }
        }
        return $this->split_plot;
    }

    #========================================================[ /synopsis page ]===
    #---------------------------------------------------------[ Full Synopsis ]---
    /** Get the movies synopsis
     * @method synopsis
     * @return string synopsis
     * @see IMDB page /synopsis
     */

    public function synopsis() {
        if (empty($this->synopsis_wiki)) {
            if ($this->page["Synopsis"] == "")
                $this->openpage("Synopsis");
            if ($this->page["Synopsis"] == "cannot open page")
                return $this->synopsis_wiki; // no such page
            if (preg_match('|<div id="swiki\.2\.1">(.*?)</div>|ims', $this->page["Synopsis"], $match))
                $this->synopsis_wiki = trim($match[1]);
        }
        return $this->synopsis_wiki;
    }

    #========================================================[ /taglines page ]===
    #--------------------------------------------------------[ Taglines Array ]---
    /** Get all available taglines for the movie
     * @method taglines
     * @return array taglines (array[0..n] of strings)
     * @see IMDB page /taglines
     */

    public function taglines() {
        if (empty($this->taglines)) {
            if ($this->page["Taglines"] == "")
                $this->openpage("Taglines");
            if ($this->page["Taglines"] == "cannot open page")
                return array(); // no such page
            if (preg_match_all("/<p>(.*?)<\/p><hr/", $this->page["Taglines"], $matches))
                $this->taglines = $matches[1];
        }
        return $this->taglines;
    }

    #=====================================================[ /fullcredits page ]===
    #-----------------------------------------------------[ Helper: TableRows ]---
    /** Get rows for a given table on the page
     * @method private get_table_rows
     * @param string html
     * @param string table_start
     * @return mixed rows (FALSE if table not found, array[0..n] of strings otherwise)
     * @see used by the methods director, cast, writing, producer, composer
     */

    private function get_table_rows($html, $table_start) {
        $row_s = strpos($html, ">" . $table_start . "<");
        $row_e = $row_s;
        if ($row_s == 0)
            return FALSE;
        $endtable = strpos($html, "</table>", $row_s);
        if (preg_match_all("/<tr>(.*?)<\/tr>/", substr($html, $row_s, $endtable - $row_s), $matches)) {
            $mc = count($matches[1]);
            for ($i = 0; $i < $mc; ++$i)
                if (strncmp(trim($matches[1][$i]), "<td valign=", 10) == 0)
                    $rows[] = $matches[1][$i];
        }
        return $rows;
    }

    #------------------------------------------------[ Helper: Cast TableRows ]---
    /** Get rows for the cast table on the page
     * @method private get_table_rows_cast
     * @param string html
     * @param string table_start
     * @return mixed rows (FALSE if table not found, array[0..n] of strings otherwise)
     * @see used by the method cast
     */

    private function get_table_rows_cast($html, $table_start, $class = "nm") {
        $row_s = strpos($html, '<table class="cast">');
        $row_e = $row_s;
        if ($row_s == 0)
            return FALSE;
        $endtable = strpos($html, "</table>", $row_s);
        if (preg_match_all("/<tr.*?(<td class=\"$class\".*?)<\/tr>/", substr($html, $row_s, $endtable - $row_s), $matches))
            return $matches[1];
        return array();
    }

    #------------------------------------------------[ Helper: Awards TableRows ]---
    /** Get rows for the awards table on the page
     * @method private get_table_rows_awards
     * @param string html
     * @param string table_start
     * @return mixed rows (FALSE if table not found, array[0..n] of strings otherwise)
     * @see used by the method awards
     * @author Qvist
     */

    private function get_table_rows_awards($html) {
        $row_s = strpos($html, '<table style="margin-top:');
        $row_e = $row_s;
        if ($row_s == 0)
            return FALSE;
        $endtable = strpos($html, "</table>", $row_s);
        $table_string = substr($html, $row_s, $endtable - $row_s);
        if (preg_match_all("/<tr>(.*?)<\/tr>/ims", $table_string, $matches)) {
            return $matches[1];
        }
        return $rows;
    }

    #------------------------------------------------------[ Helper: RowCells ]---
    /** Get content of table row cells
     * @method private get_row_cels
     * @param string row (as returned by imdb::get_table_rows)
     * @return array cells (array[0..n] of strings)
     * @see used by the methods director, cast, writing, producer, composer
     */

    private function get_row_cels($row) {
        if (preg_match_all("/<td.*?>(.*?)<\/td>/ims", $row, $matches))
            return $matches[1];
        return array();
    }

    #-------------------------------------------[ Helper: Get IMDBID from URL ]---
    /** Get the IMDB ID from a names URL
     * @method private get_imdbname
     * @param string href url to the staff members IMDB page
     * @return string IMDBID of the staff member
     * @see used by the methods director, cast, writing, producer, composer
     */

    private function get_imdbname($href) {
        if (strlen($href) == 0)
            return $href;
        $name_s = 17;
        $name_e = strpos($href, '"', $name_s);
        if ($name_e != 0)
            return substr($href, $name_s, $name_e - 1 - $name_s);
        else
            return $href;
    }

    #-------------------------------------------------------------[ Directors ]---
    /** Get the director(s) of the movie
     * @method director
     * @return array director (array[0..n] of arrays[imdb,name,role])
     * @see IMDB page /fullcredits
     */

    public function director() {
        if (empty($this->credits_director)) {
            if ($this->page["Credits"] == "")
                $this->openpage("Credits");
            if ($this->page["Credits"] == "cannot open page")
                return array(); // no such page
        }
        $director_rows = $this->get_table_rows($this->page["Credits"], "Directed by");
        if ($director_rows == null)
            $director_rows = $this->get_table_rows($this->page["Credits"], "Series Directed by");
        for ($i = 0; $i < count($director_rows); $i++) {
            $cels = $this->get_row_cels($director_rows[$i]);
            if (!isset($cels[0]))
                return array();
            $dir = array();
            $dir["imdb"] = $this->get_imdbname($cels[0]);
            $dir["name"] = strip_tags($cels[0]);
            $role = trim(strip_tags($cels[2]));
            if ($role == "")
                $dir["role"] = NULL;
            else
                $dir["role"] = $role;
            $this->credits_director[$i] = $dir;
        }
        return $this->credits_director;
    }

    #----------------------------------------------------------------[ Actors ]---
    /** Get the actors
     * @method cast
     * @return array cast (array[0..n] of arrays[imdb,name,role,thumb,photo])
     * @see IMDB page /fullcredits
     */

    public function cast() {
        if (empty($this->credits_cast)) {
            if ($this->page["Credits"] == "")
                $this->openpage("Credits");
            if ($this->page["Credits"] == "cannot open page")
                return array(); // no such page
        }
        $cast_rows = $this->get_table_rows_cast($this->page["Credits"], "Cast", "hs");
        for ($i = 0; $i < count($cast_rows); $i++) {
            $cels = $this->get_row_cels($cast_rows[$i]);
            if (!isset($cels[0]))
                return array();
            $dir = array();
            $dir["imdb"] = $this->get_imdbname($cels[1]);
            $dir["name"] = strip_tags($cels[1]);
            $role = strip_tags($cels[3]);
            if ($role == "")
                $dir["role"] = NULL;
            else
                $dir["role"] = $role;
            $dir["thumb"] = preg_replace('|.*<img src="(.*?)".*|is', '$1', $cels[0]);
            if (strpos($dir["thumb"], '._V1'))
                $dir["photo"] = preg_replace('|(.*._V1)\..+\.(.*)|is', '$1.$2', $dir["thumb"]);
            $this->credits_cast[$i] = $dir;
        }
        return $this->credits_cast;
    }

    #---------------------------------------------------------------[ Writers ]---
    /** Get the writer(s)
     * @method writing
     * @return array writers (array[0..n] of arrays[imdb,name,role])
     * @see IMDB page /fullcredits
     */

    public function writing() {
        if (empty($this->credits_writing)) {
            if ($this->page["Credits"] == "")
                $this->openpage("Credits");
            if ($this->page["Credits"] == "cannot open page")
                return array(); // no such page
        }
        $this->credits_writing = array();
        $writing_rows = $this->get_table_rows($this->page["Credits"], "Writing credits");
        for ($i = 0; $i < count($writing_rows); $i++) {
            $cels = $this->get_row_cels($writing_rows[$i]);
            if (count($cels) > 2) {
                $wrt = array();
                $wrt["imdb"] = $this->get_imdbname($cels[0]);
                $wrt["name"] = strip_tags($cels[0]);
                $role = strip_tags($cels[2]);
                if ($role == "")
                    $wrt["role"] = NULL;
                else
                    $wrt["role"] = $role;
                $this->credits_writing[$i] = $wrt;
            }
        }
        return $this->credits_writing;
    }

    #-------------------------------------------------------------[ Producers ]---
    /** Obtain the producer(s)
     * @method producer
     * @return array producer (array[0..n] of arrays[imdb,name,role])
     * @see IMDB page /fullcredits
     */

    public function producer() {
        if (empty($this->credits_producer)) {
            if ($this->page["Credits"] == "")
                $this->openpage("Credits");
            if ($this->page["Credits"] == "cannot open page")
                return array(); // no such page
        }
        $this->credits_producer = array();
        $producer_rows = $this->get_table_rows($this->page["Credits"], "Produced by");
        for ($i = 0; $i < count($producer_rows); $i++) {
            $cels = $this->get_row_cels($producer_rows[$i]);
            if (count($cels) > 2) {
                $wrt = array();
                $wrt["imdb"] = $this->get_imdbname($cels[0]);
                $wrt["name"] = strip_tags($cels[0]);
                $role = strip_tags($cels[2]);
                if ($role == "")
                    $wrt["role"] = NULL;
                else
                    $wrt["role"] = $role;
                $this->credits_producer[$i] = $wrt;
            }
        }
        return $this->credits_producer;
    }

    #-------------------------------------------------------------[ Composers ]---
    /** Obtain the composer(s) ("Original Music by...")
     * @method composer
     * @return array composer (array[0..n] of arrays[imdb,name,role])
     * @see IMDB page /fullcredits
     */

    public function composer() {
        if (empty($this->credits_composer)) {
            if ($this->page["Credits"] == "")
                $this->openpage("Credits");
            if ($this->page["Credits"] == "cannot open page")
                return array(); // no such page
        }
        $this->credits_composer = array();
        $composer_rows = $this->get_table_rows($this->page["Credits"], "Original Music by");
        for ($i = 0; $i < count($composer_rows); $i++) {
            $cels = $this->get_row_cels($composer_rows[$i]);
            if (count($cels) > 2) {
                $wrt = array();
                $wrt["imdb"] = $this->get_imdbname($cels[0]);
                $wrt["name"] = strip_tags($cels[0]);
                $role = strip_tags($cels[2]);
                if ($role == "")
                    $wrt["role"] = NULL;
                else
                    $wrt["role"] = $role;
                $this->credits_composer[$i] = $wrt;
            }
        }
        return $this->credits_composer;
    }

    #====================================================[ /crazycredits page ]===
    #----------------------------------------------------[ CrazyCredits Array ]---
    /** Get the Crazy Credits
     * @method crazy_credits
     * @return array crazy_credits (array[0..n] of string)
     * @see IMDB page /crazycredits
     */

    public function crazy_credits() {
        if (empty($this->crazy_credits)) {
            if (empty($this->page["CrazyCredits"]))
                $this->openpage("CrazyCredits");
            if ($this->page["CrazyCredits"] == "cannot open page")
                return array(); // no such page
            $tag_s = strpos($this->page["CrazyCredits"], "<li><tt>");
            $tag_e = strpos($this->page["CrazyCredits"], "</ul>", $tag_s);
            $cred = str_replace("<br>", " ", substr($this->page["CrazyCredits"], $tag_s, $tag_e - $tag_s));
            $cred = str_replace("  ", " ", str_replace("\n", " ", $cred));
            if (preg_match_all("/<li><tt>(.*?)<\/tt><\/li>/", $cred, $matches))
                $this->crazy_credits = $matches[1];
        }
        return $this->crazy_credits;
    }

    #========================================================[ /episodes page ]===
    #--------------------------------------------------------[ Episodes Array ]---
    /** Get the series episode(s)
     * @method episodes
     * @return array episodes (array[0..n] of array[0..m] of array[imdbid,title,airdate,plot,season,episode])
     * @see IMDB page /episodes
     */

    public function episodes() {
        if ($this->seasons() == 0)
            return $this->season_episodes;
        if (empty($this->season_episodes)) {
            if ($this->page["Episodes"] == "")
                $this->openpage("Episodes");
            if ($this->page["Episodes"] == "cannot open page")
                return array(); // no such page
            if (preg_match_all('!<h3>Season (\d+), Episode (\d+): <a href="/title/tt(\d{7})/">(.*)</a></h3><span.*>Original Air Date.*<strong>(.*)</strong></span><br>\s*(.*)(<h5>|</td>)!Ui', $this->page["Episodes"], $matches)) {
                for ($i = 0; $i < count($matches[0]); $i++) {
                    $this->season_episodes[$matches[1][$i]][] = array(
                        "imdbid" => $matches[3][$i], "title" => $matches[4][$i], "airdate" => $matches[5][$i],
                        "plot" => $matches[6][$i], "season" => $matches[1][$i], "episode" => $matches[2][$i]);
                }
            }
            if (preg_match_all('!<h3><a href="/title/tt(\d{7})/">(.*)</a></h3><span.*>Original Air Date.*<strong>(.*)</strong></span><br>\s*(.*)(<h5>|</td>)!Ui', $this->page["Episodes"], $matches)) {
                for ($i = 0; $i < count($matches[0]); $i++) {
                    $this->season_episodes[0][] = array(
                        "imdbid" => $matches[1][$i], "title" => $matches[2][$i], "airdate" => $matches[3][$i],
                        "plot" => $matches[4][$i], "season" => 0, "episode" => $i);
                }
            }
        }
        return $this->season_episodes;
    }

    #===========================================================[ /goofs page ]===
    #-----------------------------------------------------------[ Goofs Array ]---
    /** Get the goofs
     * @method goofs
     * @return array goofs (array[0..n] of array[type,content]
     * @see IMDB page /goofs
     */

    public function goofs() {
        if (empty($this->goofs)) {
            if (empty($this->page["Goofs"]))
                $this->openpage("Goofs");
            if ($this->page["Goofs"] == "cannot open page")
                return array(); // no such page
            $tag_s = strpos($this->page["Goofs"], '<ul class="trivia">');
            $tag_e = strrpos($this->page["Goofs"], '<ul class="trivia">'); // maybe more than one
            $tag_e = strrpos($this->page["Goofs"], "</ul>");
            $goofs = substr($this->page["Goofs"], $tag_s, $tag_e - $tag_s);
            if (preg_match_all("/<li>.*?<b>(.*?)<\/b>(.*?)<br>\s*(<br>)?<\/li>/ims", $goofs, $matches)) {
                $gc = count($matches[1]);
                for ($i = 0; $i < $gc; ++$i)
                    $this->goofs[] = array("type" => $matches[1][$i], "content" => $matches[2][$i]);
            }
        }
        return $this->goofs;
    }

    #==========================================================[ /quotes page ]===
    #----------------------------------------------------------[ Quotes Array ]---
    /** Get the quotes for a given movie
     * @method quotes
     * @return array quotes (array[0..n] of string)
     * @see IMDB page /quotes
     */

    public function quotes() {
        if (empty($this->moviequotes)) {
            if ($this->page["Quotes"] == "")
                $this->openpage("Quotes");
            if ($this->page["Quotes"] == "cannot open page")
                return array(); // no such page




                
// with this, we could even turn it into an array: url,name,quote
            if (preg_match_all('|<b><a href="(/name/.*?)">(.*?)</a>.*?:\s*?(.*?)<br|ims', str_replace("\n", " ", $this->page["Quotes"]), $matches))
                foreach ($matches[0] as $match) {
                    $this->moviequotes[] = str_replace('href="/name/', 'href="http://' . $this->imdbsite . '/name/', preg_replace('!<span class="linksoda".+?</span>!ims', '', $match));
                }
        }
        return $this->moviequotes;
    }

    #========================================================[ /trailers page ]===
    #--------------------------------------------------------[ Trailers Array ]---
    /** Get the trailer URLs for a given movie
     * @method trailers
     * @param optional boolean full Retrieve all available data (TRUE), or stay compatible with previous IMDBPHP versions (FALSE, Default)
     * @return mixed trailers either array[0..n] of string ($full=FALSE), or array[0..n] of array[lang,title,url,restful_url ($full=TRUE)
     * @see IMDB page /trailers
     */

    public function trailers($full = FALSE) {
        if (empty($this->trailers)) {
            if ($this->page["Trailers"] == "")
                $this->openpage("Trailers");
            if ($this->page["Trailers"] == "cannot open page")
                return array(); // no such page
            $tag_s = strpos($this->page["Trailers"], '<div id="search-results">');
            if (!empty($tag_s)) { // trailers on the IMDB site itself
                $tag_e = strpos($this->page["Trailers"], "</ol>", $tag_s);
                $trail = substr($this->page["Trailers"], $tag_s, $tag_e - $tag_s + 1);
                if (preg_match_all('|<a href="{0,1}(/video/screenplay/vi\d*/).*?title="(.*?)"|ims', $trail, $matches))
                    for ($i = 0; $i < count($matches[0]); ++$i) {
                        $trailer = "http://" . $this->imdbsite . $matches[1][$i];
                        if ($full)
                            $this->trailers[] = array("lang" => '', "title" => $matches[2][$i], "url" => $trailer, "restful_url" => '');
                        else
                            $this->trailers[] = $trailer;
                    }
            }
        }
        return $this->trailers;
    }

    #===========================================================[ /videosites ]===
    #------------------------------------------[ Off-site trailers and videos ]---
    /** Get the off-site videos and trailer URLs
     * @method videosites
     * @return array videosites array[0..n] of array(site,url,type,desc)
     * @see IMDB page /videosites
     */

    public function videosites() {
        if (empty($this->video_sites)) {
            if ($this->page["VideoSites"] == "")
                $this->openpage("VideoSites");
            if ($this->page["VideoSites"] == "cannot open page")
                return array(); // no such page
            if (preg_match('|<h3[^>]*>\s*Trailers on Other Sites\s*</h3>(.*?)<hr|ims', $this->page["VideoSites"], $match)) {
                preg_match_all('!<p[^>]*>(.*?)\s*\((.*?)\)\s*\(<a href="(.*?)">(.*?)</a>\)\s*</p!ims', $match[1], $matches);
                for ($i = 0; $i < count($matches[0]); ++$i) {
                    $this->video_sites[] = array("site" => $matches[4][$i], "url" => $matches[3][$i], "type" => $matches[2][$i], "desc" => $matches[1][$i]);
                }
            }
        }
        return $this->video_sites;
    }

    #==========================================================[ /trivia page ]===
    #----------------------------------------------------------[ Trivia Array ]---
    /** Get the trivia info
     * @method trivia
     * @return array trivia (array[0..n] string
     * @see IMDB page /trivia
     */

    public function trivia() {
        if (empty($this->trivia)) {
            if (empty($this->page["Trivia"]))
                $this->openpage("Trivia");
            if ($this->page["Trivia"] == "cannot open page")
                return array(); // no such page
            if (preg_match_all('!<div class="sodatext">\s*(.*?)\s</div>!ims', $this->page["Trivia"], $matches)) {
                $gc = count($matches[1]);
                for ($i = 0; $i < $gc; ++$i)
                    $this->trivia[] = str_replace('href="/', 'href="http://' . $this->imdbsite . "/", $matches[1][$i]);
            }
        }
        return $this->trivia;
    }

    #======================================================[ /soundtrack page ]===
    #------------------------------------------------------[ Soundtrack Array ]---
    /** Get the soundtrack listing
     * @method soundtrack
     * @return array soundtracks (array[0..n] of array(soundtrack,array[0..n] of credits)
     * @brief Usually, the credits array should hold [0] written by, [1] performed by.
     *  But IMDB does not always stick to that - so in many cases it holds
     *  [0] performed by, [1] courtesy of
     * @see IMDB page /soundtrack
     */

    public function soundtrack() {
        if (empty($this->soundtracks)) {
            if (empty($this->page["Soundtrack"]))
                $this->openpage("Soundtrack");
            if ($this->page["Soundtrack"] == "cannot open page")
                return array(); // no such page
            if (preg_match('|<p class="disclaimer">(.*?)</script|ims', $this->page["Soundtrack"], $match)) {
                if (preg_match_all("/<li>(.*?)<\/b><br>(.*?)<br>(.*?)<br>.*?<\/li>/", str_replace("\n", " ", $match[1]), $matches)) {
                    $mc = count($matches[0]);
                    for ($i = 0; $i < $mc; ++$i)
                        $this->soundtracks[] = array("soundtrack" => $matches[1][$i], "credits" => array(
                                str_replace('href="/', 'href="http://' . $this->imdbsite . '/', $matches[2][$i]),
                                str_replace('href="/', 'href="http://' . $this->imdbsite . '/', $matches[3][$i])));
                }
            }
        }
        return $this->soundtracks;
    }

    #=================================================[ /movieconnection page ]===
    #----------------------------------------[ Helper: ConnectionBlock Parser ]---
    /** Parse connection block (used by method movieconnection only)
     * @method private parseConnection
     * @param string conn connection type
     * @return array [0..n] of array mid,name,year,comment - or empty array if not found
     */

    private function parseConnection($conn) {
        $tag_s = strpos($this->page["MovieConnections"], "<h5>$conn</h5>");
        if (empty($tag_s))
            return array(); // no such feature
        $tag_e = strpos($this->page["MovieConnections"], "<h5>", $tag_s + 4);
        if (empty($tag_e))
            $tag_e = strpos($this->page["MovieConnections"], "<hr/><h3>", $tag_s);
        $block = substr($this->page["MovieConnections"], $tag_s, $tag_e - $tag_s);
        if (preg_match_all("/\<a href=\"(.*?)\"\>(.*?)\<\/a\> \((\d{4})\)(.*\<br\/\>\&nbsp;-\&nbsp;(.*))?/", $block, $matches)) {
            $mc = count($matches[0]);
            for ($i = 0; $i < $mc; ++$i) {
                $mid = substr($matches[1][$i], 9, strlen($matches[1][$i]) - 10); // isolate imdb id from url
                $arr[] = array("mid" => $mid, "name" => $matches[2][$i], "year" => $matches[3][$i], "comment" => $matches[5][$i]);
            }
        }
        return $arr;
    }

    #-------------------------------------------------[ MovieConnection Array ]---
    /** Get connected movie information
     * @method movieconnection
     * @return array connections (versionOf, editedInto, followedBy, spinOff,
     *         spinOffFrom, references, referenced, features, featured, spoofs,
     *         spoofed - each an array of mid, name, year, comment or an empty
     *         array if no connections of that type)
     * @see IMDB page /movieconnection
     */

    public function movieconnection() {
        if (empty($this->movieconnections)) {
            if (empty($this->page["MovieConnections"]))
                $this->openpage("MovieConnections");
            if ($this->page["MovieConnections"] == "cannot open page")
                return array(); // no such page
            $this->movieconnections["editedFrom"] = $this->parseConnection("Edited from");
            $this->movieconnections["editedInto"] = $this->parseConnection("Edited into");
            $this->movieconnections["featured"] = $this->parseConnection("Featured in");
            $this->movieconnections["features"] = $this->parseConnection("Features");
            $this->movieconnections["followedBy"] = $this->parseConnection("Followed by");
            $this->movieconnections["follows"] = $this->parseConnection("Follows");
            $this->movieconnections["references"] = $this->parseConnection("References");
            $this->movieconnections["referenced"] = $this->parseConnection("Referenced in");
            $this->movieconnections["remadeAs"] = $this->parseConnection("Remade as");
            $this->movieconnections["remakeOf"] = $this->parseConnection("Remake of");
            $this->movieconnections["spinOff"] = $this->parseConnection("Spin off");
            $this->movieconnections["spinOffFrom"] = $this->parseConnection("Spin off from");
            $this->movieconnections["spoofed"] = $this->parseConnection("Spoofed in");
            $this->movieconnections["spoofs"] = $this->parseConnection("Spoofs");
            $this->movieconnections["versionOf"] = $this->parseConnection("Version of");
        }
        return $this->movieconnections;
    }

    #=================================================[ /externalreviews page ]===
    #-------------------------------------------------[ ExternalReviews Array ]---
    /** Get list of external reviews (if any)
     * @method extReviews
     * @return array [0..n] of array [url, desc] (or empty array if no data)
     * @see IMDB page /externalreviews
     */

    public function extReviews() {
        if (empty($this->extreviews)) {
            if (empty($this->page["ExtReviews"]))
                $this->openpage("ExtReviews");
            if ($this->page["ExtReviews"] == "cannot open page")
                return array(); // no such page
            if (preg_match_all("/\<li\>\<a href=\"(.*?)\"\>(.*?)\<\/a\>/", $this->page["ExtReviews"], $matches)) {
                $mc = count($matches[0]);
                for ($i = 0; $i < $mc; ++$i) {
                    $this->extreviews[$i] = array("url" => $matches[1][$i], "desc" => $matches[2][$i]);
                }
            }
        }
        return $this->extreviews;
    }

    #=====================================================[ /releaseinfo page ]===
    #-----------------------------------------------------[ ReleaseInfo Array ]---
    /** Obtain Release Info (if any)
     * @method releaseInfo
     * @return array release_info array[0..n] of strings (country,day,month,mon,
      year,comment) - "month" is the month name, "mon" the number
     * @see IMDB page /releaseinfo
     */

    public function releaseInfo() {
        if (empty($this->release_info)) {
            if (empty($this->page["ReleaseInfo"]))
                $this->openpage("ReleaseInfo");
            if ($this->page["ReleaseInfo"] == "cannot open page")
                return array(); // no such page
            $tag_s = strpos($this->page["ReleaseInfo"], '<th class="xxxx">Country</th><th class="xxxx">Date</th>');
            $tag_e = strpos($this->page["ReleaseInfo"], '</table', $tag_s);
            $block = substr($this->page["ReleaseInfo"], $tag_s, $tag_e - $tag_s);
            preg_match_all('!<tr><td><b>(.*?)</b></td>\s*<td[^>]*>(.*?)</td>\s*<td>(.*?)</td>!ims', $block, $matches);
            $mc = count($matches[0]);
            for ($i = 0; $i < $mc; ++$i) {
                $country = strip_tags($matches[1][$i]);
                if (preg_match('!href="/date/(\d{2})-(\d{2})/">\d+ (.*?)</a>\s*<a href="/year/(\d{4})/">!is', $matches[2][$i], $match)) { // full info
                    $this->release_info[] = array('country' => $country, 'day' => $match[2], 'month' => $match[3], 'mon' => $match[1], 'year' => $match[4], 'comment' => $matches[3][$i]);
                } elseif (!preg_match('|a href=|i', $matches[2][$i], $match)) { // no links within
                    if (preg_match('!^(.+?)\s(\d{4})$!s', trim($matches[2][$i]), $match)) { // month and year
                        $this->release_info[] = array('country' => $country, 'day' => '', 'month' => $match[1], 'mon' => $this->monthNo(trim($match[1])), 'year' => $match[2], 'comment' => $matches[3][$i]);
                    } elseif (preg_match('!(\d{4})!', trim($matches[2][$i]), $match)) { // year at least
                        $this->release_info[] = array('country' => $country, 'day' => '', 'month' => '', 'mon' => '', 'year' => $match[1], 'comment' => $matches[3][$i]);
                    }
                } else {
                    $this->debug_scalar("NO MATCH ON<pre>" . htmlentities($matches[2][$i]) . "</pre>");
                }
            }
        }
        return $this->release_info;
    }

    #=======================================================[ /locations page ]===
    /** Obtain filming locations
     * @method locations
     * @return array locations array[0..n] of array[name,url] with name being the
     *               name of the location, and url a relative URL to list other
     *               movies sharing this location
     * @see IMDB page /locations
     */

    public function locations() {
        if (empty($this->locations)) {
            if (empty($this->page['Locations']))
                $this->openpage("Locations");
            if ($this->page['Locations'] == "cannot open page")
                return array(); // no such page
            $tag_s = strpos($this->page['Locations'], '<div id="tn15adrhs">');
            $tag_e = strpos($this->page['Locations'], '</dl>');
            $block = substr($this->page['Locations'], $tag_s, $tag_e - $tag_s);
            $block = substr($block, strpos($block, '<dl>'));
            if (preg_match_all('!<dt>(<a href="(.*?)">|)(.*?)(</a>|</dt>)!ims', $block, $matches)) {
                for ($i = 0; $i < count($matches[0]); ++$i)
                    $this->locations[] = array('name' => $matches[3][$i], 'url' => $matches[2][$i]);
            }
        }
        return $this->locations;
    }

    #==================================================[ /companycredits page ]===
    #---------------------------------------------[ Helper: Parse CompanyInfo ]---
    /** Parse company info
     * @method private companyParse
     * @param ref string text to parse
     * @param ref array parse target
     */

    public function companyParse(&$text, &$target) {
        preg_match_all('|<li><a href="(.*)">(.*)</a>(.*)</li>|iUms', $text, $matches);
        $mc = count($matches[0]);
        for ($i = 0; $i < $mc; ++$i) {
            $target[] = array("name" => $matches[2][$i], "url" => $matches[1][$i], "notes" => $matches[3][$i]);
        }
    }

    #---------------------------------------------------[ Producing Companies ]---
    /** Info about Production Companies
     * @method prodCompany
     * @return array [0..n] of array (name,url,notes)
     * @see IMDB page /companycredits
     */

    public function prodCompany() {
        if (empty($this->compcred_prod)) {
            if (empty($this->page["CompanyCredits"]))
                $this->openpage("CompanyCredits");
            if ($this->page["CompanyCredits"] == "cannot open page")
                return array(); // no such page
            if (preg_match('|<h2>Production Companies</h2><ul>(.*?)</ul>|ims', $this->page["CompanyCredits"], $match)) {
                $this->companyParse($match[1], $this->compcred_prod);
            }
        }
        return $this->compcred_prod;
    }

    #------------------------------------------------[ Distributing Companies ]---
    /** Info about distributors
     * @method distCompany
     * @return array [0..n] of array (name,url,notes)
     * @see IMDB page /companycredits
     */

    public function distCompany() {
        if (empty($this->compcred_dist)) {
            if (empty($this->page["CompanyCredits"]))
                $this->openpage("CompanyCredits");
            if ($this->page["CompanyCredits"] == "cannot open page")
                return array(); // no such page
            if (preg_match('|<h2>Distributors</h2><ul>(.*?)</ul>|ims', $this->page["CompanyCredits"], $match)) {
                $this->companyParse($match[1], $this->compcred_dist);
            }
        }
        return $this->compcred_dist;
    }

    #---------------------------------------------[ Special Effects Companies ]---
    /** Info about Special Effects companies
     * @method specialCompany
     * @return array [0..n] of array (name,url,notes)
     * @see IMDB page /companycredits
     */

    public function specialCompany() {
        if (empty($this->compcred_special)) {
            if (empty($this->page["CompanyCredits"]))
                $this->openpage("CompanyCredits");
            if ($this->page["CompanyCredits"] == "cannot open page")
                return array(); // no such page
            if (preg_match('|<h2>Special Effects</h2><ul>(.*?)</ul>|ims', $this->page["CompanyCredits"], $match)) {
                $this->companyParse($match[1], $this->compcred_special);
            }
        }
        return $this->compcred_special;
    }

    #-------------------------------------------------------[ Other Companies ]---
    /** Info about other companies
     * @method otherCompany
     * @return array [0..n] of array (name,url,notes)
     * @see IMDB page /companycredits
     */

    public function otherCompany() {
        if (empty($this->compcred_other)) {
            if (empty($this->page["CompanyCredits"]))
                $this->openpage("CompanyCredits");
            if ($this->page["CompanyCredits"] == "cannot open page")
                return array(); // no such page
            if (preg_match('|<h2>Other Companies</h2><ul>(.*?)</ul>|ims', $this->page["CompanyCredits"], $match)) {
                $this->companyParse($match[1], $this->compcred_other);
            }
        }
        return $this->compcred_other;
    }

    #===================================================[ /parentalguide page ]===
    #-------------------------------------------------[ ParentalGuide Details ]---
    /** Detailed Parental Guide
     * @method parentalGuide
     * @return array of strings; keys: Alcohol, Sex, Violence, Profanity,
     *         Frightening - and maybe more; values: arguments for the rating
     * @see IMDB page /parentalguide
     */

    public function parentalGuide() {
        if (empty($this->parental_guide)) {
            if (empty($this->page["ParentalGuide"]))
                $this->openpage("ParentalGuide");
            if ($this->page["ParentalGuide"] == "cannot open page")
                return array(); // no such page
            if (preg_match_all('/<div class="section">(.*)<div id="swiki(\.\d+\.\d+|_last)">/iUms', $this->page["ParentalGuide"], $matches)) {
                $mc = count($matches[0]);
                for ($i = 0; $i < $mc; ++$i) {
                    if (!preg_match('|<span>(.*)</span>|iUms', $matches[1][$i], $match))
                        continue;
                    $section = $match[1];
                    preg_match('|<p id="swiki\.\d+\.\d+\.\d+">(.*)</p>|iUms', $matches[1][$i], $match);
                    $content = trim($match[1]);
                    preg_match('/^(.*)(\s|\/)/U', $section, $match);
                    $sgot = $match[1];
                    if (empty($sgot))
                        $sgot = $section;
                    switch ($sgot) {
                        case "Alcohol" : $this->parental_guide["Drugs"] = trim($content);
                            break;
                        case "Sex" :
                        case "Violence" :
                        case "Profanity" :
                        case "Frightening":
                        default : $this->parental_guide[$sgot] = trim($content);
                            break;
                    }
                }
            }
        }
        return $this->parental_guide;
    }

    #===================================================[ /officialsites page ]===
    #---------------------------------------------------[ Official Sites URLs ]---
    /** URLs of Official Sites
     * @method officialSites
     * @return array [0..n] of url, name
     * @see IMDB page /officialsites
     */

    public function officialSites() {
        if (empty($this->official_sites)) {
            if (empty($this->page["OfficialSites"]))
                $this->openpage("OfficialSites");
            if ($this->page["OfficialSites"] == "cannot open page")
                return array(); // no such page
            preg_match('|official sites for(.*?)related links|ims', $this->page["OfficialSites"], $match);
            if (preg_match_all('|<li><a href="(.*?)">(.*?)</a></li>|ims', $match[1], $matches)) {
                $mc = count($matches[0]);
                for ($i = 0; $i < $mc; ++$i) {
                    $this->official_sites[] = array("url" => $matches[1][$i], "name" => $matches[2][$i]);
                }
            }
        }
        return $this->official_sites;
    }

    #========================================================[ /keywords page ]===
    #--------------------------------------------------------------[ Keywords ]---
    /** Get the complete keywords for the movie
     * @method keywords_all
     * @return array keywords
     * @see IMDB page /keywords
     */

    function keywords_all() {
        if (empty($this->all_keywords)) {
            if ($this->page["Keywords"] == "")
                $this->openpage("Keywords");
            if (preg_match_all('|<li><b class="keyword">\s*<a href\="/keyword\/[\w\-]+/">(.*?)</a>|', $this->page["Keywords"], $matches))
                $this->all_keywords = $matches[1];
        }
        return $this->all_keywords;
    }

    #========================================================[ /awards page ]===
    #--------------------------------------------------------------[ Awards ]---
    /** Get the complete awards for the movie
     * @method awards
     * @return array awards array[festivalName]['entries'][0..n] of array[year,won,category,award,people,comment]
     * @see IMDB page /awards
     * @author Qvist
     * @brief array[festivalName] is array[name,entries] - where name is a string,
     *        and entries is above described array
     */

    public function awards() {
        if (empty($this->awards)) {
            if ($this->page["Awards"] == "")
                $this->openpage("Awards");
            $award_rows = $this->get_table_rows_awards($this->page["Awards"]);
            $rowcount = count($award_rows);
            $festival = "";
            $year = 0;
            $won = false;
            $award = "";
            $comment = "";
            $people = array();
            $nr = 0;
            for ($i = 0; $i < $rowcount; $i++) {
                $cels = $this->get_row_cels($award_rows[$i]);
                if (count($cels) == 0) {
                    continue;
                }
                if (count($cels) == 1 && preg_match('|<big><a href\="/Sections/Awards/([^\/]+)/">(.*?)</a></big>|s', $cels[0], $matches)) {
                    $festival = $matches[1];
                    $this->awards[$festival]['name'] = $matches[2];
                    $nr = 0;
                }
                if (count($cels) == 4 && preg_match('|<a href\="/Sections/Awards/' . quotemeta($festival) . '/[\d-]+">(\d{4}) </a>|s', $cels[0], $matches)) {
                    $year = $matches[1];
                    array_shift($cels);
                }
                if (count($cels) == 3 && preg_match('|<b>(.*?)</b>|s', $cels[0], $matches)) {
                    $won = ($matches[1] == "Won") ? true : false;
                    array_shift($cels);
                }
                if (count($cels) == 2 && strpos($cels[0], "<") === false) {
                    $award = $cels[0];
                    array_shift($cels);
                }
                if (count($cels) == 1 && preg_match('|([^<>]*)<br>(.*)<small>|s', $cels[0], $matches)) {
                    $category = trim($matches[1]);
                    preg_match_all('|<a href\="/name/nm(\d{7})/">(.*?)</a>|s', $cels[0], $matches);
                    $people = isset($matches[0][0]) ? array_combine($matches[1], $matches[2]) : array();
                    preg_match('|<small>(.*?)</small>|s', $cels[0], $matches);
                    $comment = isset($matches[1]) ? strip_tags($matches[1]) : '';
                    array_shift($cels);
                    $nr++;
                }
                if (count($cels) == 0) {
                    $this->awards[$festival]['entries'][$nr] = array(
                        'year' => $year, 'won' => $won, 'category' => $category, 'award' => $award, 'people' => $people, 'comment' => $comment);
                }
            }
        }
        return $this->awards;
    }

}

// end class imdb
?>
Back to Top