Beispiel #1
0
 def __init__(self):
     self.rmg = RichMetadataGenerator.getInstance()
     self.parser = None
     self.options = None  
     self.default_title = "P2P-Next project discovery feed"
     self.default_publisher = "P2P-Next (http://www.p2p-next.org)"
     self.default_image = "http://stream.e5.ijs.si/images/p2p-next-logo.jpg" 
 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())
Beispiel #3
0
    def getRichMetadata(self, richmeta=None):
        """
        Get rich metadata based on attributes in inherited
        class. RichMetadata gets assigned according to the mapper of
        the inheriting class instance. Mappers of the inheriting
        classes are defined in settings.

        @param richmeta RichMetadata instance
        @return RichMetadata instance
        """
        assert self._mapper != None
        rmm = RichMetadataGenerator.getInstance()
        rmeta = rmm.getRichMetadata()
        if richmeta != None:
            rmeta.copy(richmeta)
        for a, v in self.__dict__.items():
            if not a.startswith("_"):
                if v != None:
                    if self._mapper.has_key(a) and self._mapper.get(a) != None:
                        try:
                            f = getattr(rmeta, self._mapper[a])
                            if f != None:
                                f(v)
                            else:
                                _log.debug("Getting the method %s has failed, None has been returned.", self._mapper[a])
                        except Exception, e:
                            _log.debug("Setting rich metadata attribute %s whith value %s has failed.", self._mapper[a], v)
Beispiel #4
0
 def testIOptionalMetadata(self):
     log.setLevel(llI)
     _log.info("------- Optional metadata test --------")
     rmg = RichMetadataGenerator.getInstance()
     rm_tva_xml = dict()
     rm_mpeg7_xml = dict()
     mmap = self.metaMap()
     _log.debug("+ get RichMetadata instance")
     for k, v in mmap.items():
         _log.debug("\n" + v.toString())
     _log.debug("+ RichMetadata instance to XML")
     for k, v in mmap.items():
         xml = rmg.build(v)
         rm_tva_xml["tva_" + k] = xml
         _log.debug(rmg.prettyPrint(xml))
         xml = rmg.build(v, metadata.TAG_MPEG7)
         rm_mpeg7_xml["mpeg7_" + k] = xml
         _log.debug(rmg.prettyPrint(xml))
     _log.debug("+ XML back to RichMetadata instance")
     for k, v in rm_tva_xml.items():
         _log.debug("++ " + k + " to meta")
         m = rmg.getRichMetadata(v)
         orig = k.split("_")[1]
         self.metadataCrossCompare(mmap[orig], m)
     for k, v in rm_mpeg7_xml.items():
         _log.debug("++ " + k + " to meta")
         m = rmg.getRichMetadata(v)
         orig = k.split("_")[1]
         self.metadataCrossCompare(mmap[orig], m)
     _log.debug("+ RichMetadata instance TVA cross to MPEG7 XML")
     for k, v in mmap.items():
         xml_tva = rmg.build(v)
         xml_mpeg7 = rmg.build(v, metadata.TAG_MPEG7)
         self.crossBuildsCompareXML(xml_tva, xml_mpeg7)
Beispiel #5
0
 def __init__(self):
     self.rmm = RichMetadataGenerator.getInstance()
     self.parser = None
     self.options = None
     self.metadataType = None
     self.meta = None
     self.setValue = False
 def testFRTVSLOLiveFeeds(self):
     _log.info("Test RTVSLO programme schedule ------------")
     if not TestMetaGenerator.run_test:
         _log.debug("Test avoided.")
         return
     feeds = {"http://www.rtvslo.si/modload.php?&c_mod=rspored-v2&s_content=xml&izbran_program=1": "http://193.138.1.109:19951",
              "http://www.rtvslo.si/modload.php?&c_mod=rspored-v2&s_content=xml&izbran_program=2": "http://193.138.1.109:19952",
              "http://www.rtvslo.si/modload.php?&c_mod=rspored-v2&s_content=xml&izbran_program=22": "http://193.138.1.109:19953"}
     metaFeeds = []
     for f, source in feeds.items():
         fm = RTVSLOLiveFeed.getMetadata(f)
         # Get media information as well
         fm.identifyMedia(source)
         metaFeeds.append(fm)
     rmi = {}
     rmg = RichMetadataGenerator.getInstance()
     for lf in metaFeeds:
         # Get rich metadata from the feed
         lmeta = lf.getRichMetadata()
         for item in lf._items:
             # Get item rich metadata and add the live feed meta
             imeta = item.getRichMetadata(lmeta)
             rmi[imeta] = item
     for rm, item in rmi.items():
         _log.debug(rmg.prettyPrint(rmg.build(rm)))
 def testECreateRichTorrents(self):
     _log.info("Create rich metadata torrents ------------")
     if not TestMetaGenerator.run_test:
         _log.debug("Test avoided.")
         return
     data = None
     self.assertTrue(TestMetaGenerator.data != None, "Test E depends on data gathered in test D, set testD attribute to True")
     if TestMetaGenerator.data != None:
         data = TestMetaGenerator.data
     else:
         return
     rmg = RichMetadataGenerator.getInstance()
     torrents = []
     for k, v in data.items():
         if v.content_base != None:
             # Choose only a small subset of content to download
             if v.content_base == "http://www.rtvslo.si/podcasts/gori_doli_naokoli.xml":
                 mm_file = tempfile.NamedTemporaryFile()
                 try:
                     urllib.urlretrieve(v.id, mm_file.name)
                     torrent_def = TorrentDef()
                     torrent_def.add_content(mm_file.name)
                     torrent_def.set_tracker("http://wanabe.a.tracker.com:8080")
                     torrent_def.set_metadata(k)
                     torrent_def.finalize()
                     torrent_def.save(mm_file.name + ".torrent")
                     torrents.append(mm_file.name + ".torrent")
                 except Exception, e:
                     _log.error("Failed to generate torrent file, reason: " + str(e))
    def testDCopyLiveFeed(self):
        _log.debug("Copy live feed ------------")
        if not TestFeedGenerator.run_test:
            _log.debug("Test avoided.")
            return
        feeds = {"http://www.rtvslo.si/modload.php?&c_mod=rspored-v2&s_content=xml&izbran_program=1": "http://193.138.1.109:19951",
                 "http://www.bbc.co.uk/bbctwo/programmes/schedules/england/today.xml": None}
        parser = {"RTVSLOLiveFeed": lambda x: RTVSLOLiveFeed.getMetadata(x),
                  "BBCLiveFeed": lambda x: BBCLiveFeed.getMetadata(x),}
        # Provisional links to the stream
        links = {"www.rtvslo.si": "http://stream.e5.ijs.si/ch1.html",
                  "www.bbc.co.uk": "http:/to.uknown.net/bbctwo"}
        rmg = RichMetadataGenerator.getInstance()
        for f, v in feeds.items():
            url = urlparse.urlparse(f)
            if settings.LIVE_FEED_PARSER.get(url[1]) != None:
                p = parser.get(settings.LIVE_FEED_PARSER.get(url[1]))
                if p != None:
                    lfmeta = p(f)
                if v != None:
                    lfmeta.identifyMedia(v)
#                _log.debug(lfmeta.toString())
                p2pfeed = P2PNextLiveAtomFeed(title=lfmeta.title, feed_url=lfmeta.title_detail_base, language=lfmeta.language, author_name=lfmeta.author, feed_guid="Should be id of the stream", image=lfmeta.image_href)
                for i in lfmeta._items:
                    if links.get(url[1]) != None:
                        ilink = links[url[1]]
                        ilink_type = "text/html"
                    iadditional_id_data = ""
                    if i.subtitle != None:
                        iadditional_id_data += i.subtitle
                    if i.duration != None:
                        iadditional_id_data += i.duration
                    p2pfeed.add_item(title=i.title, link=ilink, link_type=i.link_type, unique_id=i.id, description=i.summary, image=i.p2pnext_image_src, additional_id_data=iadditional_id_data)
                _log.debug(rmg.prettyPrint(p2pfeed.writeString(), 'utf-8'))
    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'))
Beispiel #10
0
def begin(request):
    def parse(feed):
        feed = feedparser.parse(settings.FEED_DIR+feed)
        feed.channel.description = feed.channel.description.encode('utf-8')
        return {'data': feed,
                'edit_form': AddForm(QueryDict(urllib.urlencode(feed.channel)))}
    
    #feeds = map(parse, os.listdir(settings.FEED_DIR))

    if request.method == 'POST':
        form = AddForm(request.POST)
        if form.is_valid():
            rmg = RichMetadataGenerator.getInstance()
            m = rmg.getRichMetadata()

            m.setTitle(form.cleaned_data['title'])
            #m.setLanguage(form.cleaned_data['language'])
            #m.setGenre(form.cleaned_data['genre'])
            
            print rmg.prettyPrint(rmg.build(m))
            

            return HttpResponseRedirect('/')
    else:
        form = AddForm()

    context = {'feeds': [],
               'MEDIA_URL': settings.MEDIA_URL,
               'add_form': form}
    context.update(csrf(request))
    
    return render_to_response('browse.html', context)
Beispiel #11
0
 def testGDynamicMethods(self):
     log.setLevel(llG)
     _log.info("------- Dynamic methods test --------")
     rmm = RichMetadataGenerator.getInstance()
     meta = rmm.getRichMetadata()
     meta.setProductionLocation("SI").setLanguage("Slovenian").setOriginator("JSI")
     meta.setCaptionLanguage("SI").setGenre("Code").setPublisher("p2p-next")
     meta.setMinimumAge("3").setProductionDate("2010-8-16").setCaptionLanguage("EN")
     meta.setReleaseDate("2010-8-17").setTitleSeriesTitle("P2P-Next code")
     meta.setTitleMain("Rich Metadata implementation")
     meta.setTitleEpisodeTitle("Rich Metadata v" + __revision__)
     meta.setDuration("0.75MM").setHorizontalSize("2").setVerticalSize("cca. 1300")
     meta.setVideoCoding("Generated").setAudioCoding("Manual").setFrameRate("1")
     meta.setNumOfChannels("2").setFileSize("cca. 56k").setBitRate("75")
     meta.setAspectRatio("Substantial")
     meta.setSynopsis("Initial study of RichMetadata API according to the P2P-Next project design")
     xml_tva = rmm.build(meta)
     _log.debug(rmm.prettyPrint(xml_tva))
     xml_mpeg7 = rmm.build(meta, metadata.TAG_MPEG7)
     _log.debug(rmm.prettyPrint(xml_mpeg7))
     self.crossBuildsCompareXML(xml_tva, xml_mpeg7)
     for m in metadata.METADATA_SETS:
         meta = rmm.getRichMetadata(None, m)
         out = ""
         apimethods = meta.getAPIMethods()
         apimethods.sort()
         for method in apimethods:
             out += method + ", "
         out = out.strip().rstrip(",")
         _log.debug(m.capitalize() + " metadata set current API methods: " + out)
Beispiel #12
0
 def testAGenerateP2PNextAtomFeed(self):
     _log.debug("Generate P2P-Next Atom feeds ------------")
     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")
     rmg = RichMetadataGenerator.getInstance()
     _log.debug(rmg.prettyPrint(feed.writeString(), 'utf-8'))
     #### Test some changes we have done to the Django feedgenerator
     # 0.) Default generator
     self.assertTrue(isinstance(feed, P2PNextAtomFeed))
     # 1.) Can generate feed without description and swapped
     # feed_url and link
     self.assertTrue(P2PNextAtomFeed(title=u"BBC One London", feed_url=u"http://p2pnextfeed1.rad0.net/content/feed/bbc/bbcone"))
     # 2.) Without specified link the id is not None
     self.assertTrue(P2PNextAtomFeed(title=u"BBC One London", feed_url=u"http://p2pnextfeed1.rad0.net/content/feed/bbc/bbcone").feed['id'] != None)
     # 3.) Specifying an image turns on p2pnext namespace
     self.assertTrue(feed.root_attributes().has_key("xmlns:p2pnext"))
     self.assertTrue(feed.feed.has_key("image"))
     self.assertTrue(feed.feed["image"] != None)
     self.assertTrue(feed.items[0].has_key("image"))
     self.assertTrue(feed.items[0]["image"] != None)
     # 4.) Specifying an image in an item turns on p2pnext namespace
     feed2 = 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")
     feed2.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")
     self.assertTrue(feed2.root_attributes().has_key("xmlns:p2pnext"))
     self.assertTrue(feed2.feed.has_key("image"))
     self.assertTrue(feed2.feed["image"] == None)
     self.assertTrue(feed2.items[0].has_key("image"))
     self.assertTrue(feed2.items[0]["image"] != None)
     # 5.) Only title and description (summary) are needed for an
     # item, since link || content, id still MUST be provided
     feed3 = P2PNextAtomFeed(title=u"BBC One London", feed_url=u"http://p2pnextfeed1.rad0.net/content/feed/bbc/bbcone")
     feed3.add_item(title="Weatherview",  description=u"Detailed weather forecast.")
     # In this case we generate id on the fly from the item link on build
     self.assertTrue(feed3.items[0]['unique_id'] == None)
     # 6.) But the build will fail if either link nor content are
     # available
     self.assertRaises(FeedGeneratorError, feed3.writeString)
     # 7.) So try with some content
     feed4 = P2PNextAtomFeed(title=u"BBC One London", feed_url=u"http://p2pnextfeed1.rad0.net/content/feed/bbc/bbcone")
     feed4.add_item(title="Weatherview",  description=u"Detailed weather forecast.", content="Still need better specification how to  be encoded")
     pf = feedparser.parse(StringIO(feed4.writeString()))
     self.assertTrue(pf.entries[0]['id'] != None)
     _log.debug("Unique id generated based on content: %s", pf.entries[0]['id'])
     # 8.) And with a link
     feed5 = P2PNextAtomFeed(title=u"BBC One London", feed_url=u"http://p2pnextfeed1.rad0.net/content/feed/bbc/bbcone")
     feed5.add_item(title="Weatherview",  description=u"Detailed weather forecast.", link=u"http://p2pnextfeed1.rad0.net/content/info/bbc/bbcone/b00vk4xq")
     pf = feedparser.parse(StringIO(feed5.writeString()))
     self.assertTrue(pf.entries[0]['id'] != None)
     _log.debug("Unique id generated based on a link: %s", pf.entries[0]['id'])
     linkBasedId = pf.entries[0]['id']
     # 9.) And if we try both, link prevails (content is discarded)
     feed6 = P2PNextAtomFeed(title=u"BBC One London", feed_url=u"http://p2pnextfeed1.rad0.net/content/feed/bbc/bbcone")
     feed6.add_item(title="Weatherview",  description=u"Detailed weather forecast.", content="Still need better specification how to  be encoded", link=u"http://p2pnextfeed1.rad0.net/content/info/bbc/bbcone/b00vk4xq")
     pf = feedparser.parse(StringIO(feed6.writeString()))
     self.assertTrue(pf.entries[0]['id'] != None)
     self.assertTrue(pf.entries[0]['id'] == linkBasedId)
Beispiel #13
0
 def testALearn(self):
     log.setLevel(llA)
     _log.info("------- Learn test --------")
     rmm = RichMetadataGenerator.getInstance()
     for m in rmm.knownMasters():
         master = rmm.getMaster(m)
         _log.debug("Learned from master: %s, %s", master.formatType, master.metadataType)
         _log.debug("\n" + master.root.toString())
Beispiel #14
0
 def testECrossBuilds(self, tva_in=None, mpeg7_in=None):
     log.setLevel(llE)
     _log.info("------- Cross build --------")
     rmg = RichMetadataGenerator.getInstance()
     tva_xml = rmg.build(self.getMetaCore())
     mpeg7_xml = rmg.build(self.getMetaCore(), metadata.TAG_MPEG7)
     _log.debug(rmg.prettyPrint(tva_xml))
     _log.debug(rmg.prettyPrint(mpeg7_xml))
     self.crossBuildsCompareXML(tva_xml, mpeg7_xml)
Beispiel #15
0
 def testDBuild(self):
     log.setLevel(llD)
     _log.info("------- Build test --------")
     rmm = RichMetadataGenerator.getInstance()
     tva = rmm.getRichMetadata(metadata.LEARN_BASE_CORE[metadata.TAG_TVA_MAIN])
     xml_tva = rmm.build(tva)
     _log.debug(rmm.prettyPrint(xml_tva))
     mpeg7 = rmm.getRichMetadata(metadata.LEARN_BASE_CORE[metadata.TAG_MPEG7])
     xml_mpeg7 = rmm.build(mpeg7, metadata.TAG_MPEG7)
     _log.debug(rmm.prettyPrint(xml_mpeg7))
Beispiel #16
0
 def getMetaPayment(self, xml=False, formatType=None):
     rmm = RichMetadataGenerator.getInstance()
     meta = rmm.getRichMetadata(None, metadata.METADATA_PAYMENT)
     meta.setAcceptDonations("True")
     meta.setAdvancedInfos("http://www.p2p-next.org/paymentInformation.html")
     meta.setCurrency("EUR").setPaymentId("pay-one").setPaymentRecipient("me")
     meta.setPrice("2000").setProgramId("crid://p2p-next/seeMe")
     meta.setPublisher("p2p-next")
     if xml:
         return rmm.build(meta, formatType)
     return meta
Beispiel #17
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'))
Beispiel #18
0
 def getMetaAdvertising(self, xml=False, formatType=None):
     rmm = RichMetadataGenerator.getInstance()
     meta = rmm.getRichMetadata(None, metadata.METADATA_ADVERTISING)
     meta.setAdFormat("All-over").setAdType("P2PAdd").setAge("15")
     meta.setAllowAdvertising("True").setAspectRatio("16:9").setBusinessModel("BM2")
     meta.setCircularContent("Allow Superdistribution").setCountry("EU")
     meta.setFrameRate("30").setGender("W").setHorizontalSize("720")
     meta.setIsLiveContent("True").setProgramId("crid://market/me2")
     meta.setPublisher("p2p-next-2").setStreamingType("In-stream")
     meta.setVerticalSize("405").setVideoCoding("MPEG-4 Video")
     if xml:
         return rmm.build(meta, formatType)
     return meta
Beispiel #19
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)
Beispiel #20
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
Beispiel #21
0
 def getDIDBase(self, xml = False):
     rmg = RichMetadataGenerator.getInstance()
     meta = rmg.getRichMetadata(None, metadata.MPEG_21_BASE)
     meta.setIdentifier("urn:p2p-next:item:rtv-slo-slo1-xyz") 
     meta.setRelatedIdentifier("urn:rtv-slo:slo1-xyz") 
     # Will build core metadata of type TVA
     meta.setMetaCore(rmg.build(self.getMetaCore())) 
     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.setContentReference("URI to video included in the torrent")
     meta.setContentType("video/ts") 
     meta.setLimoReference("URI to additional MPEG_21 data (limo)")
     if xml:
         return rmg.build(meta)
     return meta
Beispiel #22
0
 def getMetaScalability(self, xml=False, formatType=None):
     rmg = RichMetadataGenerator.getInstance()
     meta = rmg.getRichMetadata(None, metadata.METADATA_SCALABILITY)
     meta.setAdaptationOperatorDependencyId("0 1 2 3")
     meta.setAdaptationOperatorQualityLevel("0 0 0 0")
     meta.setAdaptationOperatorTemporalLevel("0 0 0 0")
     meta.setConstraintBitrate("400 800 1200 2400")
     meta.setPPS("spsId=1,value=xyz:spsId=2,value=zxy")
     meta.setProgramId("crid://yet/another")
     meta.setPublisher("the one")
     meta.setSPS("spsId=1,width=20,height=16,value=kuku:spsId=2,width=3,height=2,value=lala")
     meta.setUtilityFramerate("25 25 25 25")
     meta.setUtilityHeight("240 240 480 480")
     meta.setUtilityWidth("320 320 640 640")
     if xml:
         return rmg.build(meta, formatType)
     return meta
Beispiel #23
0
 def testBGetMetadata(self):
     log.setLevel(llB)
     _log.info("------- Get metadata --------")
     rmm = RichMetadataGenerator.getInstance()
     tva = rmm.getRichMetadata(metadata.LEARN_BASE_CORE[metadata.TAG_TVA_MAIN])
     _log.debug("\n" + tva.toString())
     mpeg7 = rmm.getRichMetadata(metadata.LEARN_BASE_CORE[metadata.TAG_MPEG7], metadata.TAG_MPEG7)
     _log.debug("\n" + mpeg7.toString())
     for k in tva.core:
         self.assertTrue(mpeg7.core.has_key(k))
     for k in tva.core:
         _tvaExists = False
         _mpeg7Exists = False
         if getattr(tva, k):
             _tvaExists = True
         if getattr(mpeg7, k):
             _mpeg7Exists = True
         if _tvaExists != _mpeg7Exists:
             _log.warn("Offending core key %s, TVA = %s, MPEG7 = %s", k, _tvaExists, _mpeg7Exists)
Beispiel #24
0
 def testFCostumizedExportFeed(self):
     _log.info("Customized 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://stream.e5.ijs.si/vod"
     for f in feeds:
         url = urlparse.urlparse(f)
         if url.netloc == "www.rtvslo.si":
             channel = Channel.getContentSource(f, publish, RTVVoDContent())
             for i, v in channel.items.items():
                 self.assertTrue(type(v) == type(RTVVoDContent()))
         else:
             channel = Channel.getContentSource(f, publish)
             for i, v in channel.items.items():
                 self.assertTrue(type(v) == type(ContentUnit()))
         _log.debug(rmg.prettyPrint(channel.exportFeed(), 'utf-8'))
Beispiel #25
0
 def testHSparseMetadata(self):
     log.setLevel(llH)
     _log.info("------- Sparse metadata test --------")
     rmm = RichMetadataGenerator.getInstance()
     meta = rmm.getRichMetadata()
     meta.setProductionLocation("SI").setLanguage("Slovenian").setOriginator("JSI")
     xml_tva = rmm.build(meta)
     xml_mpeg7 = rmm.build(meta, metadata.TAG_MPEG7)
     _log.debug(rmm.prettyPrint(xml_tva))
     _log.debug(rmm.prettyPrint(xml_mpeg7))
     self.crossBuildsCompareXML(xml_tva, xml_mpeg7)
     meta2 = rmm.getRichMetadata()
     meta2.setTitleMain("Rich Metadata implementation")
     meta2.setNumOfChannels("2").setFileSize("cca. 56k").setBitRate("75")
     meta2.setHorizontalSize("2").setVerticalSize("cca. 1300")
     xml_tva2 = rmm.build(meta2)
     _log.debug(rmm.prettyPrint(xml_tva2))
     xml_mpeg7_2 = rmm.build(meta2, metadata.TAG_MPEG7)
     _log.debug(rmm.prettyPrint(xml_mpeg7_2))
     self.crossBuildsCompareXML(xml_tva2, xml_mpeg7_2)
Beispiel #26
0
 def crossBuildsCompareXML(self, tva_in, mpeg7_in):
     _log.info("+++ Cross build compare XML +++")
     rmm = RichMetadataGenerator.getInstance()
     # Two instances of the "same" metadata
     tva = rmm.getRichMetadata(tva_in)
     mpeg7 = rmm.getRichMetadata(mpeg7_in)
     # Cross build
     mpeg7_from_tva = rmm.build(tva, metadata.TAG_MPEG7)
     tva_from_mpeg7 = rmm.build(mpeg7, metadata.TAG_TVA_MAIN)
     # Cross instances
     mpeg7_cross = rmm.getRichMetadata(mpeg7_from_tva)
     tva_cross = rmm.getRichMetadata(tva_from_mpeg7)
     for a in rmm.knownAttributes():
         if getattr(tva_cross, a):
             if not getattr(mpeg7_cross, a):
                 _log.error("Attribute '%s' present in TVA but not in MPEG7 rich metadata instance.", a)
             else:
                 if getattr(tva_cross, a) != getattr(mpeg7_cross, a):
                     _log.warn("Attribute '%s' present in both sets but different (TVA) '%s' != '%s' (MPEG7).", a, getattr(tva_cross, a), getattr(mpeg7_cross, a))
         if getattr(mpeg7_cross, a):
             if not getattr(tva_cross, a):
                 _log.error("Attribute '%s' present in MPEG7 but not in TVA rich metadata instance.", a)
     _log.info("Comparing cross builds back for TVA")
     for a in rmm.knownAttributes():
         if getattr(tva, a):
             if not getattr(tva_cross, a):
                 _log.error("Attribute '%s' present in TVA but not in TVA-Cross rich metadata instance.", a)
             else:
                 if getattr(tva, a) != getattr(tva_cross, a):
                     _log.warn("Attribute '%s' present in both sets but different (TVA) '%s' != '%s' (TVA-Cross).", a, getattr(tva, a), getattr(tva_cross, a))
     _log.info("Comparing cross builds back for MPEG7")
     for a in rmm.knownAttributes():
         if getattr(mpeg7, a):
             if not getattr(mpeg7_cross, a):
                 _log.error("Attribute '%s' present in TVA but not in TVA-Cross rich metadata instance.", a)
             else:
                 if getattr(mpeg7, a) != getattr(mpeg7_cross, a):
                     _log.warn("Attribute '%s' present in both sets but different (MPEG7) '%s' != '%s' (MPEG7-Cross).", a, getattr(mpeg7, a), getattr(mpeg7_cross, a))
     self.metadataCrossCompare(tva, mpeg7_cross)
     self.metadataCrossCompare(mpeg7, tva_cross)
Beispiel #27
0
 def testGBBCLiveFeeds(self):
     _log.info("Test BBC programme schedule ------------")
     if not TestMetaGenerator.run_test:
         _log.debug("Test avoided.")
         return
     feeds = {"http://www.bbc.co.uk/bbctwo/programmes/schedules/england/today.xml": None}
     metaFeeds = []
     for f, source in feeds.items():
         fm = BBCLiveFeed.getMetadata(f)
         if source != None:
             fm.identifyMedia(source)
         metaFeeds.append(fm)
     rmi = {}
     rmg = RichMetadataGenerator.getInstance()
     for lf in metaFeeds:
         # Get rich metadata from the feed
         lmeta = lf.getRichMetadata()
         for item in lf._items:
             # Get item rich metadata and add the live feed meta
             imeta = item.getRichMetadata(lmeta)
             rmi[imeta] = item
     for rm, item in rmi.items():
         _log.debug(rmg.prettyPrint(rmg.build(rm)))
Beispiel #28
0
 def getMetaCore(self, xml=False, formatType=None):
     rmm = RichMetadataGenerator.getInstance()
     meta = rmm.getRichMetadata()
     meta.setProductionLocation("SI").setLanguage("Slovenian")
     meta.setOriginator("JSI")
     meta.setCaptionLanguage("SI").setGenre("Code").setPublisher("p2p-next")
     meta.setProductionDate("2010-8-16").setCaptionLanguage("EN")
     meta.setReleaseDate("2010-8-17").setTitleSeriesTitle("P2P-Next code")
     meta.setTitleMain("Rich Metadata implementation")
     meta.setTitleEpisodeTitle("Rich Metadata v" + __revision__)
     meta.setDuration("1M").setMinimumAge("3")
     meta.setHorizontalSize("640").setVerticalSize("480")
     meta.setFrameRate("27").setAspectRatio("4:3")
     meta.setVideoCoding("Generated").setAudioCoding("Manual")
     meta.setNumOfChannels("2").setFileSize("120k").setBitRate("75")
     meta.setSynopsis("Initial study of RichMetadata API according to the P2P-Next project design")
     meta.setProgramId("crid://p2p-next/example123")
     meta.setAudioCoding("MPEG-1 Audio Layer III")
     meta.setVideoCoding("MPEG-2 Video Main Profile @ Main Level")
     meta.setFileFormat("mp4")
     if xml:
         return rmm.build(meta, formatType)
     return meta
Beispiel #29
0
 def getDIDAdditional(self, xml=False):
     rmg = RichMetadataGenerator.getInstance()
     meta = rmg.getRichMetadata(None, metadata.MPEG_21_ADDITIONAL)
     meta.setRelatedIdentifier("urn:rtv-slo:slo1-xyz")
     meta.setCSSName("Name of the CSS file in Limo") 
     meta.setCss("Limo CSS content, should be included as XML CDATA") 
     meta.setHtml("Limo HTML content, should be included as XML CDATA") 
     meta.setJavascript("Limo Javascript content, should be included as XML CDATA") 
     meta.setJavascriptName("Name of Javascript file in Limo") 
     meta.setLogo("Logo graphics") 
     meta.setLogoName("Name of the logo file") 
     meta.setLogoReference("URI reference to the logo (Needed indeed?)") 
     # Note that parsing depends on proper definition of mime type
     # start (image/)
     meta.setLogoType("image/Mime type of logo") 
     # Will build advertising metadata of type TVA
     meta.setMetaAdvertisement(rmg.build(self.getMetaAdvertising()))
     # Will build payment metadata of type TVA
     meta.setMetaPayment(rmg.build(self.getMetaPayment())) 
     # Will build scalability metadata of type TVA
     meta.setMetaScalability(rmg.build(self.getMetaScalability()))
     if xml:
         return rmg.build(meta)
     return meta
Beispiel #30
0
 def testJDIDMetadata(self):
     log.setLevel(llJ)
     _log.info("------- DID metadata test --------")
     rmg = RichMetadataGenerator.getInstance()
     _rm = dict()
     _log.debug("+ Get DID RichMetadata instances")
     for k, v in self.didMap().items():
         _rm[k] = v
         _log.debug("\n" + v.toString())
     richm = list()
     richm.append(_rm["base"])
     richm.append(_rm["additional"])
     _log.debug("+ RichMetadata instance DID to XML")
     didxml = list()
     for m in richm:
         xml = rmg.build(m)
         didxml.append(xml)
         _log.debug(rmg.prettyPrint(xml))
     _log.debug("+ DID XML back to RichMetadata instance ")
     i = 0
     for v in didxml:
         m = rmg.getRichMetadata(v)
         self.metadataCrossCompare(richm[i], m)
         i += 1