'Internal constructor.
@param download The Download this state belongs too.
@param status The status of the Download (DLSTATUS_*)
@param progress The general progress of the Download.
@param stats The BT engine statistics for the Download.
@param filepieceranges The range of pieces that we are interested in.
The get_pieces_complete() returns only completeness information about
this range. This is used for playing a video in a multi-torrent file.
@param logmsgs A list of messages from the BT engine which may be of'

def __init__(self, download, status, error, progress, stats=None, seeding_stats=None, filepieceranges=None, logmsgs=None, peerid=None, videoinfo=None):

    self._logger = logging.getLogger(self.__class__.__name__)
    self.download = download
    self.filepieceranges = filepieceranges
    self.logmsgs = logmsgs
    self.vod_status_msg = None
    self.seeding_stats = seeding_stats
    self.haveslice = None
    self.stats = None
    self.length = None
    name = self.download.get_def().get_name()
    if (stats is None):
        self._logger.debug("stats    is    None    '%s'", name)
        self.error = error
        self.progress = progress
        if (self.error is not None):
            self.status = DLSTATUS_STOPPED_ON_ERROR
        else:
            self.status = status
    elif (error is not None):
        self._logger.debug("error    is    not    None    '%s'", name)
        self.error = error
        self.progress = 0.0
        self.status = DLSTATUS_STOPPED_ON_ERROR
    elif ((status is not None) and (not (status in [DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING]))):
        self._logger.debug("we    have    status    and    it    is    not    downloading    or    seeding    '%s'", name)
        self.error = error
        self.status = status
        if (self.status == DLSTATUS_WAITING4HASHCHECK):
            self.progress = 0.0
        else:
            self.progress = stats['frac']
            if ('wanted' in stats):
                self.length = stats['wanted']
    else:
        self._logger.debug("copy    from    stats    '%s'", name)
        self.error = None
        self.progress = stats['frac']
        if (stats['frac'] == 1.0):
            self.status = DLSTATUS_SEEDING
        else:
            self.status = DLSTATUS_DOWNLOADING
        self.stats = stats
    if (stats and stats.get('stats', None)):
        if (not self.filepieceranges):
            self.haveslice = stats['stats'].have
        else:
            self.haveslice_total = stats['stats'].have
            selected_files = self.download.get_selected_files()
            totalpieces = 0
            for (t, tl, o, f) in self.filepieceranges:
                if ((f in selected_files) or (not selected_files)):
                    diff = (tl - t)
                    totalpieces += diff
            haveslice = ([False] * totalpieces)
            have = 0
            index = 0
            for (t, tl, o, f) in self.filepieceranges:
                if ((f in selected_files) or (not selected_files)):
                    for piece in range(t, tl):
                        haveslice[index] = stats['stats'].have[piece]
                        if haveslice[index]:
                            have += 1
                        index += 1
            self.haveslice = haveslice
            if ((have == len(haveslice)) and (self.status == DLSTATUS_DOWNLOADING)):
                self.status = DLSTATUS_SEEDING
                self.progress = 1.0
