Advertisement
Guest User

Untitled

a guest
Aug 17th, 2011
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.31 KB | None | 0 0
  1. program IMDB;
  2.  
  3. uses
  4. StringUtils1;
  5.  
  6. // ***** Manually set UserCountry to your required Classification Country below *****
  7. const
  8. //UserCountry = '';
  9. { Delete the line above and remove the "//" in front of one the
  10. following lines, or add your country if it is not listed }
  11. UserCountry = 'USA';
  12. //UserCountry = 'Canada';
  13. //UserCountry = 'Mexico';
  14. //UserCountry = 'Brazil';
  15. //UserCountry = 'Argentina';
  16. //UserCountry = 'Australia';
  17. //UserCountry = 'India';
  18. //UserCountry = 'Italy';
  19. //UserCountry = 'Spain';
  20. //UserCountry = 'Portugal';
  21. //UserCountry = 'France';
  22. //UserCountry = 'Germany';
  23. //UserCountry = 'Netherlands';
  24. //UserCountry = 'UK';
  25. //UserCountry = 'Ireland';
  26. //UserCountry = 'Finland';
  27. //UserCountry = 'Norway';
  28. //UserCountry = 'Sweden';
  29. //UserCountry = 'Switzerland';
  30.  
  31. PopularTitleSearchURL = 'http://www.imdb.com/find?tt=1;q=';
  32. FullTitleSearchURL = 'http://www.imdb.com/find?more=tt;q=';
  33. EpisodeTitleSearchURL = 'http://www.imdb.com/find?s=tt;ttype=ep;q=';
  34.  
  35. var
  36. MovieName: string;
  37. MovieURL: string;
  38. MovieNumber: string;
  39. UpdateFile: TStringList;
  40.  
  41. function ConvertToASCII(AText: string): string;
  42. begin
  43. Result := AText;
  44. if GetOption('ConvertToASCII') = 1 then
  45. begin
  46. if StringUtils1_Version > 5 then
  47. Result := Cp1252ToASCII(AText)
  48. else
  49. ShowMessage('The "ConvertToASCII" option requires a newer version of StringUtils1.pas (at least version 6).' + #13#10 + 'Run the "Update Scripts" script to get it.');
  50. end;
  51. end;
  52.  
  53. // ***** analyzes IMDB's results page that asks to select a movie from a list *****
  54.  
  55. procedure AnalyzeResultsPage(Address: string);
  56. var
  57. PageText: string;
  58. Value: string;
  59. begin
  60. PageText := ConvertToASCII(GetPage(Address));
  61. if ((GetOption('BatchMode') = 2) and (GetField(fieldURL)<>'')) or (pos('<title>IMDb', PageText) = 0) then
  62. begin
  63. AnalyzeMoviePage(PageText)
  64. end
  65. else
  66. begin
  67. if Pos('<b>No Matches.</b>', PageText) > 0 then
  68. begin
  69. if GetOption('BatchMode') = 0 then
  70. ShowMessage('No movie found for this search.');
  71. Exit;
  72. end;
  73. if GetOption('BatchMode') = 0 then
  74. begin
  75. PickTreeClear;
  76. repeat
  77. Value := TextBefore(PageText, '</b> (Displaying', '<p><b>');
  78. if Value <> '' then
  79. begin
  80. HTMLRemoveTags(Value);
  81. HTMLDecode(Value);
  82. PickTreeAdd(Value, '');
  83. end;
  84. Value := TextBetween(PageText, '<table><tr>', '</table>');
  85. PageText := RemainingText;
  86. until not AddMovieTitles(Value);
  87. Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
  88. if Value <> '' then
  89. PickTreeMoreLink('http://www.imdb.com' + Value);
  90. if GetOption('EpisodeTitleSearch') > 0 then
  91. PickTreeMoreLink(EpisodeTitleSearchURL + UrlEncode(MovieName));
  92. if PickTreeExec(Address) then
  93. AnalyzeResultsPage(Address);
  94. end
  95. else
  96. begin
  97. Value := TextBetween(PageText, '.</td><td valign="top">', '</a>');
  98. if Value <> '' then
  99. AnalyzeResultsPage('http://www.imdb.com' + TextBetween(Value, '<a href="', '" onclick="'));
  100. end;
  101. end;
  102. end;
  103.  
  104. // ***** analyzes Google's results page that asks to select a movie from a list *****
  105.  
  106. procedure AnalyzeGooglesResultsPage(GoogleAddress: string);
  107. var
  108. PageText: string;
  109. Value: string;
  110. Address: string;
  111. begin
  112. PageText := GetPage(GoogleAddress);
  113. Address := '';
  114. if Pos('did not match any documents', PageText) > 0 then
  115. begin
  116. ShowMessage('No movie found for this search');
  117. Exit;
  118. end;
  119. if GetOption('BatchMode') = 0 then
  120. begin
  121. PickTreeClear;
  122. PickTreeAdd('Google`s search results for "' + MovieName + '" on IMDB:', '');
  123. repeat
  124. Value := TextBetween(PageText, '<h3 class=r>', '</a>');
  125. PageText := RemainingText;
  126. Address := TextBetween(Value, '<a href="', 'maindetails"');
  127. if (GetOption('AllActors') = 1) or (GetOption('Producer') = 1) then
  128. if Address <> '' then
  129. Address := Address + 'combined';
  130. HTMLRemoveTags(Value);
  131. HTMLDecode(Value);
  132. if (Pos(') - ', Value) = 0) and (Value <> '') and (Address <> '') then
  133. PickTreeAdd(Value, Address);
  134. until Value = '';
  135. if PickTreeExec(GoogleAddress) then
  136. AnalyzeResultsPage(GoogleAddress);
  137. end
  138. else
  139. begin
  140. Value := TextBetween(PageText, '<h3 class=r>', '</a>');
  141. Address := TextBetween(Value, '<a href="', 'maindetails"');
  142. if (GetOption('AllActors') = 1) or (GetOption('Producer') = 1) then
  143. if Address <> '' then
  144. Address := Address + 'combined';
  145. if Address <> '' then
  146. AnalyzeResultsPage(Address);
  147. end;
  148. end;
  149.  
  150. // ***** adds the movie titles found on IMDB's results page *****
  151.  
  152. function AddMovieTitles(List: string): Boolean;
  153. var
  154. Value, Value1, Value2: string;
  155. Address: string;
  156. p1, p2: Integer;
  157. begin
  158. Result := False;
  159. Value := TextBetween(List, '.</td><td valign="top">', '</td>');
  160. if GetOption('HideAkaTitles') = 1 then
  161. Value := StringReplace(Value, TextAfter(Value, '<p class="find-aka">'), '')
  162. else
  163. Value := StringReplace(Value, 'aka', ' | aka');
  164.  
  165. List := RemainingText;
  166. while Value <> '' do
  167. begin
  168. Address := TextBetween(Value, '<a href="/title/tt', '/');
  169. // ##########
  170. // if (GetOption('AllActors') = 1) or (GetOption('Producer') = 1) then
  171. // Address := Address + '/combined'
  172. // else
  173. // Address := Address + '/';
  174. Address := Address + '/combined';
  175. // ##########
  176. HTMLRemoveTags(Value);
  177. HTMLDecode(Value);
  178.  
  179. if GetOption('HideAkaTitles') = 0 then
  180. if Pos('| aka', Value)<> 0 then
  181. begin
  182. p1 := Pos(')', Value);
  183. p2 := Pos('| aka', Value);
  184.  
  185. Value1 := Copy(Value, 0, p1+1);
  186. Value2 := Copy(Value, p2, Length(Value));
  187. Value := Value1+Value2;
  188. end;
  189.  
  190.  
  191. // if GetOption('HideAkaTitles') = 1 then
  192. // Value := Value + ')';
  193. PickTreeAdd(Value, 'http://www.imdb.com/title/tt' + Address);
  194. Result := True;
  195. Value := TextBetween(List, '.</td><td valign="top">', '</td>');
  196. if GetOption('HideAkaTitles') = 1 then
  197. Value := StringReplace(Value, TextAfter(Value, '<br>&#160;'), '')
  198. else
  199. Value := StringReplace(Value, 'aka', ' | aka');
  200.  
  201. List := RemainingText;
  202. end;
  203. end;
  204.  
  205. // ***** analyzes the page containing movie information *****
  206.  
  207. procedure AnalyzeMoviePage(PageText: string);
  208. var
  209. Value, Value2, Value3, ValueAlt, FullValue: string;
  210. p, Count: Integer;
  211. begin
  212. MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/');
  213. if MovieNumber = '' then
  214. MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/combined"');
  215. if MovieNumber = '' then
  216. MovieNumber := TextBetween(PageText, '<link rel="canonical" href="http://www.imdb.com/title/tt', '/');
  217. // #########
  218. // if ((GetOption('AllActors') = 1) or (GetOption('Producer') = 1)) and (Pos('<div id="tn15" class="maindetails">', PageText) > 0) then
  219. // PageText := ConvertToASCII(GetPage('http://www.imdb.com/title/tt' + MovieNumber + '/combined'));
  220. if Pos('/combined"', TextBetween(PageText, '<link rel="canonical"', '/>')) = 0 then
  221. PageText := ConvertToASCII(GetPage('http://www.imdb.com/title/tt' + MovieNumber + '/combined'));
  222. // #########
  223. MovieURL := 'http://imdb.com/title/tt' + MovieNumber;
  224. // URL
  225. if CanSetField(fieldURL) then
  226. SetField(fieldURL, MovieURL);
  227. // OriginalTitle & TranslatedTitle & Year
  228. if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) or CanSetField(fieldTranslatedTitle) then
  229. begin
  230. Value := TextBetween(PageText, '<title>', '</title>');
  231. ValueAlt := TextBetween(PageText, '<span class="title-extra">','<i>');
  232. p := Pos('></span', ValueAlt);
  233. if p > 0 then
  234. ValueAlt := '';
  235. p := Pos(' (1', Value);
  236. if p = 0 then
  237. p := Pos(' (2', Value);
  238. Value2 := Copy(Value, 0, p-1);
  239. Value := Copy(Value, p+2, Length(Value));
  240. HTMLDecode(Value2);
  241. HtmlDecode(ValueAlt);
  242.  
  243. if CanSetField(fieldTranslatedTitle) then
  244. SetField(fieldTranslatedTitle, Value2);
  245.  
  246. if CanSetField(fieldOriginalTitle) then
  247. if ValueAlt <> '' then
  248. SetField(fieldOriginalTitle, ValueAlt)
  249. else
  250. SetField(fieldOriginalTitle, Value2);
  251. if Pos('/', Value) > 0 then
  252. Value2 := TextBefore(Value, '/', '')
  253. else
  254. Value2 := TextBefore(Value, ')', '');
  255. if CanSetField(fieldYear) then
  256. SetField(fieldYear, Value2);
  257. end;
  258.  
  259. // Picture
  260. if CanSetPicture then
  261. begin
  262. case GetOption('ImageKind') of
  263. 2: if not ImportSmallPicture(PageText) then
  264. ImportPictureNotAvailable(PageText);
  265. 3: if not ImportLargePicture(PageText) then
  266. if not ImportSmallPicture(PageText) then
  267. ImportPictureNotAvailable(PageText);
  268. 4: if not ImportMerchandisingPicture then
  269. if not ImportDvdDetailsPicture then
  270. ImportSmallPicture(PageText);
  271. 5: if not ImportDvdDetailsPicture then
  272. if not ImportMerchandisingPicture then
  273. ImportSmallPicture(PageText);
  274. else
  275. ImportSmallPicture(PageText);
  276. end;
  277. end;
  278. // Director
  279. if CanSetField(fieldDirector) then
  280. begin
  281. Value := TextBetween(PageText, '<h5>Director:', '</div>');
  282. if Value = '' then
  283. Value := TextBetween(PageText, '<h5>Director', '</div>');
  284. if Pos(':<', Value) > 0 then
  285. Value := '<' + TextAfter(Value, ':<');
  286. if Pos('<p>', Value) > 0 then
  287. Value := TextBetween(Value, '<p>', '</p>');
  288. Value := StringReplace(Value, '<br/>', ',');
  289. HTMLRemoveTags(Value);
  290. HTMLDecode(Value);
  291. Value := StringReplace(Value, ', more', '');
  292. Value := StringReplace(Value, ', (more)', '');
  293. Value := StringReplace(Value, ' ', '');
  294. Value := StringReplace(Value, #13, '');
  295. Value := StringReplace(Value, #10, '');
  296. Value := StringReplace(Value, #9, '');
  297. Value := StringReplace(Value, ',', ', ');
  298. if Copy(Value, Length(Value) - 1, 2) = ', ' then
  299. Value := Copy(Value, 0, Length(Value) - 2);
  300. SetField(fieldDirector, Value);
  301. end;
  302. // Actors
  303. if CanSetField(fieldActors) then
  304. begin
  305. Value := FullTrim(TextBetween(PageText, '<table class="cast">', '</table>'));
  306. if Value <> '' then
  307. begin
  308. FullValue := '';
  309. Count := 0;
  310. case GetOption('ActorsLayout') of
  311. 0, 1:
  312. while Pos('<tr', Value) > 0 do
  313. begin
  314. Value2 := TextBetween(Value, '<tr', '</tr>');
  315. Value := RemainingText;
  316. if Pos('rest of cast', Value2) > 0 then
  317. Continue;
  318. if FullValue <> '' then
  319. FullValue := FullValue + #13#10;
  320. TextBefore(Value2, '</td>', '');
  321. Value2 := FullTrim(TextBetween(Value2, '<td class="nm">', '</td>'));
  322. HTMLRemoveTags(Value2);
  323. if Value2 <> '' then
  324. begin
  325. FullValue := FullValue + Value2;
  326. Count := Count + 1;
  327. end;
  328. // ###
  329. if (Count = 15) and (GetOption('AllActors') = 0) then
  330. Break;
  331. // ###
  332. if (Count = 10) and (GetOption('AllActors') = 2) then
  333. Break;
  334. end;
  335. 2, 3:
  336. while Pos('<tr', Value) > 0 do
  337. begin
  338. Value2 := TextBetween(Value, '<tr', '</tr>');
  339. Value := RemainingText;
  340. if Pos('rest of cast', Value2) > 0 then
  341. Continue;
  342. if FullValue <> '' then
  343. FullValue := FullValue + #13#10;
  344. TextBefore(Value2, '</td>', '');
  345. Value2 := FullTrim(TextBetween(Value2, '<td class="nm">', '</td>'));
  346. HTMLRemoveTags(Value2);
  347. if Value2 <> '' then
  348. begin
  349. FullValue := FullValue + Value2;
  350. Value2 := FullTrim(TextBetween(RemainingText, '"char">', '</td>'));
  351. if Value2 <> '' then
  352. FullValue := FullValue + ' (as ' + Value2 + ')';
  353. Count := Count + 1;
  354. // ###
  355. if (Count = 15) and (GetOption('AllActors') = 0) then
  356. Break;
  357. // ###
  358. if (Count = 10) and (GetOption('AllActors') = 2) then
  359. Break;
  360. end;
  361. end;
  362. 4:
  363. begin
  364. FullValue := Value;
  365. FullValue := StringReplace(FullValue, ' <tr><td align="center" colspan="4"><small>rest of cast listed alphabetically:</small></td></tr>', '');
  366. FullValue := StringReplace(FullValue, '> <', '><');
  367. FullValue := StringReplace(FullValue, '</tr>', #13#10);
  368. end;
  369. end;
  370. HTMLRemoveTags(FullValue);
  371. HTMLDecode(FullValue);
  372. case GetOption('ActorsLayout') of
  373. 0, 2:
  374. FullValue := StringReplace(FullValue, #13#10, ', ');
  375. end;
  376. SetField(fieldActors, FullValue);
  377. end;
  378. end;
  379. //Country
  380. if CanSetField(fieldCountry) then
  381. begin
  382. SetField(fieldCountry, ImportList(PageText, GetOption('MultipleValuesCountry'), '/country/'));
  383. end;
  384. //Category
  385. if CanSetField(fieldCategory) then
  386. begin
  387. SetField(fieldCategory, ImportList(PageText, GetOption('MultipleValuesCategory'), '/Genres/'));
  388. end;
  389. // Language
  390. if CanSetField(fieldLanguages) then
  391. begin
  392. SetField(fieldLanguages, ImportList(PageText, GetOption('MultipleValuesLanguages'), '/language/'));
  393. end;
  394. // Audio Format
  395. if CanSetField(fieldAudioFormat) then
  396. begin
  397. SetField(fieldAudioFormat, ImportList(PageText, GetOption('MultipleValuesAudioFormat'), '/search/title?sound_mixes='));
  398. end;
  399. // Aspect Ratio
  400. begin
  401. Value := '';
  402. Value := TextBetween(PageText, '<h5>Aspect Ratio:</h5>', '</div>');
  403. if Pos('<p>', Value) > 0 then
  404. Value := TextBetween(Value, '<p>', '</p>');
  405. if Pos('<a ', Value) > 0 then
  406. Value := TextBefore(Value, '<a ', '');
  407. HTMLRemoveTags(Value);
  408. HTMLDecode(Value);
  409. Value := FullTrim(Value);
  410. Value := StringReplace(Value, ', more', '');
  411. Value := StringReplace(Value, ', (more)', '');
  412. Value := StringReplace(Value, ' more', '');
  413. if (CanSetField(fieldVideoFormat)) and (GetOption('AspectRatio') = 1) then
  414. SetField(fieldVideoFormat, Value);
  415. if (CanSetField(fieldResolution)) and (GetOption('AspectRatio') = 2) then
  416. SetField(fieldResolution, Value);
  417. end;
  418. // Description
  419. if CanSetField(fieldDescription) then
  420. begin
  421. Value := TextBetween(PageText, '<h5>Plot:</h5>', '</div>');
  422. if Value = '' then
  423. Value := TextBetween(PageText, '<h5>Plot Summary:</h5>', '</div>');
  424. if Pos('<p>', Value) > 0 then
  425. Value := TextBetween(Value, '<p>', '</p>');
  426. Value := StringReplace(Value, '<div class="info-content">', '');
  427. Value := StringReplace(Value, Textbetween(Value, '| <a class="tn15more inline" href="synopsis">', '</a>'), '');
  428. Value := StringReplace(Value, Textbetween(Value, '<a class="tn15more inline" href="synopsis">', '</a>'), '');
  429. Value := StringReplace(Value, '| <a class="tn15more inline" href="synopsis"></a>', '');
  430. Value := StringReplace(Value, '<a class="tn15more inline" href="synopsis"></a>', '');
  431. Value := StringReplace(Value, '&raquo;', '');
  432. if (Value = #13#10 + #13#10) or (Value = #13#10) then
  433. Value := '';
  434. if (GetOption('DescriptionSelection') = 0) and (Pos('<a class="tn15more inline"', Value) > 0) then
  435. Value := TextAfter(Value, #13#10);
  436. if Value <> '' then
  437. SetField(fieldDescription, ImportSummary(Value));
  438. end;
  439. // Length
  440. if CanSetField(fieldLength) then
  441. begin
  442. Value := TextBetween(PageText, '<h5>Runtime:</h5>', '</div>');
  443. if Pos('<p>', Value) > 0 then
  444. Value := TextBetween(Value, '<p>', '</p>');
  445. Value := TextBefore(Value, ' min', '');
  446. HTMLRemoveTags(Value);
  447. Value := FullTrim(Value);
  448. if Value <> '' then
  449. begin
  450. if Pos(':', Value) > 0 then
  451. SetField(fieldLength, TextAfter(Value, ':'))
  452. else
  453. SetField(fieldLength, Value);
  454. end;
  455. end;
  456. // Writer (Producer Field)
  457. if CanSetField(fieldProducer) then
  458. begin
  459. if GetOption('Producer') = 1 then
  460. begin
  461. Value := TextBetween(PageText, 'Produced by</a></h5>', '</table>');
  462. FullValue := '';
  463. Value2 := TextBetween(Value, '<a href="/name/', '</a>');
  464. while Value2 <> '' do
  465. begin
  466. Value := RemainingText;
  467. Value2 := TextAfter(Value2, '">');
  468. if FullValue <> '' then
  469. FullValue := FullValue + ', ';
  470. FullValue := FullValue + Value2;
  471. Value2 := TextBetween(Value, '<a href="/name/', '</a>');
  472. end;
  473. HTMLDecode(FullValue);
  474. SetField(fieldProducer, FullValue);
  475. end
  476. else
  477. begin
  478. Value := TextBetween(PageText, '<h5>Writer', '</div>');
  479. if Pos(':<', Value) > 0 then
  480. Value := '<' + TextAfter(Value, ':<');
  481. if Pos('<p>', Value) > 0 then
  482. Value := TextBetween(Value, '<p>', '</p>');
  483. Value := StringReplace(Value, '<br/>', ',');
  484. Value := StringReplace(Value, '>more<', '><');
  485. HTMLRemoveTags(Value);
  486. HTMLDecode(Value);
  487. if Value <> '' then
  488. begin
  489. Value := StringReplace(Value, '..., more', '');
  490. Value := StringReplace(Value, ', more', '');
  491. Value := StringReplace(Value, '...', '');
  492. Value := StringReplace(Value, ' &', '');
  493. Value := StringReplace(Value, ' ', '');
  494. Value := StringReplace(Value, #13, '');
  495. Value := StringReplace(Value, #10, '');
  496. Value := StringReplace(Value, #9, '');
  497. Value := StringReplace(Value, ',', ', ');
  498. Value := FullTrim(StringReplace(Value, ' and, ', ', '));
  499. if Value <> '' then
  500. while StrGet(Value, Length(Value)) = ',' do
  501. begin
  502. Delete(Value, Length(Value), 1);
  503. Value := FullTrim(Value);
  504. end;
  505. SetField(fieldProducer, Value);
  506. end;
  507. end;
  508. end;
  509. // Comments
  510. if CanSetField(fieldComments) then
  511. begin
  512. if (GetOption('CommentType') = 1) then
  513. begin
  514. Value := TextAfter(PageText,'/rg/title-nav-item/usercomments/');
  515. if (Value <> '') or (Pos('href="usercomments" class="link"', PageText) > 0) then
  516. begin
  517. Value2 := '';
  518. FullValue := ConvertToASCII(GetPage(MovieURL+'/usercomments'));
  519. FullValue := TextAfter(FullValue, 'review useful:</small><br>');
  520. while FullValue <> '' do
  521. begin
  522. Value := TextBetween(FullValue, '<b>', '<div');
  523. Value2 := Value2 + #13#10 + #13#10 + TextBefore(Value, '</b>', '');
  524. Value := RemainingText;
  525. Value2 := Value2 + #13#10 + 'Date: ' + TextBetween(Value, '<small>', '</small>');
  526. Value := RemainingText;
  527. Value := 'Author: ' + TextBetween(Value, 'comments">', '<br>');
  528. HtmlRemoveTags(Value);
  529. Value2 := Value2 + #13#10 + Value;
  530. Value := RemainingText;
  531. Value := TextBetween(Value, '<p>' + #13#10, #13#10 + '</p>');
  532. Value := StringReplace(Value, #13#10, ' ');
  533. Value := StringReplace(Value, '<br><br>', #13#10);
  534. Value := StringReplace(Value, '<br>', #13#10);
  535. HtmlDecode(Value);
  536. Value2 := Value2 + #13#10 + #13#10 + FullTrim(Value);
  537. FullValue := TextAfter(FullValue, 'review useful:</small><br>');
  538. end;
  539. HTMLRemoveTags(Value2);
  540. HTMLDecode(Value2);
  541. SetField(fieldComments, 'USER COMMENTS:' + Value2 + #13#10);
  542. end;
  543. end
  544. else
  545. if (GetOption('CommentType') = 0) then
  546. begin
  547. Value := TextAfter(PageText, '/comments">');
  548. if Value <> '' then
  549. begin
  550. Value := TextBetween(Value, '<p>', '</p>');
  551. Value := StringReplace(Value, #13#10, ' ');
  552. Value := StringReplace(Value, '<br>', #13#10);
  553. HTMLRemoveTags(Value);
  554. HTMLDecode(Value);
  555. Value := FullTrim(Value);
  556. while Pos(' ', Value) > 0 do
  557. Value := StringReplace(Value, ' ', ' ');
  558. while Pos(#13#10, Value) = 1 do
  559. Delete(Value, 1, 2);
  560. SetField(fieldComments, Value + #13#10);
  561. end;
  562. end
  563. else
  564. if (GetOption('CommentType') = 2) then
  565. SetField(fieldComments, '');
  566. end;
  567. // TagLine
  568. if GetOption('GetTagline') > 0 then
  569. begin
  570. Value := TextBetween(PageText, '<h5>Tagline:</h5>', '</div>');
  571. if Pos('<p>', Value) > 0 then
  572. Value := TextBetween(Value, '<p>', '</p>');
  573. if Pos('<a', Value) > 0 then
  574. Value := TextBefore(Value, '<a', '');
  575. Value := TextAfter(Value, #13#10);
  576. HTMLRemoveTags(Value);
  577. HTMLDecode(Value);
  578. Value := FullTrim(Value);
  579. if Value <> '' then
  580. begin
  581. if StrGet(Value, 1) <> '"' then
  582. Value := '"' + Value + '"';
  583. case GetOption('GetTagline') of
  584. 1:
  585. begin
  586. if GetField(fieldDescription) <> '' then
  587. Value := Value + #13#10 + #13#10 + GetField(fieldDescription);
  588. SetField(fieldDescription, Value);
  589. end;
  590. 2:
  591. begin
  592. if GetField(fieldComments) <> '' then
  593. Value := Value + #13#10 + #13#10 + GetField(fieldComments);
  594. SetField(fieldComments, Value);
  595. end;
  596. end;
  597. end;
  598. end;
  599. // Trivia
  600. if GetOption('Trivia') > 0 then
  601. begin
  602. sleep(50);
  603. Value := MovieUrl;
  604. FullValue := ConvertToASCII(GetPage(Value+'/trivia'));
  605. case GetOption('Trivia') of
  606. 1,2:
  607. Value := TextBetween(FullValue, '<div class="sodatext">', '</div>');
  608. 3,4:
  609. Value := TextBetween(FullValue, '<div class="list">', '<div id="sidebar">');
  610. end;
  611. if Value <> '' then
  612. begin
  613. Value := StringReplace(Value, #13#10, '');
  614. while Pos(' ', Value) > 0 do
  615. Value := StringReplace(Value, ' ', '');
  616. while Pos('<span class="linksoda">', Value) > 0 do
  617. begin
  618. Value := StringReplace(Value, TextBetween(Value, '<span class="linksoda">', '</div>'), '');
  619. Value := StringReplace(Value, '<span class="linksoda"></div>', '');
  620. end;
  621. Value := StringReplace(Value, 'Link this trivia', '');
  622. Value := StringReplace(Value, '<div class="sodatext">', #13#10 + '- ');
  623. HTMLRemoveTags(Value);
  624. HTMLDecode(Value);
  625. case GetOption('Trivia') of
  626. 1,3:
  627. begin
  628. if GetField(fieldDescription) <> '' then
  629. Value := GetField(fieldDescription) + #13#10 + #13#10 + 'IMDB TRIVIA: ' + Value
  630. else
  631. Value := 'IMDB TRIVIA: ' + Value;
  632. SetField(fieldDescription, Value);
  633. end;
  634. 2,4:
  635. begin
  636. if GetField(fieldComments) <> '' then
  637. Value := GetField(fieldComments) + #13#10 + #13#10 + 'IMDB TRIVIA: ' + Value
  638. else
  639. Value := 'IMDB TRIVIA: ' + Value;
  640. SetField(fieldComments, Value);
  641. end;
  642. end;
  643. end;
  644. end;
  645. // Awards
  646. if (GetOption('Awards') > 0) then
  647. begin
  648. ImportAwards();
  649. end;
  650. // Rating
  651. if CanSetField(fieldRating) then
  652. begin
  653. // (Remove the "//" of the next two lines beginning with "Value" and add "//" to the following two lines beginning with Value
  654. // if you would like to import arithmetic ratings instead of IMDB's user ratings)
  655. // Value := ConvertToASCII(GetPage(MovieURL + '/ratings'));
  656. // Value := TextBetween(Value, 'Arithmetic mean = ', '. ');
  657. Value := TextBetween(PageText, '<h5>User Rating:</h5>', '</b>');
  658. Value := TextBetween(Value, '<b>', '/');
  659. if Value <> '' then
  660. SetField(fieldRating, Value);
  661. end;
  662. if GetOption('UserRatings') > 0 then
  663. begin
  664. Value := TextBetween(PageText, '<a href="ratings" class="tn15more">', '</a>');
  665. if Value <> '' then
  666. Value := 'User Rating: ' + GetField(fieldRating) + ' out of 10 (with ' + Value + ')';
  667. if (GetOption('UserRatings') = 1) and (Value <> '') and (CanSetField(fieldMediaType)) then
  668. SetField(fieldMediaType, Value);
  669. if (GetOption('UserRatings') = 2) and (Value <> '') then
  670. SetField(fieldComments, GetField(fieldComments) + #13#10 + #13#10 + Value);
  671. end;
  672. // Classification
  673. if GetOption('Classification') > 0 then
  674. begin
  675. if UserCountry = '' then
  676. ShowMessage('Country not set for classification selection - Click "Editor" tab in the scripting window, then select your country by modifying the required line as explained in the first lines of the code')
  677. else
  678. begin
  679. Value := TextBetween(PageText, '<a href="/search/title?certificates=', '</div>');
  680. Value := TextBetween(Value, UserCountry + ':', '</a>'); if Value <> '' then
  681. begin
  682. if GetOption('Classification') = 1 then
  683. SetField(fieldMediaType, Value)
  684. else
  685. SetField(fieldComments, GetField(fieldComments) + #13#10 + #13#10 + 'Classification: ' + Value);
  686. end;
  687. end;
  688. end;
  689. // MPAA rating
  690. if (GetOption('MPAA') > 0) then
  691. begin
  692. Value := FullTrim(TextBetween(PageText, '<h5><a href="/mpaa">MPAA</a>:</h5>', '</div>'));
  693. if Pos('<p>', Value) > 0 then
  694. Value := TextBetween(Value, '<p>', '</p>');
  695. HTMLRemoveTags(Value);
  696. Value := FullTrim(Value);
  697. // Value := TextAfter(Value, #13#10);
  698. if Value <> '' then
  699. begin
  700. if GetOption('MPAA') = 1 then
  701. SetField(fieldMediaType, TextBetween(Value, 'Rated ', ' '))
  702. else
  703. SetField(fieldComments, GetField(fieldComments) + #13#10 + #13#10 + Value);
  704. end;
  705. end;
  706. end;
  707.  
  708. // ***** Imports lists like Genre, Country, etc. depending of the selected option *****
  709.  
  710. function ImportList(PageText: string; MultipleValues: Integer; StartTag: string): string;
  711. var
  712. Value, Value2: string;
  713. begin
  714. if MultipleValues = 0 then
  715. begin
  716. Value := TextBetween(PageText, StartTag, '</a>');
  717. Value2 := TextAfter(Value, '">');
  718. end
  719. else
  720. begin
  721. Value := TextBetween(PageText, StartTag, '</div>');
  722. Value2 := TextBefore(Value, '<a class="tn15more inline"', '');
  723. if Value2 = '' then
  724. Value2 := Value;
  725. Value2 := TextAfter(Value2, '">');
  726. HTMLRemoveTags(Value2);
  727. if MultipleValues = 1 then
  728. Value2 := StringReplace(Value2, ' | ', ', ');
  729. if MultipleValues = 2 then
  730. Value2 := StringReplace(Value2, ' | ', ' / ');
  731. if MultipleValues = 3 then
  732. Value2 := '';
  733. end;
  734. Value2 := StringReplace(Value2, #13#10, '');
  735. Value2 := StringReplace(Value2, ' , ', ', ');
  736. HTMLDecode(Value2);
  737. Result := FullTrim(Value2);
  738. end;
  739.  
  740. // ***** functions to import the different pictures kinds, depending of the option selected by user *****
  741.  
  742. //Import small picture from IMDB movie main page
  743. function ImportSmallPicture(PageText: string): Boolean;
  744. var
  745. Value: string;
  746. begin
  747. Result := False;
  748. Value := TextBetween(PageText, '<div class="photo">', '</div>');
  749. if (Value <> '') and (Pos('"Poster Not Submitted"', Value) = 0) then
  750. begin
  751. Value := TextBetween(Value, 'src="', '"');
  752. if Value <> '' then
  753. begin
  754. GetPicture(Value);
  755. Result := True;
  756. end;
  757. end;
  758. end;
  759.  
  760. //Import large image from link on IMDB movie main page
  761. function ImportLargePicture(PageText: string): Boolean;
  762. var
  763. Value: string;
  764. begin
  765. Result := False;
  766. Value := TextBetween(PageText, '<div class="photo">', '</div>');
  767. if (Value <> '') and (Pos('"Poster Not Submitted"', Value) = 0) and (Pos('<a name="poster" href="/rg/action-box-title/primary-photo', Value) > 0) then
  768. begin
  769. Value := TextBetween(Value, 'href="/rg/action-box-title/primary-photo', '"');
  770. if Value <> '' then
  771. begin
  772. Value := 'http://www.imdb.com' + Value;
  773. Value := GetPage(Value);
  774. Value := TextBetween(Value, '<div class="primary">', '</div>');
  775. if (Value <> '') and (Pos(' src="', Value) > 0) then
  776. begin
  777. Value := TextBetween(Value, ' src="', '"');
  778. GetPicture(Value);
  779. Result := True;
  780. end;
  781. end;
  782. end;
  783. end;
  784.  
  785. //Image not available, import "No Poster Available" icon
  786. function ImportPictureNotAvailable(PageText: string): Boolean;
  787. var
  788. Value: string;
  789. begin
  790. Result := False;
  791. Value := TextBetween(PageText, '<div class="photo">', '</div>');
  792. if (Value <> '') and (Pos('"Poster Not Submitted"', Value) > 0) then
  793. begin
  794. Value := TextBetween(Value, 'src="', '"');
  795. if Value <> '' then
  796. begin
  797. GetPicture(Value);
  798. Result := True;
  799. end;
  800. end;
  801. end;
  802.  
  803. //Image from DVD Details Page
  804. function ImportDvdDetailsPicture: Boolean;
  805. var
  806. Value, PageText: string;
  807. begin
  808. Result := False;
  809. PageText := ConvertToASCII(GetPage(MovieUrl+'/dvd'));
  810. Value := TextBefore(PageText, '.jpg alt="', '<table class="dvd_section" cellpadding="10"><tr>');
  811. if Value <> '' then
  812. begin
  813. Value := TextBetween(Value, '<a href="', '">');
  814. if Value <> '' then
  815. Result := ImportFromAmazonRedirect('http://www.imdb.com' + Value);
  816. end;
  817. end;
  818.  
  819. //Image from Merchandising Links (/sales) Page
  820. function ImportMerchandisingPicture: Boolean;
  821. var
  822. Value, PageText: string;
  823. begin
  824. Result := False;
  825. PageText := ConvertToASCII(GetPage(MovieUrl+'/sales'));
  826. Value := TextBefore(PageText, '.jpg" width=', '<td class=w_rowtable_colcover><a href="');
  827. if Value <> '' then
  828. begin
  829. Value := TextBefore(Value, '"><img', '');
  830. if Value <> '' then
  831. Result := ImportFromAmazonRedirect('http://www.imdb.com' + Value);
  832. end;
  833. end;
  834.  
  835. function ImportFromAmazonRedirect(Url: string): Boolean;
  836. var
  837. Value, PageText: string;
  838. begin
  839. Result := False;
  840. PageText := ConvertToASCII(GetPage(Url));
  841. Value := TextBetween(PageText, '<td id="prodImageCell"', '" id="prodImage"');
  842. // Value := StringReplace(TextAfter(Value, ' src="'), '_AA240', '');
  843. Value := StringReplace(Value, TextBetween(Value, '_AA', '_'), '');
  844. Value := StringReplace(TextAfter(Value, ' src="'), '_AA', '');
  845. if Value <> '' then
  846. begin
  847. GetPicture(Value);
  848. Result := True;
  849. end;
  850. end;
  851.  
  852. // ***** Gets summaries for the movie, based on the plot outline given in parameter (that contains the URL to more summaries) *****
  853.  
  854. function ImportSummary(PlotText: string): string;
  855. var
  856. Address, Value, Value2, Value3, Value4, PageText, Longest: string;
  857. begin
  858. Address := TextBetween(PlotText, '<a class="tn15more inline" href="', '" ');
  859. if (Address = '') or (GetOption('DescriptionSelection') = 0) or (GetOption('DescriptionSelection') = 3) then
  860. begin
  861. Value3 := FullTrim(TextBefore(PlotText, '<a class="tn15more inline"', ''));
  862. if Value3 = '' then
  863. Value3 := FullTrim(PlotText);
  864. HTMLRemoveTags(Value3);
  865. HTMLDecode(Value3);
  866. end;
  867. if (Address <> '') and (GetOption('DescriptionSelection') > 0) then
  868. begin
  869. PageText := ConvertToASCII(GetPage('http://www.imdb.com' + Address));
  870. PickListClear;
  871. Longest := '';
  872. Value := TextBetween(PageText, '<p class="plotpar">', '</p>');
  873. PageText := RemainingText;
  874. while Value <> '' do
  875. begin
  876. Value := TextBefore(Value, '<i>', '');
  877. Value := FullTrim(StringReplace(Value, #13#10, ' '));
  878. Value := StringReplace(Value, '<br>', #13#10);
  879. HTMLRemoveTags(Value);
  880. HTMLDecode(Value);
  881. while Pos(' ', Value) > 0 do
  882. Value := StringReplace(Value, ' ', ' ');
  883. if Length(Value) > Length(Longest) then
  884. Longest := Value;
  885. PickListAdd(FullTrim(Value));
  886. Value := TextBetween(PageText, '<p class="plotpar">', '</p>');
  887. PageText := RemainingText;
  888. end;
  889. if (GetOption('BatchMode') > 0) or (GetOption('DescriptionSelection') = 2) then
  890. Value4 := Longest
  891. else
  892. begin
  893. if not PickListExec('Select a description for "' + GetField(fieldOriginalTitle) + '"', Value4) then
  894. Value4 := '';
  895. end;
  896. end;
  897. if Value3 <> '' then
  898. begin
  899. if Value4 <> '' then
  900. begin
  901. Result := Value3 + #13#10 + #13#10 + Value4;
  902. end
  903. else
  904. begin
  905. Result := Value3;
  906. end;
  907. end
  908. else
  909. begin
  910. Result := Value4;
  911. end;
  912. end;
  913.  
  914. // Import awards
  915. procedure ImportAwards;
  916. var
  917. PageText, FullValue, Block, Value, Row: string;
  918. Year, Result, Award, Category: string;
  919. begin
  920. sleep(50);
  921. Value := MovieUrl;
  922. PageText := ConvertToASCII(GetPage(Value+'/awards'));
  923. PageText := TextBetween(PageText, '<table style=', '</table>');
  924. FullValue := '';
  925. while PageText <> '' do
  926. begin
  927. Block := TextBetween(PageText, '<big>', '<big>');
  928. if Block = '' then
  929. begin
  930. Block := PageText;
  931. PageText := '';
  932. end
  933. else
  934. begin
  935. Block := '<big>' + Block;
  936. PageText := '<big>' + RemainingText;
  937. end;
  938. Value := TextBetween(Block, '<big>', '</big>');
  939. Block := RemainingText;
  940. HTMLRemoveTags(Value);
  941. HTMLDecode(Value);
  942. FullValue := FullValue + #13#10 + '- ' + Value;
  943. Year := '';
  944. Result := '';
  945. repeat
  946. Award := '';
  947. Category := '';
  948. Row := TextBetween(Block, '<tr>', '</tr>');
  949. Block := RemainingText;
  950. if (Pos('<th>Year</th><th>Result</th><th>Award</th><th>Category/Recipient(s)</th>', Row) = 0)
  951. and (Pos('<td colspan="4">&nbsp;</td>', Row) = 0) then
  952. begin
  953. if Pos('<a href="/Sections/Awards', Row) > 0 then
  954. begin
  955. Year := TextBetween(Row, '<a href="/Sections/Awards', '</a>');
  956. Row := RemainingText;
  957. Year := FullTrim(TextAfter(Year, '>'));
  958. end;
  959. if Pos('valign="middle"><b>', Row) > 0 then
  960. begin
  961. Result := TextBetween(Row, 'valign="middle"><b>', '</b></td>');
  962. HTMLDecode(Result);
  963. Row := RemainingText;
  964. end;
  965. if Pos('valign="middle">', Row) > 0 then
  966. begin
  967. Award := TextBetween(Row, 'valign="middle">', '</td>');
  968. HTMLDecode(Award);
  969. Row := RemainingText;
  970. end;
  971. if Award <> '' then
  972. FullValue := FullValue + #13#10 + ' ' + Year + ' ' + Result + ' "' + Award + '"';
  973. Category := TextBetween(Row, '<td valign="top">' + #13#10, '<br>');
  974. if Pos('<a href="/name', Category) > 0 then
  975. begin
  976. RemainingText := Category;
  977. Category := '';
  978. end;
  979. HTMLDecode(Category);
  980. Category := FullTrim(Category);
  981. Row := StringReplace(StringReplace(RemainingText, #13#10, ''), '<br>', ', ');
  982. HTMLRemoveTags(Row);
  983. HTMLDecode(Row);
  984. Row := FullTrim(Row);
  985. Row := StringReplace(Row, ' ', '');
  986. Row := StringReplace(Row, ' ,', ',');
  987. if Row = ',' then
  988. Row := '';
  989. if (Row <> '') or (Category <> '') then
  990. begin
  991. FullValue := FullValue + #13#10 + ' ' + Category;
  992. if Row <> '' then
  993. begin
  994. while StrGet(Row, Length(Row)) = ',' do
  995. begin
  996. Delete(Row, Length(Row), 1);
  997. Row := FullTrim(Row);
  998. end;
  999. if Category = '' then
  1000. FullValue := FullValue + Row
  1001. else
  1002. FullValue := FullValue + ': ' + Row;
  1003. end;
  1004. end;
  1005. end;
  1006. until Pos('</tr>', Block) = 0;
  1007. end;
  1008. if FullValue <> '' then
  1009. case GetOption('Awards') of
  1010. 1:
  1011. begin
  1012. if GetField(fieldDescription) <> '' then
  1013. Value := GetField(fieldDescription) + #13#10 + #13#10 + 'AWARDS: ' + FullValue
  1014. else
  1015. Value := 'AWARDS: ' + FullValue;
  1016. SetField(fieldDescription, Value);
  1017. end;
  1018. 2:
  1019. begin
  1020. if GetField(fieldComments) <> '' then
  1021. Value := GetField(fieldComments) + #13#10 + #13#10 + 'AWARDS: ' + FullValue
  1022. else
  1023. Value := 'AWARDS: ' + FullValue;
  1024. SetField(fieldComments, Value);
  1025. end;
  1026. end;
  1027. end;
  1028.  
  1029. // ***** beginning of the program *****
  1030.  
  1031. begin
  1032. // Check StringUtils1 version and update if < version 7
  1033. if StringUtils1_Version < 7 then
  1034. begin
  1035. if ShowWarning('Old version of file "Stringutils1.pas" detected: v'+IntToStr(StringUtils1_Version)+#13#10+'The script requires at least version 7.'+#13#10+'Download and install latest version now ?') = True then
  1036. begin
  1037. UpdateFile := TStringList.Create;
  1038. UpdateFile.Text := GetPage('http://update.antp.be/amc/scripts/StringUtils1.pas');
  1039. UpdateFile.SaveToFile(dirScripts + 'StringUtils1.pas');
  1040. UpdateFile.Free;
  1041. ShowInformation('StringUtils1 has been updated. Please restart IMDB script now. Thank you.');
  1042. Exit;
  1043. end
  1044. else
  1045. begin
  1046. ShowInformation('You can download latest version of "StringUtils1.pas" using script "update scripts" or via http://update.antp.be/amc/scripts');
  1047. Exit;
  1048. end;
  1049. end;
  1050. // Check for current AMC version
  1051. if CheckVersion(3,5,0) then
  1052. begin
  1053. MovieName := '';
  1054. if GetOption('BatchMode') = 2 then
  1055. begin
  1056. MovieName := GetField(fieldURL);
  1057. if Pos('imdb.com', MovieName) = 0 then
  1058. MovieName := '';
  1059. end;
  1060. if MovieName = '' then
  1061. MovieName := GetField(fieldOriginalTitle);
  1062. if MovieName = '' then
  1063. MovieName := GetField(fieldTranslatedTitle);
  1064. if GetOption('BatchMode') = 0 then
  1065. begin
  1066. if not Input('IMDB Import', 'Enter the title or the IMDB URL of the movie:', MovieName) then
  1067. Exit;
  1068. end
  1069. else
  1070. Sleep(500);
  1071. if MovieName <> '' then
  1072. begin
  1073. if Pos('imdb.com', MovieName) > 0 then
  1074. AnalyzeResultsPage(MovieName)
  1075. else
  1076. begin
  1077. MovieName := StringReplace(MovieName, '&', 'and');
  1078. if GetOption('GoogleSearch') = 1 then
  1079. AnalyzeGooglesResultsPage('http://www.google.com/search?num=30&q=site:www.imdb.com/title/+' + UrlEncode(MovieName) + '+/maindetails')
  1080. else
  1081. if GetOption('GoogleSearch') = 2 then
  1082. AnalyzeGooglesResultsPage('http://www.google.com/search?num=30&q=site:www.imdb.com/title/+%22' + UrlEncode(MovieName) + '%22+/maindetails')
  1083. else
  1084. begin
  1085. if (GetOption('BatchMode') > 0) or (GetOption('PopularSearches') = 1) then
  1086. AnalyzeResultsPage(PopularTitleSearchURL + UrlEncode(MovieName))
  1087. else
  1088. AnalyzeResultsPage(FullTitleSearchURL + UrlEncode(MovieName));
  1089. end;
  1090. end;
  1091. end;
  1092. end
  1093. else
  1094. ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  1095. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement