metadata_fetch 0.3.3

  • Readme
  • Changelog
  • Installing
  • 92

Metadata Fetch #

A dart library for extracting metadata in web pages. Supports OpenGraph, Meta, Twitter Cards, and Structured Data (Json-LD)

Usage #

Extract Metadata for a given URL #

import 'package:metadata_fetch/metadata_fetch.dart';

main() async {
  var data = extract("https://flutter.dev/"); // Use the extract() function to fetch data from the url

  print(data.title) // Flutter - Beautiful native apps in record time

  print(data.description) // Flutter is Google's UI toolkit for crafting beautiful...

  print(data.image) // https://flutter.dev/images/flutter-logo-sharing.png

  var dataAsMap = data.toMap();

}

Parsing Manually #

Get aggregated Metadata from a document

This method prioritizes Open Graph data, followed by Twitter Card, JSON-LD and finally falls back too HTML metadata.

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // get metadata
  var data = MetadataParser.parse(document);
  print(data);


}

Get Open Graph Metadata

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // get metadata
  var data = MetadataParser.OpenGraph(document);
  print(data);


}

Get Html Metadata

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // get metadata
  var data = MetadataParser.HtmlMeta(document);
  print(data);
}

Get Structured Data (Json+LD)

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // Just Json-ld schema
  var data = MetadataParser.JsonLdSchema(document);
  print(data);
}

Get Twitter Cards Metadata

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://www.epicurious.com/expert-advice/best-soy-sauce-chefs-pick-article');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // Get Twitter Card metadata
  var data = MetadataParser.TwitterCard(document);
  print(data);
}

Credit #

This library is inspired by open_graph_parser. However this one tries to be more general.

Roadmap #

  • Weighted or Preferred Metadata. Can assign custom weights for each parser to provide a fallback priority sytem
  • Improve Documentation

Questions, Bugs, and Feature Requests #

Please forward all queries about this project to the issue tracker.

0.3.3 #

  • Relative image url now uses the absolute path

0.3.2 #

  • Improved JsonLD Parser

0.3.1 #

  • Added JSON serialization

0.3.0 #

  • Added Twitter Card Parser
  • Metadata structure now includes url

0.2.1 #

  • Minor Improvements

0.2.0 #

  • Improve API and generalized the Metadata Parser
  • Added more documentation

0.1.1 #

  • Various improvements throughout

0.1.0 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  metadata_fetch: ^0.3.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:metadata_fetch/metadata_fetch.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Health suggestions

Format lib/src/parsers/base_parser.dart.

Run dartfmt to format lib/src/parsers/base_parser.dart.

Format lib/src/parsers/htmlmeta_parser.dart.

Run dartfmt to format lib/src/parsers/htmlmeta_parser.dart.

Format lib/src/parsers/jsonld_parser.dart.

Run dartfmt to format lib/src/parsers/jsonld_parser.dart.

Format lib/src/utils/util.dart.

Run dartfmt to format lib/src/utils/util.dart.

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and metadata_fetch.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
html ^0.14.0+3 0.14.0+3
http ^0.12.0+4 0.12.1
string_validator ^0.1.3 0.1.4
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
csslib 0.16.1
http_parser 3.1.4
meta 1.2.2 1.3.0-nullsafety
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
pedantic ^1.8.0 1.9.2
test ^1.6.0