Delphi IdNNTP: download a file from Usenet according to NZB-file

531 Views Asked by At

I have a NZB file, something like this:

<?xml version="1.0" encoding="utf-8" ?>
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
 <head>
   <meta type="title">Your File!</meta>
   <meta type="tag">Example</meta>
 </head>
 <file poster="Joe Bloggs &lt;[email protected]&gt;" 
       date="1071674882" 
       subject="Here's your file! abc-mr2a.r01 (1/2)">
   <groups>
     <group>alt.binaries.newzbin</group>
     <group>alt.binaries.mojo</group>
   </groups>
   <segments>
     <segment bytes="102394" number="1">[email protected]</segment>
     <segment bytes="4501" number="2">[email protected]</segment>
   </segments>
 </file>
</nzb>

Is there any way to download and assemble this file using Indy IdNNTP? I will be grateful for any sample code. Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

Actually, it was pretty easy:

  Xml := TXmlVerySimple.Create;
  Xml.Text:=recieved_nzb;

  //Each <file> section
  ChildNodes := Xml.Root.ChildNodes;
  for q := 0 to ChildNodes.Count - 1 do
    begin    
      IdNNTP1.SelectGroup(ChildNodes.Items[q].Find('groups').Find('group').Text);
      SegmentNodes:=ChildNodes.Items[q].Find('segments').ChildNodes;

      //Each <segment> (message)
      for w := 0 to SegmentNodes.Count - 1 do
      begin
          idNNTP1.GetArticle(SegmentNodes.Items[w].Text,IdMessage1);
          IdMessage1.SaveToFile('c:\!!!!\'+SegmentNodes.Items[w].Text, false);
          Application.ProcessMessages;
      end;
    end;