home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2006 March / maximum-cd-2006-03.iso / Software / Apps / Juice22Setup.exe / compat / 2x / iPodder.py < prev   
Encoding:
Python Source  |  2005-07-28  |  3.3 KB  |  91 lines

  1. import ipodder
  2.  
  3. class Enclosure:
  4.     """Support shelved iPodder.Enclosure objects, which were moved to
  5.     ipodder.core after the 2.1 release.  This is a straight copy from
  6.     core.py v1.1."""
  7.     
  8.     def __init__(self, url, feed, length, marked, item_title, item_description, item_link):
  9.         """Initialise the `Enclosure`.
  10.         
  11.         url -- the url of the enclosure
  12.         feed -- the feed it's in
  13.         length -- the length of the enclosure
  14.         marked -- marked for download?
  15.         title -- title of the enclosing item"""
  16.         
  17.         self.url = url
  18.         self.feed = feed
  19.         self.marked = marked # for download
  20.         self.length = length
  21.         self.item_title = item_title
  22.         self.creation_time = time.localtime()
  23.         self.download_started = None
  24.         self.download_completed = None
  25.         self.description = item_description
  26.         self.item_link = item_link
  27.         self.status = "new"
  28.         
  29.     def unmark(self):
  30.         "Unmark this enclosure for download."
  31.         self.marked = False
  32.  
  33.     def GetStatus(self):
  34.         """Return a displayable version of self.status.
  35.         AG: Superseded by i18n lookups in str_dl_(state)"""
  36.         if self.status == "new":
  37.             return "New"
  38.         if self.status == "queued":
  39.             return "Queued"
  40.         if self.status == "downloading":
  41.             return "Downloading"
  42.         if self.status == "cancelled":
  43.             return "Cancelled"
  44.         if self.status == "downloaded":
  45.             return "Finished"
  46.         if self.status == "partial":
  47.             return "Partially downloaded"
  48.         log.debug("Enclosure has unknown status %s" % self.status)
  49.         return "Unknown"
  50.     
  51.     def GetStatusDownloadSpeed(self):
  52.         """Return a displayable version of self.status.  i18n lookups
  53.         go in here."""
  54.         retval = ""
  55.         if self.status == "downloading" and hasattr(self,"grabber") and self.grabber:
  56.             retval += "%.1f%%; %.1fkB/s" % ((100*self.grabber.fraction_done),self.grabber.download_rate/1024)
  57.         return retval
  58.  
  59.     def get_target_status(self):
  60.         """Just an alias for a method of the containing feed.
  61.         See ipodder.Feed.get_target_status()."""
  62.         return self.feed.get_target_status(self)
  63.     
  64.     #We have to remove the feed object to make this pickleable.
  65.     def __getstate__(self):
  66.         state = self.__dict__.copy()
  67.         state['feedid'] = self.feed.id
  68.         del state['feed']
  69.         return state
  70.     
  71.     def __setstate__(self,dict):
  72.         self.__dict__.update(dict)
  73.         self.feed = ipodder.get_feeds_instance()[self.feedid]
  74.         del self.feedid
  75.         if not hasattr(self,"creation_time"):
  76.             self.creation_time = time.localtime()
  77.         if not hasattr(self,"download_started"):
  78.             self.download_started = None
  79.         if not hasattr(self,"download_completed"):
  80.             self.download_completed = None
  81.         if not hasattr(self,"status"):
  82.             self.status = "downloaded"
  83.         if not hasattr(self,"description"):
  84.             self.description = None
  85.         if not hasattr(self,"item_link"):
  86.             self.item_link = None
  87.             
  88.     def __str__(self): 
  89.         "Return our filename as a string."
  90.         return basename(self.feed.get_target_filename(self))
  91.