TrackerStat.fromJson constructor

TrackerStat.fromJson(
  1. JsonMap rawData
)

Implementation

factory TrackerStat.fromJson(JsonMap rawData) {
  bool handleNumOrBoolToBool(dynamic rawVal) {
    if (rawVal is bool) return rawVal;
    if (rawVal is num || rawVal is int) return rawVal != 0;
    return false;
  }

  return TrackerStat(
    announceState: rawData['announceState'] as num,
    announce: rawData['announce'] as String,
    downloadCount: rawData['downloadCount'] as num,
    hasAnnounced: rawData['hasAnnounced'] as bool,
    hasScraped: rawData['hasScraped'] as bool,
    host: rawData['host'] as String,
    id: rawData['id'] as num,
    isBackup: rawData['isBackup'] as bool,
    lastAnnouncePeerCount: rawData['lastAnnouncePeerCount'] as num,
    lastAnnounceResult: rawData['lastAnnounceResult'] as String,
    lastAnnounceStartTime: rawData['lastAnnounceStartTime'] as num,
    lastAnnounceSucceeded: rawData['lastAnnounceSucceeded'] as bool,
    lastAnnounceTime: rawData['lastAnnounceTime'] as num,
    // lastAnnounceTimedOut return int whtn rpc<16 and return bool currently.
    lastAnnounceTimedOut:
        handleNumOrBoolToBool(rawData['lastAnnounceTimedOut']),
    lastScrapeResult: rawData['lastScrapeResult'] as String,
    lastScrapeStartTime: rawData['lastScrapeStartTime'] as num,
    lastScrapeSucceeded: rawData['lastScrapeSucceeded'] as bool,
    lastScrapeTime: rawData['lastScrapeTime'] as num,
    // lastScrapeTimedOut return int before rpc<16 and return bool currently.
    lastScrapeTimedOut: handleNumOrBoolToBool(rawData['lastScrapeTimedOut']),
    leecherCount: rawData['leecherCount'] as num,
    nextAnnounceTime: rawData['nextAnnounceTime'] as num,
    nextScrapeTime: rawData['nextScrapeTime'] as num,
    scrapeState: rawData['scrapeState'] as num,
    scrape: rawData['scrape'] as String,
    seederCount: rawData['seederCount'] as num,
    tier: rawData['tier'] as num,
    sitename: rawData['sitename'] as String?,
  );
}