1 | #!/usr/bin/php |
---|
2 | <?php |
---|
3 | |
---|
4 | /** |
---|
5 | * OFDB Onlinefilmdatenbank MythVideo Script |
---|
6 | * Written in January 2008 by Christian Gdel <cg at dmesg dot ch> |
---|
7 | */ |
---|
8 | |
---|
9 | include('HTTP/Request.php'); |
---|
10 | define('OFDB_URL', 'http://www.ofdb.de/'); |
---|
11 | |
---|
12 | /* parse the arguments */ |
---|
13 | switch ($argv[1]) { |
---|
14 | case "-M": |
---|
15 | ofdb_search($argv[2]); |
---|
16 | break; |
---|
17 | case "-D": |
---|
18 | ofdb_fetch($argv[2]); |
---|
19 | break; |
---|
20 | case "-P": |
---|
21 | ofdb_poster($argv[2]); |
---|
22 | break; |
---|
23 | } |
---|
24 | |
---|
25 | function ofdb_search($query) { |
---|
26 | $req = new HTTP_Request(); |
---|
27 | |
---|
28 | /* search for the movie */ |
---|
29 | $req->setURL(OFDB_URL . 'view.php?page=suchergebnis'); |
---|
30 | $req->setMethod(HTTP_REQUEST_METHOD_POST); |
---|
31 | $req->addPostData('SText', $query); |
---|
32 | $req->addPostData('Kat', 'Titel'); |
---|
33 | |
---|
34 | $req->sendRequest(); |
---|
35 | $dom = @DOMDocument::loadHTML($req->getResponseBody()); |
---|
36 | $xp = new DOMXPath($dom); |
---|
37 | |
---|
38 | $nodes = $xp->query("//a[starts-with(@href, 'view.php?page=film&fid=')]"); |
---|
39 | foreach ($nodes as $node) { |
---|
40 | $id = substr($node->getAttribute('href'), 23); |
---|
41 | $title = $node->textContent; |
---|
42 | |
---|
43 | printf("%s:%s\n", $id, $title); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | function ofdb_poster($id) { |
---|
48 | $req = new HTTP_Request(null, array("allowRedirects" => true)); |
---|
49 | |
---|
50 | $req->setURL(OFDB_URL . 'view.php?page=film&fid=' . $id); |
---|
51 | $req->sendRequest(); |
---|
52 | $dom = @DOMDocument::loadHTML($req->getResponseBody()); |
---|
53 | $xp = new DOMXPath($dom); |
---|
54 | |
---|
55 | /* IMDB-ID (for poster) */ |
---|
56 | if (($node = $xp->query("//img[@src='images/film_imdb.gif']")->item(0)->parentNode) instanceof DOMNode) |
---|
57 | $imdb_id = substr($node->getAttribute('href'),29); |
---|
58 | |
---|
59 | $req->setURL('http://www.imdb.com/title/tt' . $imdb_id . '/posters'); |
---|
60 | $req->sendRequest(); |
---|
61 | $dom = @DOMDocument::loadHTML($req->getResponseBody()); |
---|
62 | $xp = new DOMXPath($dom); |
---|
63 | |
---|
64 | /* look for impawards */ |
---|
65 | if (($node = $xp->query("//a[contains(@href,'impawards.com')]")->item(0)) instanceof DOMNode) { |
---|
66 | |
---|
67 | $base = $node->getAttribute('href'); |
---|
68 | $req->setURL($base); |
---|
69 | $req->sendRequest(); |
---|
70 | $dom = @DOMDocument::loadHTML($req->getResponseBody()); |
---|
71 | $xp = new DOMXPath($dom); |
---|
72 | |
---|
73 | if (($node = $xp->query("//img[starts-with(@src, 'posters/')]")->item(0)) instanceof DOMNode) { |
---|
74 | $url = dirname($base) . "/" . $node->getAttribute('src'); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | if (!$url) { |
---|
79 | if (($node = $xp->query("//table[starts-with(@background,'http://posters.imdb.com/posters/')]")->item(0)) instanceof DOMNode) |
---|
80 | $url = $node->getAttribute('background'); |
---|
81 | } |
---|
82 | |
---|
83 | print($url); |
---|
84 | } |
---|
85 | |
---|
86 | function ofdb_fetch($id) { |
---|
87 | $req = new HTTP_Request(null, array("allowRedirects" => true)); |
---|
88 | |
---|
89 | $req->setURL(OFDB_URL . 'view.php?page=film&fid=' . $id); |
---|
90 | $req->sendRequest(); |
---|
91 | $dom = @DOMDocument::loadHTML($req->getResponseBody()); |
---|
92 | $xp = new DOMXPath($dom); |
---|
93 | |
---|
94 | /* IMDB-URL (for runtime) */ |
---|
95 | if (($node = $xp->query("//img[@src='images/film_imdb.gif']")->item(0)->parentNode) instanceof DOMNode) |
---|
96 | $imdb_url = $node->getAttribute('href'); |
---|
97 | |
---|
98 | /* Title (german title) */ |
---|
99 | if (($node = $xp->query("//td[@width='99%']/font[@size='3']/b")->item(0)) instanceof DOMNode) |
---|
100 | $title = $node->textContent; |
---|
101 | |
---|
102 | /* Countries */ |
---|
103 | foreach ($xp->query("//a[starts-with(@href, 'view.php?page=blaettern&Kat=Land&')]") as $node) |
---|
104 | $countries[] = $node->textContent; |
---|
105 | $countries = join(',', $countries); |
---|
106 | |
---|
107 | /* Year */ |
---|
108 | if (($node = $xp->query("//a[starts-with(@href, 'view.php?page=blaettern&Kat=Jahr&')]")->item(0)) instanceof DOMNode) |
---|
109 | $year = $node->textContent; |
---|
110 | |
---|
111 | /* Directors */ |
---|
112 | foreach ($xp->query("//td[@width='99%']/table/tr[4]/td[3]//a[starts-with(@href,'view.php?page=liste')]") as $node) |
---|
113 | $directors[] = $node->firstChild->data; |
---|
114 | $directors = join(',', $directors); |
---|
115 | |
---|
116 | /* Actors */ |
---|
117 | foreach ($xp->query("//td[@width='99%']/table/tr[5]/td[3]//a[starts-with(@href,'view.php?page=liste')]") as $node) |
---|
118 | $actors[] = $node->firstChild->data; |
---|
119 | $actors = join(',', $actors); |
---|
120 | |
---|
121 | /* Genres */ |
---|
122 | foreach ($xp->query("//a[starts-with(@href, 'view.php?page=genre&Genre=')]") as $node) |
---|
123 | $genres[] = $node->textContent; |
---|
124 | $genres = join(',', $genres); |
---|
125 | |
---|
126 | /* Userrating */ |
---|
127 | if (($node = $xp->query("//img[@src='images/notenskala.gif']")->item(0)->parentNode) instanceof DOMNode) |
---|
128 | $rating = trim(substr($node->textContent,56,4)); |
---|
129 | |
---|
130 | /* Find the sid */ |
---|
131 | if (($node = $xp->query("//a[starts-with(@href, 'view.php?page=inhalt&fid=')]")->item(0)) instanceof DOMNode) |
---|
132 | $sid = substr($node->getAttribute('href'),30 + strlen($id)); |
---|
133 | |
---|
134 | /* Plot */ |
---|
135 | $req->setURL(OFDB_URL . 'view.php?page=inhalt&sid=' . $sid . '&fid=' . $id); |
---|
136 | $req->sendRequest(); |
---|
137 | $dom = @DOMDocument::loadHTML($req->getResponseBody()); |
---|
138 | $xp = new DOMXPath($dom); |
---|
139 | |
---|
140 | if (($node = $xp->query("//font[@class='Blocksatz']")->item(0)) instanceof DOMNode) |
---|
141 | $plot = str_replace($node->firstChild->textContent,"",$node->textContent); |
---|
142 | |
---|
143 | /* Fetch IMDB page */ |
---|
144 | $req->setURL($imdb_url); |
---|
145 | $req->sendRequest(); |
---|
146 | $dom = @DOMDocument::loadHTML($req->getResponseBody()); |
---|
147 | $xp = new DOMXPath($dom); |
---|
148 | |
---|
149 | /* Release Date */ |
---|
150 | if (($node = $xp->query("//div[@class='info']/h5[starts-with(.,'Premierendatum')]")->item(0)->parentNode) instanceof DOMNode) |
---|
151 | $premiere = trim(substr($node->textContent,17,-6)); |
---|
152 | |
---|
153 | /* Runtime */ |
---|
154 | if (($node = $xp->query("//div[@class='info']/h5[starts-with(.,'L')]")->item(0)->parentNode) instanceof DOMNode) |
---|
155 | $runtime = substr(trim($node->textContent),8,-4); |
---|
156 | |
---|
157 | printf("Title:%s\n" . |
---|
158 | "Year:%s\n" . |
---|
159 | "ReleaseDate:%s\n" . |
---|
160 | "Director:%s\n" . |
---|
161 | "Plot:%s\n" . |
---|
162 | "UserRating:%s\n" . |
---|
163 | "MovieRating:\n" . |
---|
164 | "Runtime:%s\n" . |
---|
165 | "Writers:\n" . |
---|
166 | "Cast:%s\n" . |
---|
167 | "Genres:%s\n" . |
---|
168 | "Countries:%s\n", |
---|
169 | |
---|
170 | $title, $year, $premiere, $directors, $plot, $rating, $runtime, $actors, $genres, $countries); |
---|
171 | } |
---|
172 | ?> |
---|