@@ -347,6 +347,8 @@ private void FixEncodingInDictionary(BDictionary data, Encoding encoding)
347347 /// <returns>A list of list of trackers (announce URLs).</returns>
348348 protected virtual IList < IList < string > > ParseTrackers ( BDictionary data , Encoding encoding )
349349 {
350+ // Specification: http://bittorrent.org/beps/bep_0012.html
351+
350352 var trackerList = new List < IList < string > > ( ) ;
351353 var primary = new List < string > ( ) ;
352354 trackerList . Add ( primary ) ;
@@ -358,18 +360,31 @@ protected virtual IList<IList<string>> ParseTrackers(BDictionary data, Encoding
358360 primary . Add ( announce ) ;
359361 }
360362
361- // Get the 'announce-list' list´s
362- var announceLists = data . Get < BList > ( TorrentFields . AnnounceList ) ? . AsType < BList > ( ) as IList < BList > ;
363- if ( announceLists ? . Any ( ) == true )
363+ // Get the 'announce-list' list's
364+ var announceLists = data . Get < BList > ( TorrentFields . AnnounceList ) ;
365+ if ( announceLists == null )
366+ return trackerList ;
367+
368+ // According to the specification it should be a list of lists
369+ if ( announceLists . All ( x => x is BList ) )
364370 {
365- // Add the first list to the primary list and remove duplicates
366- primary . AddRange ( announceLists . First ( ) . AsStrings ( encoding ) ) ;
367- trackerList [ 0 ] = primary . Distinct ( ) . ToList ( ) ;
371+ var lists = announceLists . AsType < BList > ( ) as IList < BList > ;
372+ if ( lists . Any ( ) )
373+ {
374+ // Add the first list to the primary list and remove duplicates
375+ primary . AddRange ( lists . First ( ) . AsStrings ( encoding ) ) ;
376+ trackerList [ 0 ] = primary . Distinct ( ) . ToList ( ) ;
368377
369- // Add the other lists to the lists of lists of announce urls
370- trackerList . AddRange (
371- announceLists . Skip ( 1 )
372- . Select ( x => x . AsStrings ( encoding ) . ToList ( ) ) ) ;
378+ // Add the other lists to the lists of lists of announce urls
379+ trackerList . AddRange ( lists . Skip ( 1 ) . Select ( x => x . AsStrings ( encoding ) . ToList ( ) ) ) ;
380+ }
381+ }
382+ // It's not following the specification, it's strings instead of lists
383+ else if ( ParseMode == TorrentParserMode . Tolerant && announceLists . All ( x => x is BString ) )
384+ {
385+ // Add them all to the first list
386+ primary . AddRange ( announceLists . AsStrings ( encoding ) ) ;
387+ trackerList [ 0 ] = primary . Distinct ( ) . ToList ( ) ;
373388 }
374389
375390 return trackerList ;
0 commit comments