OpenSubtitles API を使用して映画の字幕をダウンロードしたいのですが、完全に機能する例がどこにも見つかりません。私が見つけたのはこれだけでした:
http://www.yanniel.info/2012/01/open-subtitles-api-in-delphi.html
ここで言うことはすべてやりましたが、不完全です。ログインして字幕を見つけましたが、最終的にファイルをダウンロードする方法がわかりません?
編集:これは私がこれまで行ったことです。
unit OpensubtitlesAPI;
interface
uses
IdHTTP, Classes, SysUtils;
function LogIn(aUsername, aPassword,
aLanguage, aUserAgent: string): string;
function LogOut(aToken: string): string;
function SearchSubtitles(aToken, aSublanguageID,
aMovieHash: string;
aMovieByteSize: Cardinal): string; overload;
function SearchSubtitles(aToken, aSublanguageID: string;
aImdbID: Cardinal): string; overload;
function SearchSubtitles(aToken, aSublanguageID,
aQuery: string): string; overload;
implementation
function XML_RPC(aRPCRequest: string): string;
const
cURL= 'http://api.opensubtitles.org/xml-rpc';
var
lHTTP: TIdHTTP;
Source,
ResponseContent: TStringStream;
begin
lHTTP := TIdHTTP.Create(nil);
lHTTP.Request.ContentType := 'text/xml';
lHTTP.Request.Accept := '*/*';
lHTTP.Request.Connection := 'Keep-Alive';
lHTTP.Request.Method := 'POST';
lHTTP.Request.UserAgent := 'OS Test User Agent';
Source := TStringStream.Create(aRPCRequest);
ResponseContent:= TStringStream.Create;
try
try
lHTTP.Post(cURL, Source, ResponseContent);
Result:= ResponseContent.DataString;
except
Result:= '';
end;
finally
lHTTP.Free;
Source.Free;
ResponseContent.Free;
end;
end;
function LogIn(aUsername, aPassword, aLanguage, aUserAgent: string): string;
const
LOG_IN = '<?xml version="1.0"?>' +
'<methodCall>' +
' <methodName>LogIn</methodName>' +
' <params>' +
' <param>' +
' <value><string>%0:s</string></value>' +
' </param>' +
' <param>' +
' <value><string>%1:s</string></value>' +
' </param>' +
' <param>' +
' <value><string>%2:s</string></value>' +
' </param>' +
' <param>' +
' <value><string>%3:s</string></value>' +
' </param>' +
' </params>' +
'</methodCall>';
begin
//TODO: XML Encoding
Result:= XML_RPC(Format(LOG_IN, [aUsername, aPassword, aLanguage, aUserAgent]));
end;
function LogOut(aToken: string): string;
const
LOG_OUT = '<?xml version="1.0"?>' +
'<methodCall>' +
' <methodName>LogOut</methodName>' +
' <params>' +
' <param>' +
' <value><string>%0:s</string></value>' +
' </param>' +
' </params>' +
'</methodCall>';
begin
//TODO: XML Encoding
Result:= XML_RPC(Format(LOG_OUT, [aToken]));
end;
function SearchSubtitles(aToken, aSublanguageID, aMovieHash: string; aMovieByteSize: Cardinal): string;
const
SEARCH_SUBTITLES = '<?xml version="1.0"?>' +
'<methodCall>' +
' <methodName>SearchSubtitles</methodName>' +
' <params>' +
' <param>' +
' <value><string>%0:s</string></value>' +
' </param>' +
' <param>' +
' <value>' +
' <array>' +
' <data>' +
' <value>' +
' <struct>' +
' <member>' +
' <name>sublanguageid</name>' +
' <value><string>%1:s</string>' +
' </value>' +
' </member>' +
' <member>' +
' <name>moviehash</name>' +
' <value><string>%2:s</string></value>' +
' </member>' +
' <member>' +
' <name>moviebytesize</name>' +
' <value><double>%3:d</double></value>' +
' </member>' +
' </struct>' +
' </value>' +
' </data>' +
' </array>' +
' </value>' +
' </param>' +
' </params>' +
'</methodCall>';
begin
//TODO: XML Encoding
Result:= XML_RPC(Format(SEARCH_SUBTITLES, [aToken, aSublanguageID, aMovieHash, aMovieByteSize]));
end;
function SearchSubtitles(aToken, aSublanguageID: string;
aImdbID: Cardinal): string;
const
SEARCH_SUBTITLES = '<?xml version="1.0"?>' +
'<methodCall>' +
' <methodName>SearchSubtitles</methodName>' +
' <params>' +
' <param>' +
' <value><string>%0:s</string></value>' +
' </param>' +
' <param>' +
' <value>' +
' <array>' +
' <data>' +
' <value>' +
' <struct>' +
' <member>' +
' <name>sublanguageid</name>' +
' <value><string>%1:s</string>' +
' </value>' +
' </member>' +
' <member>' +
' <name>imdbid</name>' +
' <value><string>%2:d</string></value>' +
' </member>' +
' </struct>' +
' </value>' +
' </data>' +
' </array>' +
' </value>' +
' </param>' +
' </params>' +
'</methodCall>';
begin
//TODO: XML Encoding
Result:= XML_RPC(Format(SEARCH_SUBTITLES, [aToken, aSublanguageID, aImdbID]));
end;
function SearchSubtitles(aToken, aSublanguageID,
aQuery: string): string;
const
SEARCH_SUBTITLES = '<?xml version="1.0"?>' +
'<methodCall>' +
' <methodName>SearchSubtitles</methodName>' +
' <params>' +
' <param>' +
' <value><string>%0:s</string></value>' +
' </param>' +
' <param>' +
' <value>' +
' <array>' +
' <data>' +
' <value>' +
' <struct>' +
' <member>' +
' <name>sublanguageid</name>' +
' <value><string>%1:s</string>' +
' </value>' +
' </member>' +
' <member>' +
' <name>query</name>' +
' <value><string>%2:s</string></value>' +
' </member>' +
' </struct>' +
' </value>' +
' </data>' +
' </array>' +
' </value>' +
' </param>' +
' </params>' +
'</methodCall>';
begin
//TODO: XML Encoding
Result:= XML_RPC(Format(SEARCH_SUBTITLES, [aToken, aSublanguageID, aQuery]));
end;
end.
そして最後に、C++ Builder を使用して次の作業を行いました。
void __fastcall TForm1::Button1Click(TObject *Sender)
{
UnicodeString response = LogIn("", "", "en", "OS Test User Agent");
XMLDocument1->XML->Text = response;
XMLDocument1->Active = true;
UnicodeString token = XMLDocument1->ChildNodes->Nodes[1]->GetChildNodes()->Nodes[0]->
GetChildNodes()->Nodes[0]->GetChildNodes()->Nodes[0]->
GetChildNodes()->Nodes[0]->GetChildNodes()->Nodes[0]->
GetChildNodes()->Nodes[1]->GetChildNodes()->Nodes[0]->
GetText();
Memo1->Text = SearchSubtitles(token, "en", "7d9cd5def91c9432", 735934464);
LogOut(token);
}
これを実行すると、次のような応答が返されます。
<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>status</name>
<value>
<string>200 OK</string>
</value>
</member>
<member>
<name>data</name>
<value>
<boolean>0</boolean>
</value>
</member>
<member>
<name>seconds</name>
<value>
<double>0.008</double>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>
それで、次は何ですか?ファイル (字幕) の場所を取得するには? ありがとう。