def add_music(link=None, title=None, artist=None): cover_art = get_cover_art(title, artist) music = get_music_file(link, True) music_content = music[0] if music else None type = music[1] if music else None content_key = Content.add_music(origin=link, artist=artist, title=title, data=music_content, image=cover_art, user=UserData.add_or_get_user(), type=type if type else 'music') return content_key
def add_image(link=None, data=None): if not link and not data: raise FieldNotFoundException('no link or data found when adding image') image_content = None if not data: result = urlfetch.fetch(link) if result.status_code != 200: raise ImageNotFoundException('image %s not found' % str(link)) image_content = result.content image_type = get_image_type(link) else: image_content = decode_base64_image(data) image_type = get_image_type(data) link = 'binary data' if image_content: content_key = Content.add_image(origin=link, data=image_content, type=image_type, user=UserData.add_or_get_user()) return content_key return None