def post(self, request, *args, **kwargs): content = request.POST['content'] try: oembed_preview = providers.request(content) except ProviderNotFoundException: oembed_preview = {} # Always generate web_preview as fallback for oembed_preview try: title, description, image = web_preview(content, parser='html.parser') except requests.exceptions.InvalidURL: return JsonResponse({'preview': None, 'title': None}) except webpreview.excepts.EmptyURL: return JsonResponse({'preview': None, 'title': None}) if 'html' in oembed_preview: preview_html = oembed_preview['html'] elif image: preview_html = f'<img src="{image}" alt="Website Preview" />' else: preview_html = '<div class="unavailable">Preview not available for this URL</div>' if 'title' in oembed_preview: title = oembed_preview['title'] return JsonResponse({'preview': preview_html, 'title': title})
def update_profile_reel_thumbnail(user_id): profile = dillo.models.profiles.Profile.objects.get(user_id=user_id) oembed_data = providers.request(profile.reel) if 'thumbnail_url' not in oembed_data: return url = oembed_data['thumbnail_url'] log.debug("Update profile for user %i" % user_id) download_image_from_web(url, profile.reel_thumbnail_16_9)
def to_native(self, value): if not value or not standalone_url_re.match(value): return "" url = value.strip() try: response = providers.request(url, **self.params) except ProviderException: return "" else: return full_handler(url, response, **self.params)
def post(self, request, *args, **kwargs): content = request.POST['content'] try: preview = providers.request(content) except ProviderNotFoundException: preview = {} preview_default = 'Preview not available for this link.' preview_html = preview_default if 'html' not in preview else preview['html'] preview_title = None if 'title' not in preview else preview['title'] return JsonResponse({'preview': preview_html, 'title': preview_title})
def update_profile_reel_thumbnail(user_id): profile = dillo.models.profiles.Profile.objects.get(user_id=user_id) oembed_data = providers.request(profile.reel) if 'thumbnail_url' not in oembed_data: return url = oembed_data['thumbnail_url'] hashed_path = download_image_from_web(url, dillo.models.posts.PostMediaImage()) log.debug("Update profile for user %i" % user_id) dillo.models.profiles.Profile.objects.filter(user_id=user_id).update( reel_thumbnail_16_9=hashed_path)
def to_native(self, value): if not value or not standalone_url_re.match(value): return "" url = value.strip() try: response = providers.request(url, **self.params) except ProviderException: return "" else: html = full_handler(url, response, **self.params) # Tweak for youtube to hide controls and info bars. html = html.replace('feature=oembed', 'feature=oembed&showinfo=0&controls=0') return html
def to_native(self, value): if not value or not standalone_url_re.match(value): return "" url = value.strip() if value == 'https://vimeo.com/85425318': return "<iframe src=\"//player.vimeo.com/video/85425318\" hard=\"code\" width=\"1024\" height=\"576\" frameborder=\"0\" title=\"How it works - Cares\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>" try: response = providers.request(url, **self.params) except ProviderException: return "" except URLError: return "" else: html = full_handler(url, response, **self.params) # Tweak for youtube to hide controls and info bars. html = html.replace('feature=oembed', 'feature=oembed&showinfo=0&controls=0') return html
def to_representation(self, value): if not value or not standalone_url_re.match(value): return "" url = value.strip() if value == 'https://vimeo.com/85425318': return "<iframe src=\"//player.vimeo.com/video/85425318\" " \ "hard=\"code\" width=\"1024\" height=\"576\" " \ "frameborder=\"0\" title=\"How it works - Cares\" " \ "webkitallowfullscreen mozallowfullscreen " \ "allowfullscreen></iframe>" try: response = providers.request(url, **self.params) except ProviderException: return "" except URLError: return "" else: html = full_handler(url, response, **self.params) # Tweak for youtube to hide controls and info bars. html = html.replace('feature=oembed', 'feature=oembed&showinfo=0&controls=0') return html