msbimport

package
v2.3.13-0...-f83e716 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: GPL-3.0 Imports: 21 Imported by: 0

README

Moe-Sticker-Bot Import Component (msbimport)

Description

This package is intended to fetch, parse, download and convert LINE and KakaoTalk Stickers from share link.

It is designed to be able to operate independentaly from moe-sticker-bot core so third party apps can also utilize this package.

此套件或CLI用於解析LINE/Kakaotalk貼圖的分享連結並下載和轉換。

此套件可獨立於moe-sticker-bot使用, 第三方App可以輕鬆利用此套件或CLI處理複雜貼圖。

CLI Usage/終端機程式使用

Source code of CLI is on: /moe-sticker-bot/cmd/msbimport

Download msbimport: 下載msbimporthttps://github.com/star-39/moe-sticker-bot/releases

msbimport --help
Usage of ./msbimport:
  -convert
    	Convert to Telegram format(WEBP/WEBM) 轉換為Telegram格式。
  -dir string
    	Where to put sticker files. 指定存放貼圖檔的資料夾。
  -json
    	Output JSON serialized LineData, useful when integrating with other apps. 列印LineData為JSON。
  -link string
    	Import link(LINE/kakao) 分享連結。
  -log_level string
    	Log level (default "debug")
        
msbimport --link https://store.line.me/stickershop/product/27286

msbimport --link https://store.line.me/stickershop/product/27286 --convert --json

API Usage

A typical workflow is to call parseImportLink then prepareImportStickers.

go get -u https://github.com/star-39/moe-sticker-bot
import "github.com/star-39/moe-sticker-bot/pkg/msbimport"

//Create a context, which can be used to interrupt the process.
ctx, _ := context.WithCancel(context.Background())

//Create a empty LineData struct pointer.
ld := &msbimport.LineData{}

//LineData will be parsed to ld.
warn, err := msbimport.ParseImportLink("https://store.line.me/stickershop/product/27286", ld)
if err != nil {
    //handle error here.
}
if warn != "" {
    //handle warning message here.
}

err = msbimport.PrepareImportStickers(ctx, ld, "./", false)
if err != nil {
    //handle error here.
}

//If I18n title is needed(LINE only), TitleWg must be waited.
ld.TitleWg.Wait()
println(ld.I18nTitles)

for _, lf := range ld.Files {
    //Each file has its own waitgroup and musted be waited.
    lf.Wg.Wait()
    if lf.CError != nil {
        //hanlde sticker error here.
    }
    println(lf.OriginalFile)
    println(lf.ConvertedFile)
    //...
}

//Your stickers files will appear in the work dir you specified.

License

GPL v3 License.

Source code of this package MUST ALWAYS be disclosed no matter what use case is,

and source code referring to this package MUST ALSO be discolsed and share the same GPL v3 License.

Documentation

Index

Constants

View Source
const (
	LINE_STICKER_STATIC       = "line_s"  //普通貼圖
	LINE_STICKER_ANIMATION    = "line_a"  //動態貼圖
	LINE_STICKER_POPUP        = "line_p"  //全螢幕
	LINE_STICKER_POPUP_EFFECT = "line_f"  //特效
	LINE_EMOJI_STATIC         = "line_e"  //表情貼
	LINE_EMOJI_ANIMATION      = "line_i"  //動態表情貼
	LINE_STICKER_MESSAGE      = "line_m"  //訊息
	LINE_STICKER_NAME         = "line_n"  //隨你填
	KAKAO_EMOTICON            = "kakao_e" //KAKAOTALK普通貼圖

	StoreLine  = "line"
	StoreKakao = "kakao"

	WARN_KAKAO_PREFER_SHARE_LINK = "prefer share link for kakao"
)

Line sticker types

Variables

View Source
var BSDTAR_BIN = "bsdtar"

Functions

func ParseImportLink(link string, ld *LineData) (string, error)

Parse a LINE or Kakao link and fetch metadata. The metadata can be used to call prepareImportStickers. Returns a string and an error. String act as a warning message, empty string means no warning yield.

Attention: During this step, ld.Amount, ld.Files and ld.IsAnimated will NOT be available!

func PrepareImportStickers

func PrepareImportStickers(ctx context.Context, ld *LineData, workDir string, needConvert bool) error

Prepare import stickers files. A context is provided, which can be used to interrupt the process. When this function returns, stickers are ready to be sent to execAutoCommit. However, wg inside each LineFile might still not being done yet, wg.Wait() is required for individual sticker file.

ld.Amount, ld.Files and ld.IsAnimated will be produced after return.

Types

type KakaoJson

type KakaoJson struct {
	Result KakaoJsonResult
}

type KakaoJsonResult

type KakaoJsonResult struct {
	//Korean title
	Title string
	//kakao ID
	TitleUrl string
	//PNG urls
	ThumbnailUrls []string
	//??
	TitleImageUrl string
	//Cover image
	TitleDetailUrl string
}

type LineData

type LineData struct {
	//Waitgroup for when linedata become available.
	Wg sync.WaitGroup
	//Store type, defined in const.
	Store string
	//Store link
	Link string
	//Store links for different langs
	I18nLinks []string
	//Sticker download link, typically ZIP.
	DLink string
	//Sticker download links.
	DLinks []string
	//Sticker file paths.
	Files []*LineFile
	//Sticker category, defined in const.
	Category string
	//Sticker pack ID.
	Id string
	//Sticker title appeared in store.
	Title string
	//I18n titles for LINE sticker packs, TitleWg must be waited before using this field.
	I18nTitles []string
	//WaitGroup for I18nTitles
	TitleWg    sync.WaitGroup
	IsAnimated bool
	Amount     int
}

This is called linedata due to historical reason, instead, it handles "import" data, which includes kakao and line by far.

type LineFile

type LineFile struct {
	Wg sync.WaitGroup
	// path of original file
	OriginalFile string
	// path of converted filea
	ConvertedFile string
	// conversion error
	CError error
}

type LineJson

type LineJson struct {
	Name string
	Sku  string
	Url  string
}

Jump to

Keyboard shortcuts

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