Example #1
0
    def make_part(self, vid, host, part):
        from helpers import uri_pattern, resolve_type
        from config import HOST

        resource = uri_pattern(vid.get("pid"), host + "/video")
        thepart = {"ma:title": vid["ma:title"], "pid": vid.get("pid"), "resource": resource}
        thepart["type"] = resolve_type(vid["dc:type"])
        if part != "snippet":
            thepart["fromYt"] = []
            thepart["ma:image"] = []
            for location in vid["ma:locator"]:
                if location["@id"] is None:
                    continue
                if resolve_type(vid["dc:type"]) == "humvideo":
                    poster = uri_pattern(location["@id"] + ".jpg", HOST + "/posters")
                    thumb = uri_pattern(location["@id"] + "_thumb.jpg", HOST + "/posters")
                    thepart["ma:image"].append({"poster": poster, "thumb": thumb})
                elif resolve_type(vid["dc:type"]) == "humaudio":
                    pass
                else:
                    thepart["ma:image"].append({"ytId": location["@id"]})
                    thepart["fromYt"].append(location["@id"])
            for att in ["ma:date", "ma:description", "ma:hasLanguage", "ma:hasPolicy", "ma:isMemberOf"]:
                thepart[att] = vid.get(att)
            for annot in thepart["ma:isMemberOf"]:
                coll = connection[MONGODB_DB].assetgroups.find_one({"_id": annot["@id"]})
                if coll is not None:
                    annot["title"] = coll["@graph"]["dc:title"]
        return thepart
Example #2
0
    def client_process(self,bundle=None,list=False,client=None):
        if not bundle:
            bundle=self.bundle
        if not client:
            client = self.request.args.get("client")

        c=clients.lookup[client]()
        m=assets.find_one(bundle["@graph"]["dc:relation"])
        m["@graph"]["resource"]=uri_pattern(m["@graph"]["pid"],config.APIHOST+"/video")
        m["@graph"]["type"]=resolve_type(m["@graph"]["dc:type"])
        m["@graph"]["url"]=[]
        for url in m["@graph"]["ma:locator"]:
            if m["@graph"]["type"]=="humvideo":
                host=config.HOST+"/video"
                ext="."+url["ma:hasFormat"].replace("video/","")
            elif m["@graph"]["type"]=="humaudio":
                host=config.HOST+"/video"
                ext="."+url["ma:hasFormat"].replace("audio/","")
            elif m["@graph"]["type"]=="yt":
                host="http://youtu.be"
                ext=""
            m["@graph"]["url"].append(uri_pattern(url["@id"]+ext,host))
        resp_context=True if not list else False
        try:
            required = True if bundle["@graph"]["pid"] in m["@graph"].get("ma:hasPolicy") else False
        except TypeError:
            return bundle_400("That annotation list isn't currently associated with any media.")
        return c.serialize(bundle["@graph"],m["@graph"],resp_context,required)
Example #3
0
    def serialize_bundle(self,payload):
        payload["@graph"]["resource"]=uri_pattern(payload["@graph"]["pid"],config.APIHOST+"/"+self.endpoint)    
        payload["@graph"]["type"]=resolve_type(payload["@graph"]["dc:type"])
        payload["@graph"]["url"]=[]
        payload["@graph"]["ma:image"]=[]
        if payload["@graph"]["type"]=="humvideo":
            prefix=config.HOST + '/'
            needs_ext=True
        elif payload['@graph']['type']=='humaudio':
            prefix=config.HOST + '/'
            needs_ext=True
        elif payload["@graph"]["type"]=="yt":
            prefix="http://youtu.be"
            needs_ext=False
        fromYt=[]
        for location in payload["@graph"]["ma:locator"]:
            if needs_ext:
                ext=location["ma:hasFormat"].split("/")[-1]
                fileName= '/' + location["@id"] + "." + ext
                hexTime="{0:x}".format(int(time.time()))
                token = hashlib.md5(''.join([
                    config.AUTH_TOKEN_SECRET,
                    fileName,
                    hexTime,
                    request.remote_addr if config.AUTH_TOKEN_IP else '' 
                ])).hexdigest()
                loc = ''.join([
                    config.AUTH_TOKEN_PREFIX,
                    token, "/", hexTime, fileName
                ])
                poster=uri_pattern(location["@id"]+".jpg",config.HOST+"/posters")
                thumb=uri_pattern(location["@id"]+"_thumb.jpg",config.HOST+"/posters")
                payload["@graph"]["ma:image"].append({"poster":poster,"thumb":thumb})
            else:
                loc=location["@id"]
                fromYt.append(loc)
                payload["@graph"]["ma:image"].append({"ytId":loc})
            payload["@graph"]["url"].append(uri_pattern(loc,prefix))
        ytThumbs=getYtThumbs(fromYt)
        for image in payload["@graph"]["ma:image"]:
            if image.get("ytId"):
                image["thumb"] = ytThumbs[image["ytId"]]["thumb"]
                image["poster"] = ytThumbs[image["ytId"]]["poster"]
                image.pop("ytId",None)
        for annot in payload["@graph"]["ma:isMemberOf"]:
            coll=ags.find_one({"_id":annot["@id"]})
            annot["title"]=coll["@graph"]["dc:title"]
            try:
                details=annotations.find_one({"_id":annot["restrictor"]})
                annot["transcript"]=bool(details['@graph']['vcp:playSettings']['vcp:showTranscript'])
            except (KeyError, TypeError):
                annot["transcript"] = False

	try:
            for track in payload["@graph"]["ma:hasRelatedResource"]:
            	track["@id"]=uri_pattern(track["@id"],config.HOST+"/text")
	except KeyError:
	    pass
        return mongo_jsonify(payload["@graph"])
Example #4
0
    def serialize_bundle(self,payload):
        if payload:
            v=assets.find({"@graph.ma:isMemberOf.@id":payload["_id"]})
            payload["@graph"]["videos"]=[]
            if not is_enrolled(payload) and not (payload['@graph']['dc:coverage'] == 'public'):
                v=self.auth_filter(v)
            thumbRetriever=[]
            for vid in v:
                if self.request.args.get("full",False):
                    resource=uri_pattern(vid["@graph"]["pid"],config.APIHOST+"/video")
                    vid["@graph"]["type"]=resolve_type(vid["@graph"]["dc:type"])
                    vid["@graph"]["resource"]=resource
                    vid["@graph"]["ma:image"]=[]

                    annot=self.find_by_relations(vid['@graph']['pid'], payload['_id'])
                    try:
                        vid['@graph']['transcript']=bool(annot['@graph']['vcp:playSettings']['vcp:showTranscript'])
                    except (TypeError, KeyError):
                        vid['@graph']['transcript']=False

                    if vid["@graph"]["type"]=="humvideo":
                        needs_ext=True
                    elif 'type' in payload['@graph'] and payload['@graph']['type']=='humaudio':
                        needs_ext=True
                    elif vid["@graph"]["type"]=="yt":
                        needs_ext=False
                    for location in vid["@graph"]["ma:locator"]:
                        if needs_ext:
                            poster=uri_pattern(location["@id"]+".jpg",config.HOST+"/posters")
                            thumb=uri_pattern(location["@id"]+"_thumb.jpg",config.HOST+"/posters")
                            vid["@graph"]["ma:image"].append({"poster":poster,"thumb":thumb})
                        else:
                            loc=location["@id"]
                            vid["@graph"]["ma:image"].append({"ytId":loc})
                            thumbRetriever.append(loc)
                    payload["@graph"]['videos'].append(vid["@graph"])
                else:
                    payload["@graph"]["videos"].append(assets.Video.make_part(vid["@graph"],config.APIHOST,self.request.args.get("part","details")))
                    thumbRetriever.extend(payload["@graph"]["videos"][-1].get("fromYt"))
                    payload["@graph"]["videos"][-1].pop("fromYt",None)
            payload["@graph"]["type"]=resolve_type(payload["@graph"]["dc:type"])
            ytThumbs=getYtThumbs(thumbRetriever)
            for vid in payload["@graph"]["videos"]:
                for image in vid["ma:image"]:
                    if image.get("ytId"):
			try:
			    image["thumb"] = ytThumbs[image["ytId"]]["thumb"]
			    image["poster"] = ytThumbs[image["ytId"]]["poster"]
			except KeyError:
			    image["thumb"] = None
			    image["poster"] = None
                        image.pop("ytId",None)
            return mongo_jsonify(payload["@graph"])
        else:
            return mongo_jsonify({})
Example #5
0
    def serialize_bundle(self,payload):
        if payload:
            v=assets.find({"@graph.ma:isMemberOf.@id":payload["_id"]})
            payload["@graph"]["videos"]=[]
            if not is_enrolled(payload) and not (payload['@graph']['dc:coverage'] == 'public'):
                v=self.auth_filter(v)
            thumbRetriever=[]
            for vid in v:
                if self.request.args.get("full",False):
                    resource=uri_pattern(vid["@graph"]["pid"],config.APIHOST+"/video")    
                    vid["@graph"]["type"]=resolve_type(vid["@graph"]["dc:type"])
                    vid["@graph"]["resource"]=resource
                    vid["@graph"]["ma:image"]=[]
                    
                    annot=self.find_by_relations(vid['@graph']['pid'], payload['_id'])
                    try:
                        vid['@graph']['transcript']=bool(annot['@graph']['vcp:playSettings']['vcp:showTranscript'])
                    except (TypeError, KeyError):
                        vid['@graph']['transcript']=False

                    if vid["@graph"]["type"]=="humvideo":
                        needs_ext=True
                    elif vid["@graph"]["type"]=="yt":
                        needs_ext=False
                    for location in vid["@graph"]["ma:locator"]:
                        if needs_ext:
                            poster=uri_pattern(location["@id"]+".jpg",config.HOST+"/posters")
                            thumb=uri_pattern(location["@id"]+"_thumb.jpg",config.HOST+"/posters")
                            vid["@graph"]["ma:image"].append({"poster":poster,"thumb":thumb})
                        else:
                            loc=location["@id"]
                            vid["@graph"]["ma:image"].append({"ytId":loc})
                            thumbRetriever.append(loc)
                    payload["@graph"]['videos'].append(vid["@graph"])
                else:
                    payload["@graph"]["videos"].append(assets.Video.make_part(vid["@graph"],config.APIHOST,self.request.args.get("part","details")))
                    thumbRetriever.extend(payload["@graph"]["videos"][-1].get("fromYt"))
                    payload["@graph"]["videos"][-1].pop("fromYt",None)
            payload["@graph"]["type"]=resolve_type(payload["@graph"]["dc:type"])
            ytThumbs=getYtThumbs(thumbRetriever)
            for vid in payload["@graph"]["videos"]:
                for image in vid["ma:image"]:
                    if image.get("ytId"):
                        image["thumb"] = ytThumbs[image["ytId"]]["thumb"]
                        image["poster"] = ytThumbs[image["ytId"]]["poster"]
                        image.pop("ytId",None)
            return mongo_jsonify(payload["@graph"])
        else:
            return mongo_jsonify({})
Example #6
0
 def get_list(self):
     alist=[]
     self.bundle=self.auth_filter()
     if self.bundle:
         for d in self.bundle:
             d["@graph"]["resource"]=uri_pattern(d["@graph"]["pid"],config.APIHOST+"/"+self.endpoint)
             d["@graph"]["type"]=resolve_type(d["@graph"]["dc:type"])
             alist.append(d["@graph"])
     return mongo_jsonify(alist)
Example #7
0
 def get_list(self):
     alist=[]
     self.bundle=self.auth_filter()
     for d in self.bundle:
         if self.request.args.get("client",None):
             alist.append(self.client_process(d,True))
         else:
             d["@graph"]["resource"]=uri_pattern(d["@graph"]["pid"],config.APIHOST+"/"+self.endpoint)
             alist.append(d["@graph"])
     return mongo_jsonify(alist)
Example #8
0
 def get_list(self):
     alist=[]
     self.bundle=self.auth_filter()
     for d in self.bundle:
         client = self.request.args.get("client",None)
         if client:
             alist.append(self.client_process(d,True))
         else:
             d["@graph"]["resource"]=uri_pattern(d["@graph"]["pid"],config.APIHOST+"/"+self.endpoint)
             alist.append(d["@graph"])
     return mongo_jsonify(alist)
Example #9
0
 def make_part(self, vid, host, part):
     from helpers import uri_pattern, resolve_type
     from config import HOST
     resource = uri_pattern(vid.get("pid"), host + "/video")
     thepart = {
         "ma:title": vid["ma:title"],
         "pid": vid.get("pid"),
         "resource": resource
     }
     thepart['type'] = resolve_type(vid['dc:type'])
     if part != "snippet":
         thepart["fromYt"] = []
         thepart["ma:image"] = []
         for location in vid["ma:locator"]:
             if location['@id'] is None:
                 continue
             if resolve_type(vid["dc:type"]) == "humvideo":
                 poster = uri_pattern(location["@id"] + ".jpg",
                                      HOST + "/posters")
                 thumb = uri_pattern(location["@id"] + "_thumb.jpg",
                                     HOST + "/posters")
                 thepart["ma:image"].append({
                     "poster": poster,
                     "thumb": thumb
                 })
             elif resolve_type(vid['dc:type']) == 'humaudio':
                 pass
             else:
                 thepart["ma:image"].append({"ytId": location["@id"]})
                 thepart["fromYt"].append(location["@id"])
         for att in [
                 "ma:date", "ma:description", "ma:hasLanguage",
                 "ma:hasPolicy", "ma:isMemberOf"
         ]:
             thepart[att] = vid.get(att)
         for annot in thepart["ma:isMemberOf"]:
             coll = connection[MONGODB_DB].assetgroups.find_one(
                 {"_id": annot["@id"]})
             if coll is not None:
                 annot["title"] = coll["@graph"]["dc:title"]
     return thepart
Example #10
0
 def set_resource(self):
     self.bundle["@graph"]["resource"]=uri_pattern(self.bundle["@graph"]["pid"],config.APIHOST+"/"+self.endpoint)