def get_list(self): if "concise" in self.request.args: self.bundle = self.auth_filter() return mongo_jsonify(map(lambda x: x['@graph'], self.bundle)) alist = [] self.bundle = self.auth_filter() thumbRetriever = [] for d in self.bundle: alist.append( self.model.make_part(d["@graph"], config.APIHOST, self.request.args.get("part", "details"))) thumbRetriever.extend(alist[-1].get("fromYt")) alist[-1].pop("fromYt", None) ytThumbs = getYtThumbs(thumbRetriever) for vid in alist: for image in vid["ma:image"]: if image.get("ytId"): try: image["thumb"] = ytThumbs[image["ytId"]]["thumb"] image["poster"] = ytThumbs[image["ytId"]]["poster"] except Exception: image["thumb"] = None image["poster"] = None image.pop("ytId", None) return mongo_jsonify(alist)
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"])
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({})
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({})
def get_list(self): alist=[] self.bundle=self.auth_filter() thumbRetriever=[] for d in self.bundle: alist.append(self.model.make_part(d["@graph"],config.APIHOST,self.request.args.get("part","details"))) thumbRetriever.extend(alist[-1].get("fromYt")) alist[-1].pop("fromYt",None) ytThumbs=getYtThumbs(thumbRetriever) for vid in alist: for image in vid["ma:image"]: if image.get("ytId"): try: image["thumb"] = ytThumbs[image["ytId"]]["thumb"] image["poster"] = ytThumbs[image["ytId"]]["poster"] except Exception: image["thumb"] = None image["poster"] = None image.pop("ytId",None) return mongo_jsonify(alist)