Documentation ¶
Overview ¶
package media provides methods for working with or deriving media-(N).json files.
Index ¶
- Constants
- func AppendHashes(ctx context.Context, opts *AppendHashesOptions, body []byte) ([]byte, error)
- func AppendMediaIDFromPath(ctx context.Context, body []byte) ([]byte, error)
- func AppendTakenAtTimestamp(ctx context.Context, body []byte) ([]byte, error)
- func AppendTakenAtTimestampWithCallback(ctx context.Context, body []byte, cb AppendTakenCallback) ([]byte, error)
- func DeriveMediaIDFromPath(path string) string
- func DeriveMediaIdFromString(input string) string
- func ExpandCaption(ctx context.Context, body []byte) ([]byte, error)
- func Open(ctx context.Context, media_uri string) (io.ReadCloser, error)
- func ParseTime(str_time string) (time.Time, error)
- type AppendHashesOptions
- type AppendTakenCallback
- type Archive
- type Caption
- type Photo
Constants ¶
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. I mean that's the idea anyway. IG seems to change to format they use between exports... Basically what that means is you should the `ParseTime` function (in this package) to parse IG dates.
const TIME_FORMAT_LOWER string = "Jan 2, 2006 3:04 pm"
TIME_FORMAT_LOWER is a time.Parse compatible string representing the manner in which Instagram datetimes encoded with lower-case AM/PM times.
const TIME_FORMAT_LOWER_COMMA string = "Jan 2, 2006, 3:04 pm"
TIME_FORMAT_LOWER_COMMA is a time.Parse compatible string representing the manner in which Instagram datetimes encoded with lower-case AM/PM times with dates and times separated by a comma.
const TIME_FORMAT_UPPER string = "Jan 2, 2006 3:04 PM"
TIME_FORMAT_UPPER is a time.Parse compatible string representing the manner in which Instagram datetimes encoded with upper-case AM/PM times.
const TIME_FORMAT_UPPER_COMMA string = "Jan 2, 2006, 3:04 PM"
TIME_FORMAT_UPPER_COMMA is a time.Parse compatible string representing the manner in which Instagram datetimes encoded with upper-case AM/PM times with dates and times separated by a comma.
Variables ¶
This section is empty.
Functions ¶
func AppendHashes ¶ added in v0.2.0
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
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
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 DeriveMediaIDFromPath ¶ added in v0.1.2
DeriveMediaIDFromPath will return a (old) media ID derived from 'path'. This method is deprecated.
func DeriveMediaIdFromString ¶ added in v0.1.2
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
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
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 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.