Esempio n. 1
0
 def testEDefaultsExportFeed(self):
     _log.info("Defaults export feed ------------")
     if not TestContentSource.run_test:
         _log.debug("Test avoided.")
         return
     feeds = ["http://www.rtvslo.si/podcasts/zapisi_iz_mocvirja.xml",
              "http://downloads.bbc.co.uk/podcasts/radio4/today/rss.xml"]
     rmg = RichMetadataGenerator.getInstance()
     publish = "http://web.server.of.your.choice/relative"
     for f in feeds:
         channel = Channel.getContentSource(f, publish)
         _log.debug(rmg.prettyPrint(channel.exportFeed(), 'utf-8'))
         # Get meta, don't identify media, since we can't (yet?)
         meta = Feed.getMetadata(StringIO(channel.exportFeed()), False)
         self.assertTrue(meta.title == channel.name)
         self.assertTrue(meta.links_href == publish + "/" + textify(channel.name) + settings.METADATA_EXT)
         self.assertTrue(meta.language == channel.metadata.getLanguage())
         self.assertTrue(meta.author == channel.metadata.getPublisher())
         self.assertTrue(meta.id == channel.getExportFeedLink())
         self.assertTrue(meta.p2pnext_image_src == channel.image)
         for i, v in channel.items.items():
             # Find according to link
             rmi = None
             for i in meta._items:
                 if i.links_href == publish + "/" + v.publish:
                     rmi = i
             self.assertTrue(rmi != None)
             self.assertTrue(rmi.title == v.name)
             self.assertTrue(rmi.links_type == "application/x-bittorrent")
             # Id not tested
             self.assertTrue(rmi.p2pnext_image_src == channel.image)
             self.assertTrue(rmi.title == v.metadata.getTitleEpisodeTitle())
Esempio n. 2
0
 def run(self):
     """
     Runs the managefeed tool and creates a feed according to specified
     options or modifies feed content (items)
     """
     core = None
     rmg = RichMetadataGenerator.getInstance()
     if options.coremetafile:
         core = rmg.getRichMetadata(options.coremetafile)                
         if core:
             if core.metadataType != metadata.METADATA_CORE:
                 self.exitOnInputError("Core metadata of wrong type: " + core.metadataType)
         else:
             self.exitOnInputError("Cannot read core metadata from supplied file: " + options.coremetafile)
     # Creates a feed
     if options.feedmod:
         if not options.title and not options.coremetafile:
             self.exitOnInputError("Feed title or core metadata must be defined")
         channel = Channel()
         if core:
             if not core.getTitleMain():
                 self.exitOnInputError("Feed title or core metadata title mainmust be defined")
             channel.name = core.getTitleMain()
             channel.metadata = core
         else:
             channel.name = options.title
         channel.storage = settings.MEDIA_ROOT + os.path.sep + textify(channel.name)
         channel.location = "file://" + channel.storage
         channel.identifier = channel.identify(channel.location)
         if options.cuci:
             cuci = classImport(classpath, options.cuci)
             if cuci:
                 channel.contentUnitClassInstance = cuci.__class.__name__
                 channel.cuci = cuci
         if os.path.isdir(channel.storage):
             channel = channel.restore(channel.storage, channel)
             if core: # core metadata supplied on command line, prevail
                 channel.metadata = core
         if options.publish:
             channel.publish = options.publish
         if options.exporturl:
             channel.exportFeedLink = options.exporturl
         if options.didbase:
             channel.setDIDBaseFile(options.didbase)
         if options.image:
             channel.image = options.image
         if not core:
             core = rmg.getRichMetadata()
         old = core
         if options.language:
             core.setLanguage(options.language)
         if options.description:
             core.setTitleSeriesTitle(options.description)
         if options.publisher:
             core.setPublisher(options.publisher)
         if options.originator:
             core.setOriginator(options.originator)
         if options.title:
             core.setTitleMain(options.title)
         if core != old or not channel.metadata:
             channel.metadata = core
         channel.store(True)
     # Adds an item to the feed
     elif options.additem:
         if not options.feeddir:
             self.exitOnInputError("For adding the feed item feed directory needs\n                    to be specified! (-d option)")
         if not os.path.exists(os.path.join(options.feeddir, settings.CONTENT_SOURCE_PROPERTIES)):
             self.exitOnInputError("Feed directory specified seems not to be populated.\n                    Feed properties file is missing in path: " + options.feeddir)
         c = Channel()
         channel = c.restore(options.feeddir)
         cu = channel.getContentUnitInstance()
         cu.acquire = channel.acquire
         if options.content:
             if os.path.exists(options.content) and os.path.isfile(options.content):
                 cu.contentFile = os.path.basename(options.content)
             else:
                 self.exitOnInputError("Content file is missing in path or is not a file:\n                    " + options.content)
         else:
             self.exitOnInputError("Content file should be specified while adding an item")
         item = Item()
         item._items.append(Media.getMetadata(options.content))
         if not core: 
             core = rmg.getRichMetadata()
         if options.title:
             core.setTitleEpisodeTitle(options.title)
         if options.synopsis:
             core.setSynopsis(options.synopsis)
         # Problem turned round. From RM set the item attributes
         for k, v in settings.MMM_ITEM.items():
             if v:
                 m = "get" + v.lstrip("set")
                 f = getattr(core, m)
                 setattr(item, k, f())
         if options.coremetafile:
             cu.metadata = item.getRichMetadata(core)
         else:
             cu.metadata = item.getRichMetadata(channel.metadata)
         cu.name = cu.metadata.getTitleEpisodeTitle()
         cu.identifier = cu.identify()
         if cu.identifier in channel.items:
             self.exitOnInputError("You are trying to add the content " + options.content + " with metadata that seems already added to the feed with name " + channel.name)
         cu.feedStore = channel.storage
         (b, e) = os.path.splitext(cu.contentFile)
         cu.storeMeta(os.path.join(channel.storage, b))
         if channel.storage != os.path.basename(options.content):
             if os.path.exists(os.path.join(channel.storage, cu.contentFile)):
                 self.exitOnInputError("You are trying to add the content " + cu.contentFile + "\n                    to the feed with name '" + channel.name + "' that already\n                    exists in the feed.")     
             os.symlink(options.content, os.path.join(channel.storage, cu.contentFile))
         cu.fresh = True
         channel.items[cu.identifier] = cu
         channel.exportTorrent()
     # Removes the item
     elif options.removeitem:
         if not options.feeddir:
             self.exitOnInputError("For removing the feed item feed directory needs to be\n                        specified (-d option)!")
         if os.path.exists(options.feeddir) and os.path.isdir(options.feeddir):
             c = Channel()
             channel = c.restore(options.feeddir)
             if channel.items.has_key(options.removeitem):
                 channel.removeContentUnit(options.removeitem)
             else:
                 self.exitOnInputError("Cannot remove nonexistent content unit, identifier " + options.removeitem + " not registred")
         else:
             self.exitOnInputError("Feed directory is missing in path or is not a directory:\n                    " + options.feeddir)                
     # List the feed
     elif options.list:
         if os.path.exists(options.list) and os.path.isdir(options.list):
             c = Channel()
             channel = c.getCSFromDir(options.list)
             if options.listlong:
                 print channel.toString()
             else:
                 print "'" + channel.name + "', stored in " + channel.storage
                 print "Location: " + channel.location
                 i = 1
                 sitems = channel.timesort.sort()
                 sitems.reverse()
                 for k in sitems:
                     if channel.items.get(k):
                         v = channel.items[k]
                         print '{0:>3}'.format(i) + ") " + v.name 
                         print "     Identifier: " + v.identifier
                         print "     Content:    " + v.contentFile
                         print "     Metadata:   " + v.metaFile
                         print "     Torrent:    " + str(v.findTorrentFile())
                         i += 1
                     else:
                         _log.warn("Programmable error: identifier in sorter that does not exists in source")
         else:
             self.exitOnInputError("Feed directory is missing in path or is not a directory:\n                    " + options.list)                
     else:
         self.exitOnInputError("None of the main options -c, -a, -r or -l specified!")