Code: Select all
const
csKinopoiskTitle = '<title>(.*?)</title>';
csKinopoiskImage = 'src="([^"]*/images/film.*?/.*?)"';
csKinopoiskOriginalName = '<span style="color: \#666; font-size: 13px">(.*?)</span>';
csKinopoiskRatingMPAA = '<img src='#39'/images/mpaa/(.*?).gif'#39' height=11 alt';
csKinopoiskCast = 'В главных ролях:(.*?)</div>';
csKinopoiskCastActor = '<li.*?<a href="/name/(.*?)/".*?>(.*?)</a>';
csKinopoiskIMDB = 'IMDB: (.*?)</div>';
csKinopoiskRating = 'text-decoration: none">(.*?)<span style="font:100';
csKinopoiskDescripton = 'itemprop="description".*?>(.*?)</td></tr>';
csKinopoiskActorImage = 'src='#39'/images/actor/(.*?)'#39;
function GetLink(const aLink: string): string;
begin
if aLink <> '' then
if Pos('://', aLink) > 0 then
Result := aLink
else
Result := 'http://www.kinopoisk.ru' + aLink
else
Result := ''
end;
function FindMediaInfo(const aRegEx: string; var aMatch: string): Boolean;
begin
with TRegExpr.Create(aRegEx, PCRE_SINGLELINE) do try
Result := Search(HtmlText);
if Result then
aMatch := Match;
finally
Free
end
end;
function TrimCommas(const aText: string): string;
var
i, j: Integer;
begin
Result := '';
if aText <> '' then begin
i := 1; j := Length(aText);
while (i <= j) and (aText[i] in ['.', ',']) do
Inc(i);
while (j > i) and (aText[j] in ['.', ',']) do
Dec(j);
if i <= j then
Result := Copy(aText, i, j - i + 1)
end
end;
function AddMediaInfo(aImdbItem: THmsIMDBItem; const aRegExpr, aCaption: string;
const aImageRegExpr: string = ''): THmsIMDBItem;
var
sMatch, aCaptionValue: string;
begin
Result := nil;
if FindMediaInfo(aRegExpr, sMatch) then begin
// *** Если добавляем жанр, то убираем ',... слова' иначе как всегда - 03/10/2013
if aCaption = 'Жанр' then
aCaptionValue := ReplaceStr(TrimCommas(ReplaceStr(HmsHtmlToText(sMatch), '|', '')), ',... слова', '')
else
aCaptionValue := TrimCommas(ReplaceStr(HmsHtmlToText(sMatch), '|', ''));
// ***
Result := aImdbItem.ChildList.AddItem(aCaption, aCaptionValue);
if (aImageRegExpr <> '') and FindMediaInfo(aImageRegExpr, sMatch) then
Result.Image := GetLink(sMatch)
end
end;
procedure AddMediaInfoMulti(aImdbItem: THmsIMDBItem; const aParams: array of string);
var
i: Integer;
begin
i := 0;
while i < Length(aParams) do begin
AddMediaInfo(aImdbItem, aParams[i], aParams[i + 1]);
Inc(i, 2)
end
end;
procedure AddMediaInfoGeneric(aImdbItem: THmsIMDBItem; const aPrefixRegEx: array of string);
const
GenericRegEx = '</td>(.*?)(</td>|keywordLink).*?</tr>';
var
i: Integer;
sCaption: string;
begin
for i := 0 to Length(aPrefixRegEx) - 1 do begin
sCaption := ReplaceStr(aPrefixRegEx[i], '\', '');
AddMediaInfo(aImdbItem, aPrefixRegEx[i] + GenericRegEx,
UpperCase(Copy(sCaption, 1, 1)) + Copy(sCaption, 2, Length(sCaption) - 1))
end
end;
procedure AddCastInfo(aImdbItem: THmsIMDBItem);
var
CastItem: THmsIMDBItem;
i: Integer;
sCastInfo, sPriorActor: string;
begin
if FindMediaInfo(csKinopoiskCast, sCastInfo) then begin
CastItem := aImdbItem.ChildList.AddItem('В главных ролях', '');
i := Pos('Роли дублировали', sCastInfo);
if i > 0 then
sCastInfo := Copy(sCastInfo, 1, i - 1);
with TRegExpr.Create(csKinopoiskCastActor, PCRE_SINGLELINE) do try
sPriorActor := '';
if Search(sCastInfo) then repeat
if sPriorActor <> Match(2) then begin
sPriorActor := Match(2);
CastItem.ChildList.AddItem(HmsHtmlToText(sPriorActor), '', 'http://www.kinopoisk.ru/images/actor/' + Match + '.jpg')
end
until not SearchAgain;
finally
Free
end
end
end;
procedure SetMediaItemProperties(aImdbItem: THmsIMDBItem; const aParams: array of string);
var
i: Integer;
ImdbParam: THmsIMDBItem;
sPropertyName, sPropertyValue: string;
begin
i := 0;
while i < Length(aParams) do begin
ImdbParam := aImdbItem.ChildList.FindItem(aParams[i]);
if ImdbParam <> nil then begin
sPropertyName := aParams[i + 1];
sPropertyValue := ImdbParam.Value;
if (sPropertyName = 'mpTitle') and (mpTrack > 0) then
sPropertyValue := sPropertyValue + Format(' [%d]', [mpTrack])
else if sPropertyName = 'mpYear' then
HmsRegExMatch('(\d+)', sPropertyValue, sPropertyValue);
HmsSetMediaItemProperty(sPropertyName, sPropertyValue);
end;
Inc(i, 2)
end
end;
var
i: Integer;
IMDBItem, ActorItem, TitleItem: THmsIMDBItem;
IMDBInfo: THmsIMDBInfo;
sActorList, sHeader, sLink: string;
begin
if ResultsViewMode = 2 then begin
sLink := HmsGetResultsValue(10);
if (sLink <> '') and HmsRegExMatch('http://www\.kinopoisk\.ru(/.*)', sLink, sLink) then
HtmlText := HmsSendRequestEx('www.kinopoisk.ru', sLink, 'GET', '',
'http://www.kinopoisk.ru'#13#10'Accept: */*'#13#10'Accept-Encoding: gzip, deflate', '', 80, 0, sHeader, True)
else
HtmlText := '';
end;
if HtmlText <> '' then begin
IMDBInfo := THmsIMDBInfo.Create;
try
IMDBItem := IMDBInfo.AddItem('Кинопоиск', '');
AddMediaInfo(IMDBItem, csKinopoiskTitle, 'Название', csKinopoiskImage);
AddMediaInfo(IMDBItem, csKinopoiskOriginalName, 'Оригинальное название');
AddMediaInfoGeneric(IMDBItem, ['год', 'страна', 'слоган', 'режиссер',
'сценарий', 'продюсер', 'оператор',
'композитор', 'жанр', 'бюджет',
'премьера \(мир\)', 'премьера \(РФ\)',
'релиз на DVD', 'релиз на Blu-Ray', 'время']);
AddMediaInfoMulti(IMDBItem, [csKinopoiskRatingMPAA, 'Рейтинг MPAA',
csKinopoiskIMDB, 'Рейтинг IMDB',
csKinopoiskRating, 'Рейтинг',
csKinopoiskDescripton, 'Описание']);
AddCastInfo(IMDBItem);
MediaInfo := IMDBInfo.SaveToString;
SetMediaItemProperties(IMDBItem, ['Название', 'mpTitle', 'Жанр', 'mpGenre',
'Продюсер', 'mpProducer', 'Режиссер', 'mpDirector',
'Год', 'mpYear', 'Рейтинг MPAA', 'mpRating',
'Описание', 'mpComment']);
{ ActorItem := IMDBItem.ChildList.FindItem('В главных ролях\0');
if ActorItem <> nil then
HmsSetMediaItemProperty('mpActor', ActorItem.Name);}
// Actor List
ActorItem := IMDBItem.ChildList.FindItem('В главных ролях');
if ActorItem <> nil then begin
sActorList := '';
for i := 0 to ActorItem.ChildList.Count - 1 do begin
if sActorList <> '' then
sActorList := sActorList + ', ';
sActorList := sActorList + ActorItem.ChildList[i].Name;
end;
if sActorList <> '' then
HmsSetMediaItemProperty('mpActor', sActorList);
end;
TitleItem := IMDBItem.ChildList.FindItem('Название');
if (TitleItem <> nil) and (TitleItem.Image <> '') then
HmsSetMediaItemProperty('mpThumbnail', TitleItem.Image);
finally
IMDBInfo.Free
end
end
end.