Ejemplo n.º 1
0
 def testEDiscoveryFeed(self):
     _log.debug("Discovery feed ------------")
     if not TestFeedGenerator.run_test:
         _log.debug("Test avoided.")
         return
     rmg = RichMetadataGenerator.getInstance()
     # Just copy original BBC feed
     radfeed = "http://p2pnextfeed1.rad0.net/content/feed/bbc"
     meta = Feed.getMetadata(radfeed, False)
     _log.debug(meta.toString())
     p2pfeed = P2PNextAtomFeed(title=meta.title, feed_url=meta.title_detail_base, author_name=meta.author, feed_guid=meta.id, image=meta.p2pnext_img_src)
     for i in meta._items:
         cat = [(i.tags_term, i.tags_scheme)]
         p2pfeed.add_item(title=i.title, link=i.links_href, link_type=i.links_type, unique_id=i.id, description=i.summary, image=i.p2pnext_image_src, categories=cat)
     _log.debug(rmg.prettyPrint(p2pfeed.writeString(), 'utf-8'))
     # Now create something on our own, this is how I would imagine
     # a top level discovery tree
     dfeed = P2PNextAtomFeed(title="P2P-Next project discovery feed", feed_url="http://whereever.you.want", author_name="P2P-Next (http://www.p2p-next.org)", feed_guid=settings.URN + settings.P2P_NEXT, image="http://stream.e5.ijs.si/images/p2p-next-logo.jpg")
     dfeed.add_item(title=meta.title, link=meta.title_detail_base, link_type="application/atom+xml", unique_id=meta.id, description="BBC discovery feed", image=meta.p2pnext_image_src, categories=[("discovery", "urn:service-type")]) 
     dfeed.add_item(title="RTV SLO", link="htt://stream.e5.ijs.si/feeds/rtv-slo-discovery.xml", link_type="application/atom+xml", unique_id=settings.URN + settings.P2P_NEXT + settings.COLON + settings.RTV_SLO, description="RTV SLO MMC discovery feed", image="http://stream.e5.ijs.si/images/mmc.jpg", categories=[("discovery", "urn:service-type")])
     _log.debug(rmg.prettyPrint(dfeed.writeString(), 'utf-8'))
     # And fake an RTV SLO discovery feed. Fake in sense that the
     # content isn't copied, torrents are not made and only
     # metadata gets processed.
     feeds = ["http://www.rtvslo.si/podcasts/18-vzporednik.xml",
              "http://www.rtvslo.si/podcasts/arsov_logos.xml",
              "http://www.rtvslo.si/podcasts/dogodki_in_odmevi.xml",
              "http://www.rtvslo.si/podcasts/utrip.xml",
              "http://www.rtvslo.si/podcasts/vecerni_gost.xml",
              "http://www.rtvslo.si/podcasts/vreme.xml"]
     rtvfeed = P2PNextAtomFeed(title="RTV SLO", feed_url="htt://stream.e5.ijs.si/feeds/rtv-slo-discovery.xml", author_name="RTV SLO MMC", feed_guid=settings.URN + settings.P2P_NEXT + settings.COLON + settings.RTV_SLO, image="http://stream.e5.ijs.si/images/mmc.jpg")
     identify = settings.IDENTIFY_HELPER[settings.PUBLISHER_RTV_SLO_MMC]
     for f in feeds:
         _log.debug("--------> Metadating a feed %s", f)
         meta = Feed.getMetadata(f)
         # Cycle through feed items
         for i in meta._items:
             video = False
             # Cycle through items media
             for m in i._items:
                 # Cycle through media streams
                 for s in m._items:
                     if s.type == "video":
                         video = True
                     # Decide on the first item
                     break
                 break
             break
         if video:
             cat = [(settings.CATEGORY_TV, settings.CATEGORY_SCHEME_ST)]
         else:
             cat = [(settings.CATEGORY_RADIO, settings.CATEGORY_SCHEME_ST)]
         rtvfeed.add_item(title=meta.title, link=meta.title_detail_base, link_type="application/atom+xml", unique_id=settings.URN + settings.P2P_NEXT + settings.COLON + settings.RTV_SLO + settings.COLON + identify(f), description=meta.subtitle, image=meta.image_href, categories=cat)
     _log.debug(rmg.prettyPrint(rtvfeed.writeString(), 'utf-8'))
Ejemplo n.º 2
0
 def testHRestoreStoredProperties(self):
     _log.info("Restore stored properties -----------")
     if not TestContentSource.run_test:
         _log.debug("Test avoided.")
         return
     feed = "http://www.rtvslo.si/podcasts/zapisi_iz_mocvirja.xml"
     publish = "http://stream.e5.ijs.si/vod"
     feedLink = "http://stream.e5.ijs.si/feeds/zapisi_iz_mocvirja.xml"
     cuci = "RTVVoDContent"
     exportLink = "http://web.server.of.your.choice/relative"
     guid = "xyz"
     image = "http://stream.e5.ijs.si/image/kuku.jpg"
     didfile = "did-base-test.xml"
     rmg = RichMetadataGenerator.getInstance()
     meta = rmg.getRichMetadata(None, metadata.MPEG_21_BASE)
     meta.setRelatedIdentifier("urn:rtv-slo:slo1-xyz") 
     meta.setPaymentReference("URI to additional MPEG_21 data (payment)") 
     meta.setAdvertisementReference("URI to additional MPEG_21 data (advertising)") 
     meta.setScalabilityReference("URI to additional MPEG_21 data (scalability)")
     meta.setLimoReference("URI to additional MPEG_21 data (limo)")
     f = open(didfile, 'w')
     f.write(rmg.build(meta))
     f.close()
     channel = Channel.getContentSource(feed, publish, RTVVoDContent(), feedLink, didfile)
     feed1_xml = channel.exportFeed(guid, image)
     test = ContentSource.getContentSource(feed)
     test.storage = channel.storage
     test.restoreAttributes()
     self.assertTrue(channel.storage == test.storage)
     self.assertTrue(channel.cstype == test.cstype)
     self.assertTrue(channel.location == test.location)
     self.assertTrue(channel.publish == test.publish)
     self.assertTrue(channel.image == test.image)
     self.assertTrue(channel.contentUnitClassInstance == test.contentUnitClassInstance)
     self.assertTrue(channel.exportFeedLink == test.exportFeedLink)
     self.assertTrue(channel.didbaseFile == test.didbaseFile)
     self.assertTrue(channel.guid == test.guid)
     channel = Channel.getContentSource(feed)
     feed2_xml = channel.exportFeed()
     # Cannot compare directly xmls since the updated can change
     feed1_meta = Feed.getMetadata(StringIO(feed1_xml), False)
     feed2_meta = Feed.getMetadata(StringIO(feed2_xml), False)
     self.assertTrue(feed1_meta.id == feed2_meta.id)
     self.assertTrue(feed1_meta.p2pnext_img_src == feed2_meta.p2pnext_img_src)
     self.assertTrue(feed1_meta.links_href == feed2_meta.links_href)
     count = 0
     for i in feed1_meta._items:
         self.assertTrue(i.links_href == feed2_meta._items[count].links_href)
         self.assertTrue(i.id == feed2_meta._items[count].id)
         self.assertTrue(i.p2pnext_image_src == feed2_meta._items[count].p2pnext_image_src)
         count += 1
Ejemplo n.º 3
0
    def testCCopyVoDFeed(self):
        _log.debug("Copy VoD feed ------------")
        if not TestFeedGenerator.run_test:
            _log.debug("Test avoided.")
            return
        feeds = ["http://www.rtvslo.si/podcasts/gori_doli_naokoli.xml",
                 "http://www.rtvslo.si/podcasts/vreme.xml",
                 "http://www.rtvslo.si/podcasts/studio_city.xml",
                 "http://downloads.bbc.co.uk/podcasts/radio4/today/rss.xml"]
        rmg = RichMetadataGenerator.getInstance()
        for f in feeds:
            _log.debug("Reading the feed %s", f)
            fmeta = Feed.getMetadata(f)
            _log.debug("Writting p2p-next feed %s", f)
            if fmeta.title_detail_base != None:
                furl = fmeta.title_detail_base
            else:
                furl = f
            p2pfeed = P2PNextAtomFeed(title=fmeta.title, feed_url=furl, language=fmeta.language, author_name=fmeta.author, feed_guid=fmeta.id, image=fmeta.image_href)
            for i in fmeta._items:
                if i.p2pnext_image_src == None:
                    i.p2pnext_image_src = fmeta.image_href
                ilink_type = None
                if i.media_content_type != None:
                    ilink_type = i.media_content_type
                elif i.extension != None:
                    if settings.MIME_TYPES_MAP.get(i.extension) != None:
                        ilink_type = settings.MIME_TYPES_MAP[i.extension]
                p2pfeed.add_item(title=i.title, link=i.links_href, link_type=ilink_type, unique_id=i.id, description=i.summary, image=i.p2pnext_image_src)

            _log.debug(rmg.prettyPrint(p2pfeed.writeString(), 'utf-8'))
Ejemplo n.º 4
0
 def testBParseP2PNextAtomFeed(self):
     _log.debug("Parse P2P-Next Atom feed ------------")
     if not TestFeedGenerator.run_test:
         _log.debug("Test avoided.")
         return
     feed = P2PNextAtomFeed(title=u"BBC One London", feed_url=u"http://p2pnextfeed1.rad0.net/content/feed/bbc/bbcone", language=u"en", author_name=u"BBC", feed_guid=u"urn:bbc-bbcone", image="http://p2pnextfeed1.rad0.net/images/bbcone.png")
     feed.add_item(title="Weatherview", link=u"http://p2pnextfeed1.rad0.net/content/info/bbc/bbcone/b00vk4xq", link_type=u"application/atom+xml", unique_id=u"urn:bbc-bbcone-b00vk4xq", description=u"Detailed weather forecast.", image="http://www.bbc.co.uk/iplayer/images/progbrand/b007yy70_150_84.jpg")
     meta = Feed.getMetadata(StringIO(feed.writeString()))
     _log.debug(meta.toString())
     self.assertTrue(meta.title == feed.feed['title'])
     self.assertTrue(meta.links_href == feed.feed['feed_url'])
     self.assertTrue(meta.language == feed.feed['language'])
     # Updated not defined in the feed, added on the fly
     self.assertTrue(meta.updated != feed.feed.get('updated'))
     self.assertTrue(meta.author == feed.feed['author_name'])
     self.assertTrue(meta.id == feed.feed['id'])
     self.assertTrue(meta.p2pnext_image_src == feed.feed['image'])
     count = 0
     for i in meta._items:
         self.assertTrue(i.title == feed.items[count]['title'])
         self.assertTrue(i.links_href == feed.items[count]['link'])
         self.assertTrue(i.links_type == feed.items[count]['link_type'])
         self.assertTrue(i.id == feed.items[count]['unique_id'])
         self.assertTrue(i.p2pnext_image_src == feed.items[count]['image'])
         self.assertTrue(i.summary == feed.items[count]['description'])
         count += 1
Ejemplo n.º 5
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())
Ejemplo n.º 6
0
 def testGExportFeedLink(self):
     _log.info("Export feed link -----------")
     if not TestContentSource.run_test:
         _log.debug("Test avoided.")
         return
     feeds = ["http://www.rtvslo.si/podcasts/zapisi_iz_mocvirja.xml"]
     rmg = RichMetadataGenerator.getInstance()
     publish = "http://stream.e5.ijs.si/vod"
     feedLink = "http://stream.e5.ijs.si/feeds/zapisi_iz_mocvirja.xml"
     for f in feeds:
         channel = Channel.getContentSource(f, publish, RTVVoDContent(), feedLink)
         meta = Feed.getMetadata(StringIO(channel.exportFeed()), False)
         self.assertTrue(meta.links_href == feedLink)
Ejemplo n.º 7
0
 def testDRichMetadata(self):
     _log.info("Generate RichMetadata ------------")
     if not TestMetaGenerator.run_test:
         _log.debug("Test avoided.")
         return
     rmg = RichMetadataGenerator.getInstance()
     # Only RTV based feed, have problems accessing BBC feeds :(
     feeds = ["http://www.rtvslo.si/podcasts/gori_doli_naokoli.xml",
              "http://www.rtvslo.si/podcasts/vreme.xml",
              "http://www.rtvslo.si/podcasts/studio_city.xml",
              "http://downloads.bbc.co.uk/podcasts/radio4/today/rss.xml"]
     metaFeeds = list()
     for f in feeds:
         metaFeeds.append(Feed.getMetadata(f))
     rmi = {}
     for mf in metaFeeds:
         # Get rich metadata from the feed
         fmeta = mf.getRichMetadata()
         for item in mf._items:
             # Get item rich metadata and add the feed meta
             imeta = item.getRichMetadata(fmeta)
             rmi[imeta] = item
     rm_read = None
     rm_orig = None
     for rm in rmi: 
         rm_orig = rm
         # Build rich metadata instances
         rm_xml = rmg.build(rm)
         _log.debug(rmg.prettyPrint(rm_xml))
         # Can we read what we had encoded?
         rm_read = rmg.getRichMetadata(rm_xml)
         # If this test raises an assertion error elevate the log
         # level in RichMetadata implementation to debug
         self.assertTrue(rm == rm_read)
     rm_read.setFrameRate("12")
     self.assertTrue(rm_read != rm_orig)
     # Build base DIDs
     storeData = {}
     for rm, v in rmi.items(): 
         rm_xml = rmg.build(rm)
         bdid = rmg.getRichMetadata(None, metadata.MPEG_21_BASE)
         bdid.setMetaCore(rm_xml)
         if v.file != None:
             bdid.setContentReference(v.file)
         if v.extension != None:
             if settings.MIME_TYPES_MAP.has_key(v.extension):
                 bdid.setContentType(settings.MIME_TYPES_MAP[v.extension])
             else:
                 if v.media_content_type != None:
                     bdid.setContentType(v.media_content_type)
         if rm.getPublisher() == settings.PUBLISHER_RTV_SLO_MMC:
             if v.id != None:
                 helper = settings.IDENTIFY_HELPER[settings.PUBLISHER_RTV_SLO_MMC]
                 ident = helper(v.id)
                 bdid.setIdentifier(settings.URN_ITEM + settings.RTV_SLO_MMC + "-" + ident)
                 bdid.setRelatedIdentifier(settings.RELATED_RTV_SLO_MMC + ident)
         bdid_xml = rmg.build(bdid)
         _log.debug(rmg.prettyPrint(bdid_xml))
         storeData[bdid_xml] = v
     # Avoid reading the feeds all the time. Data keys: DID base
     # metadata, value: items metadata
     TestMetaGenerator.data = storeData