def test_givenFeedWithSomeVodcastsWhenReferenceDateGivenThenAllNewerFeedsWillBeDownloaded(self): feed_content = r'''<?xml version='1.0' encoding='UTF-8'?> <rss version='2.0'> <channel> <title>Extra3</title> <item> <title>Extra 3 one</title> <description>Tatort Taliban; Jasmin trifft: Frau zu Guttenberg</description> <pubDate>Tue, 26 Oct 2010 11:53:49 +0200</pubDate> <enclosure url='http://media.ndr.de/download/podcasts/extradrei196/TV-20101063-2220-5801.h264.mp4' type='video/mp4' /> <guid isPermaLink='false'>TV-20101026-2220-5801-V</guid> <link>http://media.ndr.de/download/podcasts/extradrei196/TV-20101026-2220-5801.h264.mp4</link> </item> <item> <title>Extra 3 two</title> <description>Tatort Taliban; Jasmin trifft: Frau zu Guttenberg</description> <pubDate>Tue, 27 Oct 2010 11:53:49 +0200</pubDate> <enclosure url='http://media.ndr.de/download/podcasts/extradrei196/TV-20101027-2220-5801.h264.mp4' type='video/mp4' /> <guid isPermaLink='false'>TV-20101027-2220-5801-V</guid> <link>http://media.ndr.de/download/podcasts/extradrei196/TV-20101027-2220-5801.h264.mp4</link> </item> <item> <title>Extra 3 three</title> <description>Tatort Taliban; Jasmin trifft: Frau zu Guttenberg</description> <pubDate>Tue, 28 Oct 2010 11:53:49 +0200</pubDate> <enclosure url='http://media.ndr.de/download/podcasts/extradrei196/TV-20101028-2220-5801.h264.mp4' type='video/mp4' /> <guid isPermaLink='false'>TV-20101028-2220-5801-V</guid> <link>http://media.ndr.de/download/podcasts/extradrei196/TV-20101028-2220-5801.h264.mp4</link> </item> </channel></rss>''' vodcast_download_manager = VodcastDownloadManager(feed_content, None) vocast_collector = [] downloader = VodcastDownloader(None) downloader.download = lambda vodcast: vocast_collector.append(vodcast) vodcast_download_manager.downloader = downloader vodcast_download_manager.download_all_newer(as_local_datetime(datetime(2010, 10, 27, 0, 0, 0))) self.assertNotIn(Vodcast(ItemMock('Extra 3 one', (2010, 10, 26, 9, 53, 49), 'http://media.ndr.de/download/podcasts/extradrei196/TV-20101026-2220-5801.h264.mp4')) , vocast_collector) self.assertIn(Vodcast(ItemMock('Extra 3 two', (2010, 10, 27, 9, 53, 49), 'http://media.ndr.de/download/podcasts/extradrei196/TV-20101027-2220-5801.h264.mp4')) , vocast_collector) self.assertIn(Vodcast(ItemMock('Extra 3 three', (2010, 10, 28, 9, 53, 49), 'http://media.ndr.de/download/podcasts/extradrei196/TV-20101028-2220-5801.h264.mp4')) , vocast_collector)
def main(args): parser = OptionParser() parser.add_option("-u", "--url", dest="rss_url", help="download vodcasts from feed URL", metavar="URL") parser.add_option("-d", "--download-directory", dest="download_directory", help="save vodcasts in DIR", metavar="DIR") parser.add_option("-o", "--day-offset", dest="day_offset", help="only download vodcasts DAYS old or younger", metavar="DAYS", type="int", default=None) parser.add_option("-t", "--threads", dest="threads", help="how many THREADS to use for download", metavar="THREADS", type="int", default=1) parser.add_option("-v", "--verbose", action="count", dest="verbose", help="print status messages to stdout more verbose") (options, remaining_args) = parser.parse_args(args) if not (options.rss_url and options.download_directory): parser.error('url and directory are required') if not path.isdir(options.download_directory): parser.error('[%s] is not a directory' % options.download_directory) if options.verbose > 1: _checked_load_logging_config("~/.python/logging_debug.conf") elif options.verbose: _checked_load_logging_config("~/.python/logging.conf") else: logging.basicConfig(stream=sys.stdout, level=logging.WARN) vdm = VodcastDownloadManager(options.rss_url, options.download_directory, options.threads) reference_date = _determineReferenceDate(options.download_directory, options.day_offset, options.rss_url) num_updated = vdm.download_all_newer(reference_date) if num_updated > 0 or not path.exists(_create_fetch_info_path(options.download_directory, options.rss_url)): _saveLastFetchedTimestamp(options.download_directory, options.rss_url)