media

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: BSD-3-Clause Imports: 18 Imported by: 5

Documentation

Overview

package media provides methods for working with or deriving media-(N).json files.

Index

Constants

View Source
const TIME_FORMAT string = "Jan 2, 2006, 3:04 PM"

TIME_FORMAT is a time.Parse compatible string representing the manner in which Instagram datetime strings are encoded.

Variables

This section is empty.

Functions

func AppendHashes added in v0.2.0

func AppendHashes(ctx context.Context, opts *AppendHashesOptions, body []byte) ([]byte, error)

AppendHashes will append a variety of hashes to 'body' derived from its contents. For images it will append a "file_hash" (SHA-256) and a "perceptual_hash" JSON properties. For images it will append a "file_hash" (SHA-256) JSON property. Media file URIs are derived from the "path" JSON property in 'body'. These URIs are expected to be relative and resolvable in 'bucket'.

func AppendMediaIDFromPath added in v0.1.2

func AppendMediaIDFromPath(ctx context.Context, body []byte) ([]byte, error)

AppendMediaIDFromPath will derive a media ID from the `path` JSON property in 'body' and use that value to append a `media_id` JSON property to 'body'. This method is deprecated.

func AppendTakenAtTimestamp added in v0.1.2

func AppendTakenAtTimestamp(ctx context.Context, body []byte) ([]byte, error)

AppendTakenAtTimestamp will look for a `taken_at` JSON property in 'body' and use its value to derive a Unix timestamp which will be used as the value of a new `taken` JSON property (which is appended to 'body').

func AppendTakenAtTimestampWithCallback added in v0.2.3

func AppendTakenAtTimestampWithCallback(ctx context.Context, body []byte, cb AppendTakenCallback) ([]byte, error)

func DeriveMediaIDFromPath added in v0.1.2

func DeriveMediaIDFromPath(path string) string

DeriveMediaIDFromPath will return a (old) media ID derived from 'path'. This method is deprecated.

func DeriveMediaIdFromString added in v0.1.2

func DeriveMediaIdFromString(input string) string

DeriveMediaIdFromString returns the SHA-1 value of 'input'. Because Instagram doesn't include stable identifiers in its media.json output we need to derive one from some element associated with each post/photo. We used to do this using the file path but since those changed sometime between October 2020 and April 2022. So rather than picking a specific key whose value or formatting may change again this method exists to consisitently hash an arbitrary string supplied by consumers of this package. None of this should be necessary but until there are stable IDs the Instagram exports this is what we get.

func ExpandCaption added in v0.1.2

func ExpandCaption(ctx context.Context, body []byte) ([]byte, error)

func Open added in v0.1.2

func Open(ctx context.Context, media_uri string) (io.ReadCloser, error)

Open is a convenience method to create a new `blob.Bucket` instance derived from the root directory in 'media_uri' and then using that bucket to return a new `io.ReadCloser` instance for 'media_uri'.

Types

type AppendHashesOptions added in v0.2.1

type AppendHashesOptions struct {
	// A valid gocloud.dev/blob.Bucket where source media files associated with a post are found
	Bucket *blob.Bucket
	// A boolean flag indicating that a file hash (SHA-256) of the associated media file should be appended to an Instagram post
	FileHash bool
	// A boolean flag indicating that a perceptual of the associated media file should be appended to an Instagram post
	PerceptualHash bool
}

type AppendHashesOptions provides configuration options for appending hashes to an Instagram post.

type AppendTakenCallback added in v0.2.3

type AppendTakenCallback func(time.Time) (time.Time, error)

AppendTakenCallback is a user-defined callback function to be applied to `time.Time` instances in the `AppendTakenAtTimestampWithCallback` method after an initial datetime string has been parsed but before a Unix timestamp is appeneded (to an Instagram post).

type Archive added in v0.1.2

type Archive struct {
	// Photos is the list of photos (posts) in an archive.
	Photos []*Photo `json:"photos"`
}

Type Archive is a struct representing the structure of an Instagram media.json file.

type Caption

type Caption struct {
	Body     string   `json:"body"`
	Excerpt  string   `json:"excerpt"`
	Hashtags []string `json:"hashtags"`
	Users    []string `json:"users"`
}

func ParseCaption added in v0.1.2

func ParseCaption(ctx context.Context, body string) (*Caption, error)

type Photo added in v0.1.2

type Photo struct {
	// Caption is the caption associated with the post
	Caption string `json:"caption"`
	// Taken is the datetime string when the post was published
	TakenAt  string `json:"taken_at"`
	Location string `json:"location,omitempty"`
	// Path is the relative URI for the media element associated with the post
	Path    string `json:"path"`
	MediaId string `json:"media_id,omitempty"`
}

Type Photo is a struct containing data associated with an Instagram post. The name `Photo` reflects the naming conventions of the (old) Instagram media.json files.

func DerivePhotosFromReader added in v0.1.2

func DerivePhotosFromReader(ctx context.Context, r io.Reader, photos []*Photo) ([]*Photo, error)

DerivePhotosFromReader will derive zero or more Instagram photos from the body of 'r' appending each to 'photos'.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL