TorrentInfo.fromJson constructor

TorrentInfo.fromJson(
  1. JsonMap rawData
)

Implementation

factory TorrentInfo.fromJson(JsonMap rawData) {
  TorrentId? buildId() {
    final rawId = rawData[TorrentGetArgument.id.argName] as num?;
    final rawHash = rawData[TorrentGetArgument.hashString.argName] as String?;
    return !(rawId == null && rawHash == null)
        ? TorrentId(id: rawId?.toInt(), hashStr: rawHash)
        : null;
  }

  IdleLimitMode? buildSeedIdleMode() {
    final rawMode = rawData[TorrentGetArgument.seedIdleMode.argName] as num?;
    return rawMode != null ? IdleLimitMode.code(rawMode.toInt()) : null;
  }

  RatioLimitMode? buildSeedRatioMode() {
    final rawMode = rawData[TorrentGetArgument.seedRatioMode.argName] as num?;
    return rawMode != null ? RatioLimitMode.code(rawMode.toInt()) : null;
  }

  TrackerList? buildTrackerList() {
    final input = rawData[TorrentGetArgument.trackerList.argName] as String?;
    return input != null
        ? trackerListCodec.decode(input).map((e) => e.toList()).toList()
        : null;
  }

  return TorrentInfo(
    activityDate: rawData[TorrentGetArgument.activityDate.argName] as num?,
    addedDate: rawData[TorrentGetArgument.addedDate.argName] as num?,
    availability: rawData[TorrentGetArgument.availability.argName] != null
        ? Availability.fromJson(
            rawData[TorrentGetArgument.availability.argName])
        : null,
    bandwidthPriority:
        rawData[TorrentGetArgument.bandwidthPriority.argName] as num?,
    comment: rawData[TorrentGetArgument.comment.argName] as String?,
    corruptEver: rawData[TorrentGetArgument.corruptEver.argName] as num?,
    creator: rawData[TorrentGetArgument.creator.argName] as String?,
    dateCreated: rawData[TorrentGetArgument.dateCreated.argName] as num?,
    desiredAvailable:
        rawData[TorrentGetArgument.desiredAvailable.argName] as num?,
    doneDate: rawData[TorrentGetArgument.doneDate.argName] as num?,
    downloadDir: rawData[TorrentGetArgument.downloadDir.argName] as String?,
    downloadedEver:
        rawData[TorrentGetArgument.downloadedEver.argName] as num?,
    downloadLimit: rawData[TorrentGetArgument.downloadLimit.argName] as num?,
    downloadLimited:
        rawData[TorrentGetArgument.downloadLimited.argName] as bool?,
    editDate: rawData[TorrentGetArgument.editDate.argName] as num?,
    error: rawData[TorrentGetArgument.error.argName] as num?,
    errorString: rawData[TorrentGetArgument.errorString.argName] as String?,
    eta: rawData[TorrentGetArgument.eta.argName] as num?,
    etaIdle: rawData[TorrentGetArgument.etaIdle.argName] as num?,
    fileCount: rawData[TorrentGetArgument.fileCount.argName] as num?,
    files: (rawData[TorrentGetArgument.files.argName] as List?)
        ?.map((file) => File.fromJson(file))
        .toList(),
    fileStats: (rawData[TorrentGetArgument.fileStats.argName] as List?)
        ?.map((fileStat) => FileStat.fromJson(fileStat))
        .toList(),
    group: rawData[TorrentGetArgument.group.argName] as String?,
    haveUnchecked: rawData[TorrentGetArgument.haveUnchecked.argName] as num?,
    haveValid: rawData[TorrentGetArgument.haveValid.argName] as num?,
    honorsSessionLimits:
        rawData[TorrentGetArgument.honorsSessionLimits.argName] as bool?,
    id: buildId(),
    isFinished: rawData[TorrentGetArgument.isFinished.argName] as bool?,
    isPrivate: rawData[TorrentGetArgument.isPrivate.argName] as bool?,
    isStalled: rawData[TorrentGetArgument.isStalled.argName] as bool?,
    labels: (rawData[TorrentGetArgument.labels.argName] as List?)
        ?.map((label) => label.toString())
        .toList(),
    leftUntilDone: rawData[TorrentGetArgument.leftUntilDone.argName] as num?,
    magnetLink: rawData[TorrentGetArgument.magnetLink.argName] as String?,
    manualAnnounceTime:
        rawData[TorrentGetArgument.manualAnnounceTime.argName] as num?,
    maxConnectedPeers:
        rawData[TorrentGetArgument.maxConnectedPeers.argName] as num?,
    metadataPercentComplete:
        rawData[TorrentGetArgument.metadataPercentComplete.argName] as num?,
    name: rawData[TorrentGetArgument.name.argName] as String?,
    peerLimit: rawData[TorrentGetArgument.peerLimit.argName] as num?,
    peers: (rawData[TorrentGetArgument.peers.argName] as List?)
        ?.map((peer) => Peer.fromJson(peer))
        .toList(),
    peersConnected:
        rawData[TorrentGetArgument.peersConnected.argName] as num?,
    peersFrom: rawData[TorrentGetArgument.peersFrom.argName] != null
        ? PeersFrom.fromJson(rawData[TorrentGetArgument.peersFrom.argName])
        : null,
    peersGettingFromUs:
        rawData[TorrentGetArgument.peersGettingFromUs.argName] as num?,
    peersSendingToUs:
        rawData[TorrentGetArgument.peersSendingToUs.argName] as num?,
    percentComplete:
        rawData[TorrentGetArgument.percentComplete.argName] as num?,
    percentDone: rawData[TorrentGetArgument.percentDone.argName] as num?,
    pieces: rawData[TorrentGetArgument.pieces.argName] as String?,
    pieceCount: rawData[TorrentGetArgument.pieceCount.argName] as num?,
    pieceSize: rawData[TorrentGetArgument.pieceSize.argName] as num?,
    priorities: buildPriorities(
        rawData[TorrentGetArgument.priorities.argName] as List?),
    primaryMimeType:
        rawData[TorrentGetArgument.primaryMimeType.argName] as String?,
    queuePosition: rawData[TorrentGetArgument.queuePosition.argName] as num?,
    rateDownload: rawData[TorrentGetArgument.rateDownload.argName] as num?,
    rateUpload: rawData[TorrentGetArgument.rateUpload.argName] as num?,
    recheckProgress:
        rawData[TorrentGetArgument.recheckProgress.argName] as num?,
    secondsDownloading:
        rawData[TorrentGetArgument.secondsDownloading.argName] as num?,
    secondsSeeding:
        rawData[TorrentGetArgument.secondsSeeding.argName] as num?,
    seedIdleLimit: rawData[TorrentGetArgument.seedIdleLimit.argName] as num?,
    seedIdleMode: buildSeedIdleMode(),
    seedRatioLimit:
        rawData[TorrentGetArgument.seedRatioLimit.argName] as num?,
    seedRatioMode: buildSeedRatioMode(),
    sequentialDownload:
        rawData[TorrentGetArgument.sequentialDownload.argName] as bool?,
    sizeWhenDone: rawData[TorrentGetArgument.sizeWhenDone.argName] as num?,
    startDate: rawData[TorrentGetArgument.startDate.argName] as num?,
    status: rawData[TorrentGetArgument.status.argName] != null
        ? TorrentStatus.fromVal(
            (rawData[TorrentGetArgument.status.argName] as num).toInt())
        : null,
    trackers: (rawData[TorrentGetArgument.trackers.argName] as List?)
        ?.map((tracker) => Tracker.fromJson(tracker))
        .toList(),
    trackerList: buildTrackerList(),
    trackerStats: (rawData[TorrentGetArgument.trackerStats.argName] as List?)
        ?.map((trackerStat) => TrackerStat.fromJson(trackerStat))
        .toList(),
    totalSize: rawData[TorrentGetArgument.totalSize.argName] as num?,
    torrentFile: rawData[TorrentGetArgument.torrentFile.argName] as String?,
    uploadedEver: rawData[TorrentGetArgument.uploadedEver.argName] as num?,
    uploadLimit: rawData[TorrentGetArgument.uploadLimit.argName] as num?,
    uploadLimited: rawData[TorrentGetArgument.uploadLimited.argName] as bool?,
    uploadRatio: rawData[TorrentGetArgument.uploadRatio.argName] as num?,
    wanted: buildWanted(rawData[TorrentGetArgument.wanted.argName] as List?),
    webseeds: (rawData[TorrentGetArgument.webseeds.argName] as List?)
        ?.map((webseed) => webseed as String)
        .toList(),
    webseedsSendingToUs:
        rawData[TorrentGetArgument.webseedsSendingToUs.argName] as num?,
  );
}