@@ -14,16 +14,34 @@ namespace BencodeNET.Parsing
1414 /// </summary>
1515 public class TorrentParser : BObjectParser < Torrent >
1616 {
17+ /// <summary>
18+ /// The parsing mode used when parsing torrents.
19+ /// You can use <see cref="TorrentParserMode.Tolerant"/> if your torrent files are not always following the torrent specification.
20+ /// </summary>
21+ public TorrentParserMode ParseMode { get ; set ; }
22+
1723 /// <summary>
1824 /// Creates an instance using the specified <see cref="IBencodeParser"/> for parsing
1925 /// the torrent <see cref="BDictionary"/>.
2026 /// </summary>
2127 /// <param name="bencodeParser">The parser used for parsing the torrent <see cref="BDictionary"/>.</param>
2228 public TorrentParser ( IBencodeParser bencodeParser )
29+ : this ( bencodeParser , TorrentParserMode . Strict )
30+ {
31+ }
32+
33+ /// <summary>
34+ /// Creates an instance using the specified <see cref="IBencodeParser"/> for parsing
35+ /// the torrent <see cref="BDictionary"/>.
36+ /// </summary>
37+ /// <param name="bencodeParser">The parser used for parsing the torrent <see cref="BDictionary"/>.</param>
38+ /// <param name="torrentParserMode">The parsing mode to use.</param>
39+ public TorrentParser ( IBencodeParser bencodeParser , TorrentParserMode torrentParserMode )
2340 {
2441 if ( bencodeParser == null ) throw new ArgumentNullException ( nameof ( bencodeParser ) ) ;
2542
2643 BencodeParser = bencodeParser ;
44+ ParseMode = torrentParserMode ;
2745 }
2846
2947 /// <summary>
@@ -54,7 +72,8 @@ public override Torrent Parse(BencodeStream stream)
5472 /// <returns>A <see cref="Torrent"/> matching the input.</returns>
5573 protected Torrent CreateTorrent ( BDictionary data )
5674 {
57- EnsureValidTorrentData ( data ) ;
75+ if ( ParseMode == TorrentParserMode . Strict )
76+ EnsureValidTorrentData ( data ) ;
5877
5978 var info = data . Get < BDictionary > ( TorrentFields . Info ) ;
6079
0 commit comments