An open API service indexing awesome lists of open source software.

https://github.com/gri38/hyperlink_preview

Small visual preview and brief description of a http link: this library gets the data.
https://github.com/gri38/hyperlink_preview

hyperlink og-parser ogp ogp-image ogp-meta opengraph opengraph-data opengraph-parser opengraph-tags preview

Last synced: 3 days ago
JSON representation

Small visual preview and brief description of a http link: this library gets the data.

Awesome Lists containing this project

README

          

[![HitCount](https://hits.dwyl.com/gri38/hyperlink_preview.svg?style=flat-square&show=unique)](http://hits.dwyl.com/gri38/hyperlink_preview) ![badge workflow](https://github.com/gri38/hyperlink_preview/actions/workflows/python-workflow.yml/badge.svg) ![badge covergae](https://codecov.io/gh/gri38/hyperlink_preview/branch/main/graph/badge.svg)
# hyperlink_preview

## Purpose

Hyperlink_preview allows getting data needed to display a small visual preview of a http link.
It searches deeper than only ` 50px.
For the sake of efficiency:
- **read only bytes necessary** to know the dimensions of the images (not the whole image)
- **parallelized requests** to all the images

However, if the target link contains a lot of pictures, it can take a while (one to several seconds) to do all the requests. A hyperlink preview may need to be displayed quickly (for instance: on mouse hover). In that case:

### Get all data except image first, then image
```python
import hyperlink_preview as HLP

hlp = HLP.HyperLinkPreview(url="https://en.wikipedia.org/wiki/Your_Name")
if hlp.is_valid:
preview_data = hlp.get_data(wait_for_imgs=False)
# returns as soon as the data are fetched, but don't wait to "parse" all images tags if needed.
# it allows you to display a spinner as link preview image (or anything else to keep your user waiting).

# ... later you can get the remaining image data if needed:
if preview_data["image"] is None:
preview_data = hlp.get_data(wait_for_imgs=True)
```