twitter

package
v1.0.1-0...-39f75b5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 22 Imported by: 0

README

推特(Twitter/X)导入器

支持

黄色表示保留但未设置,红色表示不(完全)支持。

@startmindmap
+ Twitter
++ 范围
+++ 自己发表的
+++ 引用别人的
++++[#red] 显示被引用的
++++ 显示被引用的链接
+++ 转推
++++[#red] 显示被转发的
+++[#red] 评论
++++ 对自己的直接评论
++ 内容
+++ 正文
++++ 标签
+++++ 添加为文章标签
+++ 图片
+++ 视频
++++ 原始大小
++++[#yellow] 海报
++++[#yellow] 预加载(preload)
+++ ALT
+++[#red] 编辑历史
+++ 提及
@endmindmap

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCommands

func CreateCommands(client func() *clients.ProtoClient) *cobra.Command

Types

type CreatedAt

type CreatedAt int32

func (*CreatedAt) UnmarshalJSON

func (t *CreatedAt) UnmarshalJSON(data []byte) error

type EntityURL

type EntityURL struct {
	URL      string `json:"url"`
	Expanded string `json:"expanded_url"`
}

type FullText

type FullText string

func (*FullText) UnmarshalJSON

func (s *FullText) UnmarshalJSON(data []byte) error

type HiResImages

type HiResImages struct {
	// contains filtered or unexported fields
}

https://pbs.twimg.com/media/GA0Qq0DbYAEltfQ?format=jpg&name=4096x4096

func (*HiResImages) Open

func (h *HiResImages) Open(name string) (fs.File, error)

type Importer

type Importer struct {
	// contains filtered or unexported fields
}

func New

func New(root fs.FS, client *clients.ProtoClient) *Importer

func (*Importer) Execute

func (i *Importer) Execute(withoutAssets bool) error

TODO 允许增量导入(对存在相同ID的推文只创建一条对应的碎碎念)。

type MentionedUser

type MentionedUser struct {
	Name       string `json:"name"`        // 昵称
	ScreenName string `json:"screen_name"` // 帐号
	ID         string `json:"id"`
}

type Tweet

type Tweet struct {
	// 不是很清楚这个字段。
	// 看起来都是 false。
	Retweeted bool `json:"retweeted"`

	// 推文的 ID
	ID string `json:"id"`

	Truncated bool `json:"truncated"`

	// 是否是回复。
	InReplyToStatusID string `json:"in_reply_to_status_id"`

	// 正文内容。
	// 使用  Markdown 代替。
	FullText FullText `json:"full_text"`

	// 创建时间。
	CreatedAt CreatedAt `json:"created_at"`

	ExtendedEntities struct {
		Media []struct {
			HTTP      string `json:"media_url"`
			HTTPS     string `json:"media_url_https"`
			VideoInfo struct {
				Variants []struct {
					Bitrate     int64  `json:"bitrate,string"`
					ContentType string `json:"content_type"`
					URL         string `json:"url"`
				} `json:"variants"`
			} `json:"video_info"`
		} `json:"media"`
		HashTags []struct {
			Text string `json:"text"`
		} `json:"hashtags"`
		URLs         []EntityURL     `json:"urls"`
		UserMentions []MentionedUser `json:"user_mentions"`
	} `json:"extended_entities"`

	// 有  expanded 就不用
	Entities struct {
		Media []struct {
			HTTP      string `json:"media_url"`
			HTTPS     string `json:"media_url_https"`
			VideoInfo struct {
				Variants []struct {
					Bitrate     int64  `json:"bitrate,string"`
					ContentType string `json:"content_type"`
					URL         string `json:"url"`
				} `json:"variants"`
			} `json:"video_info"`
		} `json:"media"`
		HashTags []struct {
			Text string `json:"text"`
		} `json:"hashtags"`
		URLs         []EntityURL     `json:"urls"`
		UserMentions []MentionedUser `json:"user_mentions"`
	} `json:"entities"`
	// contains filtered or unexported fields
}

代表一条从 data/tweets.js 里面提取的推文数据。 TODO 不是很清楚两个 entities 之间的关系,有时候没有后者,有时候有。 TODO 可能需要合并?目前部分数据只使用 expanded。

func ParseTweets

func ParseTweets(fsys fs.FS) ([]*Tweet, error)

func (*Tweet) Assets

func (t *Tweet) Assets(all bool) ([]string, []VideoAsset)

func (*Tweet) IsSelfTweet

func (t *Tweet) IsSelfTweet() bool

是否是独立发推(而不是回复之类)。

func (*Tweet) Markdown

func (t *Tweet) Markdown() string

func (*Tweet) TagNames

func (t *Tweet) TagNames() []string

type VideoAsset

type VideoAsset struct {
	FileName      string
	PosterURL     string
	Poster        string
	ContentType   string
	Width, Height int
}

Jump to

Keyboard shortcuts

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