midjourney

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 14 Imported by: 2

README

go-midjourney

Experimental and unfinished Go package for interacting the unofficial MidJourney API powering midjourney.com.

Go Reference GitHub tag (latest SemVer) Actions Status GitHub issues GitHub pull requests License Status

Import

import "github.com/jimeh/go-midjourney"

Documentation

Please see the Go Reference for documentation and examples.

License

MIT

Documentation

Overview

Package midjourney provides a basic read-only API client for MidJourney. As there is no official API, it uses the same API as the MidJourney website uses, meaning that it is subject to change at any time, breaking this package.

Index

Constants

View Source
const FromDateFormat = "2006-01-02 15:04:05.999999"
View Source
const TimeFormat = "2006-01-02 15:04:05.999999"

Variables

View Source
var (
	Err                  = errors.New("midjourney")
	ErrNoAuthToken       = fmt.Errorf("%w: no auth token", Err)
	ErrInvalidAuthToken  = fmt.Errorf("%w: invalid auth token", Err)
	ErrInvalidAPIURL     = fmt.Errorf("%w: invalid API URL", Err)
	ErrInvalidHTTPClient = fmt.Errorf("%w: invalid HTTP client", Err)
	ErrNotFound          = fmt.Errorf("%w: not found", Err)
	ErrResponse          = fmt.Errorf("%w: response", Err)
	ErrResponseStatus    = fmt.Errorf("%w: response status", ErrResponse)

	DefaultAPIURL = url.URL{
		Scheme: "https",
		Host:   "www.midjourney.com",
		Path:   "/api/",
	}

	DefaultUserAgent = "go-midjourney/0.1.0" // x-release-please-version
)
View Source
var (
	ErrCollectionIDRequired = fmt.Errorf("%w: collection id required", Err)
	ErrCollectionNotFound   = fmt.Errorf("%w: collection", ErrNotFound)
)
View Source
var ErrJobIDsRequired = fmt.Errorf("%w: job IDs required", Err)
View Source
var ErrUserIDRequired = fmt.Errorf("%w: user id required", Err)

Functions

This section is empty.

Types

type APIClient added in v0.1.0

type APIClient struct {
	HTTPClient HTTPClient
	APIURL     *url.URL
	AuthToken  string
	UserAgent  string
	Logger     zerolog.Logger
}

func NewAPI added in v0.1.0

func NewAPI(options ...Option) (*APIClient, error)

func (*APIClient) Delete added in v0.1.0

func (ac *APIClient) Delete(
	ctx context.Context,
	path string,
	params url.Values,
	body any,
	x any,
) error

func (*APIClient) Do added in v0.1.0

func (ac *APIClient) Do(req *http.Request) (*http.Response, error)

func (*APIClient) Get added in v0.1.0

func (ac *APIClient) Get(
	ctx context.Context,
	path string,
	params url.Values,
	x any,
) error

func (*APIClient) Patch added in v0.1.0

func (ac *APIClient) Patch(
	ctx context.Context,
	path string,
	params url.Values,
	body any,
	x any,
) error

func (*APIClient) Post added in v0.1.0

func (ac *APIClient) Post(
	ctx context.Context,
	path string,
	params url.Values,
	body any,
	x any,
) error

func (*APIClient) Put added in v0.1.0

func (ac *APIClient) Put(
	ctx context.Context,
	path string,
	params url.Values,
	body any,
	x any,
) error

func (*APIClient) Request added in v0.1.0

func (ac *APIClient) Request(
	ctx context.Context,
	method string,
	path string,
	params url.Values,
	body any,
	result any,
) error

func (*APIClient) Set added in v0.1.0

func (ac *APIClient) Set(options ...Option) error

type AlgorithmVersion

type AlgorithmVersion string

func (*AlgorithmVersion) MarshalJSON

func (av *AlgorithmVersion) MarshalJSON() ([]byte, error)

func (*AlgorithmVersion) UnmarshalJSON

func (av *AlgorithmVersion) UnmarshalJSON(b []byte) error

type Client

type Client struct {
	API *APIClient
}

func New

func New(options ...Option) (*Client, error)

func (*Client) ArchiveDay

func (c *Client) ArchiveDay(
	ctx context.Context,
	date time.Time,
) (jobIDs []string, err error)

func (*Client) Bookmarks

func (c *Client) Bookmarks(
	ctx context.Context,
	userID string,
) (*RecentJobs, error)

func (*Client) CollectionFeed

func (c *Client) CollectionFeed(
	ctx context.Context,
	collectionID string,
) (*RecentJobs, error)

func (*Client) CollectionJobsAdd

func (c *Client) CollectionJobsAdd(
	ctx context.Context,
	collectionID string,
	jobIDs []string,
) (*CollectionJobsResult, error)

func (*Client) CollectionJobsRemove

func (c *Client) CollectionJobsRemove(
	ctx context.Context,
	collectionID string,
	jobIDs []string,
) (*CollectionJobsResult, error)

func (*Client) Collections

func (c *Client) Collections(
	ctx context.Context,
	query *CollectionsQuery,
) ([]*Collection, error)

func (*Client) CommunityFeed

func (c *Client) CommunityFeed(ctx context.Context) (*RecentJobs, error)

func (*Client) DeleteCollection

func (c *Client) DeleteCollection(
	ctx context.Context,
	collectionID string,
) (*Collection, error)

func (*Client) GetCollection

func (c *Client) GetCollection(
	ctx context.Context,
	collectionID string,
) (*Collection, error)

func (*Client) Home

func (c *Client) Home(
	ctx context.Context,
	userID string,
) (*RecentJobs, error)

func (*Client) PersonalFeed

func (c *Client) PersonalFeed(ctx context.Context) (*RecentJobs, error)

func (*Client) PutCollection

func (c *Client) PutCollection(
	ctx context.Context,
	collection *Collection,
) (*Collection, error)

func (*Client) PutCollectionData

func (c *Client) PutCollectionData(
	ctx context.Context,
	collectionID string,
	data *CollectionData,
) (*Collection, error)

func (*Client) PutCollectionFilters

func (c *Client) PutCollectionFilters(
	ctx context.Context,
	collectionID string,
	filters *CollectionFilters,
) (*Collection, error)

func (*Client) RecentJobs

func (c *Client) RecentJobs(
	ctx context.Context,
	q *RecentJobsQuery,
) (*RecentJobs, error)

func (*Client) Set

func (ac *Client) Set(options ...Option) error

func (*Client) Words

func (c *Client) Words(ctx context.Context, q *WordsQuery) ([]*Word, error)

type Collection

type Collection struct {
	CoverJobID         string          `json:"cover_job_id,omitempty"`
	Created            string          `json:"created,omitempty"`
	CreatorAvatarJobID string          `json:"creator_avatar_job_id,omitempty"`
	CreatorCoverJobID  string          `json:"creator_cover_job_id,omitempty"`
	CreatorID          string          `json:"creator_id,omitempty"`
	CreatorUsername    string          `json:"creator_username,omitempty"`
	Data               *CollectionData `json:"data,omitempty"`
	Description        string          `json:"description,omitempty"`
	Hidden             bool            `json:"hidden,omitempty"`
	ID                 string          `json:"id,omitempty"`
	NumJobs            int             `json:"num_jobs,omitempty"`
	Public             bool            `json:"public,omitempty"`
	PublicEditable     bool            `json:"public_editable,omitempty"`
	SearchTerms        []string        `json:"search_terms,omitempty"`
	Title              string          `json:"title,omitempty"`
	Workspaces         []string        `json:"workspaces,omitempty"`
}

type CollectionData

type CollectionData struct {
	Filters *CollectionFilters `json:"filters,omitempty"`
}

type CollectionFilters

type CollectionFilters struct {
	OrderBy           string `json:"orderBy,omitempty"`
	JobType           string `json:"jobType,omitempty"`
	UserIDRankedScore string `json:"user_id_ranked_score,omitempty"`
	ShowFilters       bool   `json:"showFilters,omitempty"`
}

type CollectionJobsResult

type CollectionJobsResult struct {
	Failures  []string `json:"failures,omitempty"`
	Success   bool     `json:"success,omitempty"`
	Successes []string `json:"successes,omitempty"`
}

type CollectionsQuery

type CollectionsQuery struct {
	UserID       string `url:"user_id,omitempty"`
	CollectionID string `url:"collection_id,omitempty"`
}

func (*CollectionsQuery) URLValues

func (cq *CollectionsQuery) URLValues() url.Values

type Event

type Event struct {
	Height       int      `json:"height,omitempty"`
	TextPrompt   []string `json:"textPrompt,omitempty"`
	ImagePrompts []string `json:"imagePrompts,omitempty"`
	Width        int      `json:"width,omitempty"`
	BatchSize    int      `json:"batchSize,omitempty"`
	SeedImageURL string   `json:"seedImageURL,omitempty"`
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Job

type Job struct {
	JobType           string           `json:"_job_type,omitempty"`
	Service           string           `json:"_service,omitempty"`
	ParsedParams      *ParsedJobParams `json:"_parsed_params,omitempty"`
	CurrentStatus     JobStatus        `json:"current_status,omitempty"`
	EnqueueTime       Time             `json:"enqueue_time,omitempty"`
	Event             *Event           `json:"event,omitempty"`
	Flagged           bool             `json:"flagged,omitempty"`
	FollowedByUser    bool             `json:"followed_by_user,omitempty"`
	GridID            string           `json:"grid_id,omitempty"`
	GridNum           string           `json:"grid_num,omitempty"`
	GuildID           string           `json:"guild_id,omitempty"`
	Hidden            bool             `json:"hidden,omitempty"`
	ID                string           `json:"id,omitempty"`
	ImagePaths        []string         `json:"image_paths,omitempty"`
	IsPublished       bool             `json:"is_published,omitempty"`
	LikedByUser       bool             `json:"liked_by_user,omitempty"`
	LowPriority       bool             `json:"low_priority,omitempty"`
	Metered           bool             `json:"metered,omitempty"`
	ModHidden         bool             `json:"mod_hidden,omitempty"`
	Platform          string           `json:"platform,omitempty"`
	PlatformChannel   string           `json:"platform_channel,omitempty"`
	PlatformChannelID string           `json:"platform_channel_id,omitempty"`
	PlatformMessageID string           `json:"platform_message_id,omitempty"`
	PlatformThreadID  string           `json:"platform_thread_id,omitempty"`
	Prompt            string           `json:"prompt,omitempty"`
	RankedByUser      bool             `json:"ranked_by_user,omitempty"`
	RankingByUser     int              `json:"ranking_by_user,omitempty"`
	Type              JobType          `json:"type,omitempty"`
	UserID            string           `json:"user_id,omitempty"`
	Username          string           `json:"username,omitempty"`
	FullCommand       string           `json:"full_command,omitempty"`
	ReferenceJobID    string           `json:"reference_job_id,omitempty"`
	ReferenceImageNum string           `json:"reference_image_num,omitempty"`
}

func (*Job) DiscordURL

func (j *Job) DiscordURL() string

func (*Job) ImageFilename

func (j *Job) ImageFilename() string

func (*Job) MainImageURL

func (j *Job) MainImageURL() string

func (*Job) ThumbnailURL added in v0.1.0

func (j *Job) ThumbnailURL(size ThumbnailSize) string

func (*Job) VideoURL

func (j *Job) VideoURL() string

type JobStatus

type JobStatus string
const (
	JobStatusRunning   JobStatus = "running"
	JobStatusCompleted JobStatus = "completed"
)

type JobType

type JobType string
const (
	JobTypeNull    JobType = "null"
	JobTypeGrid    JobType = "grid"
	JobTypeUpscale JobType = "upscale"
)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithAPIURL

func WithAPIURL(baseURL string) Option

func WithAuthToken

func WithAuthToken(authToken string) Option

WithAuthToken returns a new Option type which sets the auth token that the client will use. The authToken value can be fetched from the "__Secure-next-auth.session-token" cookie on the midjourney.com website.

func WithHTTPClient

func WithHTTPClient(httpClient HTTPClient) Option

func WithLogger

func WithLogger(logger zerolog.Logger) Option

func WithUserAgent

func WithUserAgent(userAgent string) Option

type Order

type Order string
const (
	OrderHot       Order = "hot"
	OrderNew       Order = "new"
	OrderOldest    Order = "oldest"
	OrderTopToday  Order = "top-today"
	OrderTopWeekly Order = "top-weekly"
	OrderTopMonth  Order = "top-month"
	OrderTopAll    Order = "top-all"
	OrderLikedTime Order = "liked_timestamp"
)

type ParsedJobParams

type ParsedJobParams struct {
	Anime    bool             `json:"anime,omitempty"`
	Aspect   string           `json:"aspect,omitempty"`
	Creative bool             `json:"creative,omitempty"`
	Fast     bool             `json:"fast,omitempty"`
	HD       bool             `json:"hd,omitempty"`
	No       []string         `json:"no,omitempty"`
	Style    string           `json:"style,omitempty"`
	Stylize  int              `json:"stylize,omitempty"`
	Test     bool             `json:"test,omitempty"`
	Testp    bool             `json:"testp,omitempty"`
	Tile     bool             `json:"tile,omitempty"`
	Upanime  bool             `json:"upanime,omitempty"`
	Upbeta   bool             `json:"upbeta,omitempty"`
	Uplight  bool             `json:"uplight,omitempty"`
	Version  AlgorithmVersion `json:"version,omitempty"`
	Vibe     bool             `json:"vibe,omitempty"`
	Video    bool             `json:"video,omitempty"`
}

type RankedScore

type RankedScore int
const (
	Unranked RankedScore = 0
	Mehd     RankedScore = 2
	Liked    RankedScore = 4
	Loved    RankedScore = 5
)

func (RankedScore) String

func (rs RankedScore) String() string

func (RankedScore) URIParam

func (rs RankedScore) URIParam() string

type RankedScores

type RankedScores []RankedScore

func (RankedScores) MarshalJSON

func (rs RankedScores) MarshalJSON() ([]byte, error)

func (RankedScores) URIParam

func (rs RankedScores) URIParam() string

URIParam returns a string representation of the RankedScores suitable for URI parameters.

func (*RankedScores) UnmarshalJSON

func (rs *RankedScores) UnmarshalJSON(data []byte) error

type RecentJobs

type RecentJobs struct {
	Query RecentJobsQuery
	Jobs  []*Job
	Page  int
}

type RecentJobsQuery

type RecentJobsQuery struct {
	Amount            int
	JobType           JobType
	OrderBy           Order
	UserIDRankedScore RankedScores
	JobStatus         JobStatus
	UserID            string
	UserIDLiked       string
	CollectionID      string
	FromDate          time.Time
	Page              int
	Prompt            string
	Personal          bool
	Dedupe            bool
	RefreshAPI        int
}

func (*RecentJobsQuery) NextPage

func (rjq *RecentJobsQuery) NextPage() *RecentJobsQuery

func (*RecentJobsQuery) URLValues

func (rjq *RecentJobsQuery) URLValues() url.Values

type ResponseError

type ResponseError struct {
	Message string `json:"error,omitempty"`
	// contains filtered or unexported fields
}

func (*ResponseError) Error

func (re *ResponseError) Error() string

func (*ResponseError) Unwrap

func (re *ResponseError) Unwrap() error

type ThumbnailSize added in v0.1.0

type ThumbnailSize int
const (
	ThumbnailSizeSmall  ThumbnailSize = 128
	ThumbnailSizeMedium ThumbnailSize = 384
	ThumbnailSizeLarge  ThumbnailSize = 640
)

type Time

type Time struct {
	time.Time
}

func (*Time) MarshalJSON

func (ct *Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

func (ct *Time) UnmarshalJSON(b []byte) (err error)

type Word

type Word struct {
	Word    string
	ImageID string
}

func (*Word) ImageURL

func (w *Word) ImageURL() string

type WordsQuery

type WordsQuery struct {
	Query  string
	Amount int
	Page   int
	Seed   int

	// RandomSeed will send a random Seed value between 0 and 9999.
	RandomSeed bool
}

func (*WordsQuery) URLValues

func (wq *WordsQuery) URLValues() url.Values

Jump to

Keyboard shortcuts

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