def append_file_as_asset_content(repo, asset_id, file_name, file_data, basics=None): asset_content_type_list = get_asset_content_records(repo) acfc = repo.get_asset_content_form_for_create(asset_id, asset_content_type_list) acfc.set_genus_type(get_asset_content_genus_type(file_name)) try: acfc.add_display_name(utilities.create_display_text(file_name)) except AttributeError: acfc.display_name = file_name data = DataInputStream(file_data) data.name = file_name acfc.set_data(data) if basics is not None: acfc = utilities.set_form_basics(acfc, basics) ac = repo.create_asset_content(acfc) # really stupid, but set the data again, because for filesystem impl # the ID above will be off by one-ish -- we need it to match the # AssetContent ID, so re-set it. # have to set it above so that the filesystem adapter kicks in on update data.seek(0) acfu = repo.get_asset_content_form_for_update(ac.ident) acfu.set_data(data) repo.update_asset_content(acfu) return repo.get_asset(asset_id), ac
def append_vtt_file_as_asset_content(repo, asset_id, file_name, file_data, locale='en'): asset_content_type_list = get_asset_content_records(repo) asset_content_type_list.append(VTT_ASSET_CONTENT_RECORD_TYPE) acfc = repo.get_asset_content_form_for_create(asset_id, asset_content_type_list) acfc.set_genus_type(VTT_ASSET_CONTENT_GENUS_TYPE) try: acfc.add_display_name(utilities.create_display_text(file_name)) except AttributeError: acfc.display_name = file_name data = DataInputStream(file_data) data.name = file_name locale = utilities.convert_two_digit_lang_code_to_locale_object( locale).language_type acfc.add_vtt_file(data, locale) repo.create_asset_content(acfc)
def add_vtt_file_to_asset(repo, asset_id, file_name, file_data, locale='en'): asset_contents = repo.get_asset_contents_by_genus_type_for_asset( VTT_ASSET_CONTENT_GENUS_TYPE, asset_id) if asset_contents.available() > 0: data = DataInputStream(file_data) data.name = file_name locale = utilities.convert_two_digit_lang_code_to_locale_object( locale).language_type asset_content = asset_contents.next() form = repo.get_asset_content_form_for_update(asset_content.ident) if locale in form._my_map['fileIds']: form.edit_vtt_file(data, locale) else: form.add_vtt_file(data, locale) repo.update_asset_content(form) else: append_vtt_file_as_asset_content(repo, asset_id, file_name, file_data, locale)
def replace_asset_main_content(repo, asset_id, file_name, file_data): """search for all non-alt / non-description / non-VTT / non-transcript asset contents and pick the first one. Assume that is the main content""" asset = repo.get_asset(asset_id) asset_contents = asset.get_asset_contents() if asset_contents.available() > 0: # filter on genusTypeId...grab first non-accessibility one for asset_content in asset_contents: if asset_content.genus_type in [ALT_TEXT_ASSET_CONTENT_GENUS_TYPE, MEDIA_DESCRIPTION_ASSET_CONTENT_GENUS_TYPE, TRANSCRIPT_ASSET_CONTENT_GENUS_TYPE, VTT_ASSET_CONTENT_GENUS_TYPE]: continue form = repo.get_asset_content_form_for_update(asset_content.ident) data = DataInputStream(file_data) data.name = file_name form.set_data(data) repo.update_asset_content(form) break
asset_name = raw_input("Enter Asset Name*: ") asset_desc = raw_input("Enter Asset Description: ") if asset_name: asset_form = grp_as_repo.get_asset_form_for_create([]) asset_form.display_name = asset_name asset_form.description = asset_desc asset_obj = grp_as_repo.create_asset(asset_form) print "\n Asset created successfully." # Create AssetContent assetcontents_count = int( raw_input("Enter No. of AssetContents to be added*: ")) for i in xrange(0, assetcontents_count): print "Adding AssetContent %d" % (i + 1) asset_content_type_list = [] assetcontent_form = grp_as_repo.get_asset_content_form_for_create( asset_obj.ident, asset_content_type_list) assetcontent_name = raw_input("Enter AssetContent Name*: ") assetcontent_desc = raw_input("Enter AssetContent Description: ") if assetcontent_name: assetcontent_form.display_name = assetcontent_name assetcontent_form.description = assetcontent_desc # To upload file filepath = raw_input("Enter path of file to be uploaded*: ") if os.path.exists(filepath): file_obj = open(filepath, 'r') assetcontent_form.set_data(DataInputStream(file_obj)) assetcontent_obj = grp_as_repo.create_asset_content( assetcontent_form) print "\n AssetContent created successfully."