uptoshare

package
v0.0.0-...-0caaa62 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0-or-later Imports: 13 Imported by: 0

Documentation

Overview

Package uptoshare uploads files to one-click hosting sites.

Index

Constants

View Source
const HistoryFile = "uptoshare_history.txt"

HistoryFile defines the name of the default history file.

Variables

View Source
var CodePadOrg = &Host{
	Poster: upload.NewPostForm("http://codepad.org/",
		"code",
		"lang", "Plain Text",
		"submit", "Submit",
	),
	Parse: func(h *Host, data string) Links {
		uri := h.GetURL("")
		ID := findLink(string(data), uri, "\"")
		if ID == "" {
			return linkWarn(h.Name() + ": parse failed")
		}
		return NewLinks(ID).
			Add("dl", ID+"/raw.txt").
			Add("fork", ID+"/fork")
	},
}

CodePadOrg implements a Text Sender to the codepad.org website.

View Source
var FileBinCa = &Host{
	Poster: upload.NewMultiparter("http://filebin.ca/upload.php", "file"),
	Parse: func(h *Host, data string) Links {
		ID := findPrefix(data, "url:", "\n")
		if ID == "" {
			return linkWarn(h.Name() + ": parse failed\n" + data)
		}
		return NewLinks(ID).
			Add("page", strings.Replace(ID, "http://ibin.co/", "http://filebin.ca/v/", 1))
	},
}

FileBinCa implements a File Sender to the imagebin.ca website.

View Source
var FreemovTop = &Host{
	Poster: upload.NewMultiparter("http://freemov.top/",
		"upload[]",
		"submit", "submit",
	),
	Parse: func(h *Host, data string) Links {
		link := findPrefix(data, `id="name" value=`, ` />`)
		if link == "" {
			println(h.Name()+" -- ANSWER\n", data)
			return linkWarn(h.Name() + ": bad format")
		}
		return NewLinks("http://" + link)
	},
}

FreemovTop implements a File Sender to the freemov.top website.

View Source
var ImageBinCa = &Host{
	Poster: upload.NewMultiparter("https://imagebin.ca/upload.php",
		"file",
		"private", "true",
	),
	Parse: func(h *Host, data string) Links {
		ID := findPrefix(data, "url:", "\n")
		if ID == "" {
			return linkWarn(h.Name() + ": parse failed")
		}
		return NewLinks(ID).
			Add("page", strings.Replace(ID, "http://ibin.co/", "http://imagebin.ca/v/", 1))
	},
}

ImageBinCa implements an Image Sender to the imagebin.ca website.

View Source
var ImageShackUs = &Host{
	Poster: upload.NewMultiparter("http://imageshack.us/upload_api.php",
		"fileupload",
		"key", "ABDGHOQS7d32e206ee33ef8cefb208d55dd030a6",
		"public", "no",
		"xml", "yes",
	),
	Parse: func(h *Host, data string) Links {
		return NewLinks(findPrefix(data, "<image_link>", "</image_link>")).
			Add("thumb", findPrefix(data, "<thumb_link>", "</thumb_link>"))
	},
}

ImageShackUs implements an Image Sender to the imageshack.us website.

View Source
var ImagebamCom = &Host{
	Poster: upload.NewMultiparter("http://www.imagebam.com/sys/upload/save",
		"file[]",
		"content_type", "1",
		"thumb_size", "250",
		"thumb_aspect_ratio", "resize",
		"thumb_file_type", "jpg",
	),
	Parse: func(h *Host, data string) Links {
		return NewLinks(findPrefix(data, "[URL=", "][IMG]")).
			Add("del", findLink(data, "http://www.imagebam.com/remove/", "'></div>"))
	},
}

ImagebamCom implements an Image Sender to the imagebam.com website.

View Source
var ImgclickNet = &Host{
	Poster: upload.NewMultiparter("http://main.imgclick.net/cgi-bin/upload_file.cgi?upload_id=",
		"file_0",
		"upload_type", "file",
	),
	Parse: func(h *Host, data string) Links {
		return NewLinks(findLink(data, "http://main.imgclick.net/i/", "[/IMG][/URL]"))
	},
}

ImgclickNet implements an Image Sender to the imgclick.net website.

View Source
var ImglandNet = &Host{
	Poster: upload.NewMultiparter("https://imgland.net/process.php?subAPI=mainsite",
		"imagefile[]",
		"usubmit", "true",
	),
	Parse: func(h *Host, data string) Links {
		ret := &imglandNetJSON{}
		e := json.Unmarshal([]byte(data), ret)
		if e != nil {
			return linkErr(e, h.Name())
		}
		return NewLinks(ret.URL)
	},
}

ImglandNet implements an Image Sender to the imagebam.com website.

View Source
var ImgurCom = &Host{
	Poster: upload.NewMultiparter("http://imgur.com/api/upload.xml",
		"image",
		"key", "b3625162d3418ac51a9ee805b1840452",
	),
	Parse: func(h *Host, data string) Links {
		println(data)
		return NewLinks(findPrefix(data, "<original_image>", "</original_image>")).
			Add("thumb", findPrefix(data, "<small_thumbnail>", "</small_thumbnail>")).
			Add("large", findPrefix(data, "<large_thumbnail>", "</large_thumbnail>")).
			Add("page", findPrefix(data, "<imgur_page>", "</imgur_page>")).
			Add("del", findPrefix(data, "<delete_page>", "</delete_page>"))
	},
}

ImgurCom implements an Image Sender to the imgur.com website.

View Source
var LeopardHosting = &Host{
	Poster: upload.NewMultiparter("http://leopard.hosting/upload.php",
		"uploadContent",

		"public", "no",
		"showname", "no",
		"json", "true",
	),
	Parse: func(h *Host, data string) Links {
		ret := &leopardHostingJSON{}
		e := json.Unmarshal([]byte(data), ret)
		if e != nil {
			return linkErr(e, h.Name())
		}
		return NewLinks(ret.Upload.DownloadURL).
			Add("del", ret.Upload.DeleteURL).
			Add("support", ret.Upload.Support).
			Add("ID", ret.Upload.FileCode)
	},
}

LeopardHosting implements a File Sender to the leopard.hosting website.

View Source
var PasteBinCom = &Host{
	Poster: &upload.AsPostFormHTTP{
		UpBase:     upload.NewBaseURL("http://pastebin.com/api/api_post.php"),
		ContentRef: "api_paste_code",
		Options: map[string]string{
			"api_option":            "paste",
			"api_paste_private":     "1",
			"api_paste_expire_date": "1M",
			"api_paste_format":      "text",
			"api_dev_key":           "4dacb211338b25bfad20bc6d4358e555",
		},
		PrePost: func(hp *upload.AsPostFormHTTP, content *string) error {
			hp.Options["api_user_key"] = ""

			return nil
		},
	},
	Parse: func(h *Host, data string) Links {
		if !strings.HasPrefix(data, "http://") {
			return linkWarn(h.Name() + ": bad format: " + data)
		}
		return NewLinks(data)
	},
}

PasteBinCom implements a Text Sender to the pastebin.com website.

View Source
var PasteBinMozillaOrg = &Host{
	Poster: &upload.AsPostFormHTTP{
		UpBase:     upload.NewBaseURL("https://pastebin.mozilla.org"),
		ContentRef: "code2",
		Options: map[string]string{
			"format":     "text",
			"paste":      "Send",
			"expiry":     "d",
			"remember":   "0",
			"parent_pid": "",
		},
		PrePost: func(hp *upload.AsPostFormHTTP, content *string) error {
			hp.Options["poster"] = "Anonymous"
			return nil
		},
	},
	Parse: func(h *Host, data string) Links {
		ID := findLink(data, "/?dl=", `"`)
		if ID == "" {
			return linkWarn(h.Name() + ": parse failed\n" + data)
		}
		uri := h.GetURL("")
		return NewLinks(uri+ID).
			Add("dl", uri+"/"+ID[5:])
	},
}

PasteBinMozillaOrg implements a Text Sender to the pastebin.mozilla.org website.

View Source
var PasteUbuntuCom = &Host{
	Poster: &upload.AsPostFormHTTP{
		UpBase:     upload.NewBaseURL("http://paste.ubuntu.com"),
		ContentRef: "content",
		Options: map[string]string{
			"syntax": "text",
			"submit": "Paste!",
		},
		PrePost: func(hp *upload.AsPostFormHTTP, content *string) error {
			hp.Options["poster"] = "Anonymous"
			return nil
		},
	},
	Parse: func(h *Host, data string) Links {
		ID := findPrefix(data, `class="pturl" href="/`, "/plain/")
		if ID == "" {
			return linkWarn(h.Name() + ": parse failed\n" + data)
		}
		return NewLinks(h.GetURL("") + "/" + ID)
	},
}

PasteUbuntuCom implements a Text Sender to the paste.ubuntu.com website.

View Source
var PixeldraIn = &Host{
	Poster: &upload.AsMultipart{
		UpBase:  upload.NewBaseURL("http://pixeldra.in/api/upload"),
		FileRef: "file",
		PrePost: func(m *upload.AsMultipart, file string) error {
			m.Options = map[string]string{
				"fileName": filepath.Base(file),
			}
			return nil
		},
	},
	Parse: func(h *Host, data string) Links {
		ret := pixeldraInJSON{}
		e := json.Unmarshal([]byte(data), &ret)
		if e != nil {
			return linkErr(e, h.Name())
		}
		return NewLinks(ret.URL).
			Add("del", ret.ID)
	},
}

PixeldraIn implements a File Sender to the pixeldra.in website.

View Source
var PlayGolangOrg = &Host{
	Poster: upload.NewRequester("POST", "https://play.golang.org/share"),
	Parse: func(h *Host, data string) Links {
		return NewLinks("https://play.golang.org/p/" + data)
	},
}

PlayGolangOrg implements a Text Sender to the play.golang.org website.

View Source
var PostimageOrg = &Host{
	Poster: upload.NewMultiparter("https://old.postimage.org/",
		"upload[]",
		"adult", "no",
	),
	Parse: func(h *Host, data string) Links {
		return NewLinks(findLink(data, "http://postimg.org/image/", "' ")).
			Add("thumb", findPrefix(data, "[img]", "[/img]")).
			Add("del", findLink(data, "http://postimg.org/delete/", "<"))
	},
}

PostimageOrg implements an Image Sender to the postimage.org website.

View Source
var TransferSh = &Host{
	Poster: &upload.AsRequestHTTP{
		Method: "PUT",
		UpBase: upload.NewBaseCB(func(file string) string {
			return "https://transfer.sh/" + filepath.Base(file)
		}),
	},
	Parse: func(h *Host, data string) Links {
		data = strings.Trim(data, " \n")
		if data == "Not Found" {
			return linkWarn(h.Name() + " has answered: " + data)
		}
		return NewLinks(data)
	},
}

TransferSh implements a File Sender to the transfer.sh website.

View Source
var VideoBinOrg = &Host{
	Poster: upload.NewMultiparter("https://videobin.org/add",
		"videoFile",
		"api", "1",
	),
	Parse: func(h *Host, data string) Links {
		return NewLinks(data)
	},
}

VideoBinOrg implements a Video Sender to the postimage.org website.

Functions

func FileNameFromURI

func FileNameFromURI(str string) string

FileNameFromURI strips file:// in front of a file path.

TODO: check nothing is missing from the original call : g_filename_from_uri

Types

type FileType

type FileType int

FileType defines the type of a backend.

const (
	FileTypeUnknown FileType = iota
	FileTypeText
	FileTypeImage
	FileTypeVideo
	FileTypeFile
)

File and backends types supported.

func (FileType) String

func (f FileType) String() string

String returns a human readable file type.

type Host

type Host struct {
	upload.Poster
	Parse func(*Host, string) Links
}

Host describes an upload service to implement a Sender.

func (*Host) Send

func (h *Host) Send(r io.Reader, size int64, filename string) Links

Send sends the file over the network to the hosting website.

type Links map[string]string

Links contains the result data of an upload.

func NewLinks(link ...string) Links

NewLinks creates links list.

An optional argument will be used as the main "link" url value.

func (Links) Add

func (li Links) Add(key, link string) Links

Add tests if link isn't empty before adding it to the list.

type Sender

type Sender interface {
	SetName(string)
	SetConfig(*upload.Config)
	Send(r io.Reader, size int64, filename string) Links
}

Sender defines the common backend upload interface.

type Uploader

type Uploader struct {
	LimitRate     int
	PostAnonymous bool
	FileForAll    bool

	// Log provides a common logger for the uptoshare service.
	Log cdtype.Logger
	// contains filtered or unexported fields
}

Uploader manages an upload queue to send files to one-click hosting websites.

func New

func New() *Uploader

New creates an Uploader.

func (*Uploader) ListHistory

func (up *Uploader) ListHistory() []Links

ListHistory returns the history content.

func (*Uploader) ListRemove

func (up *Uploader) ListRemove(uri string) error

ListRemove removes an item from the history..

func (*Uploader) SetHistory

func (up *Uploader) SetHistory(links []Links)

SetHistory sets the new history content.

func (*Uploader) SetHistoryFile

func (up *Uploader) SetHistoryFile(file string)

SetHistoryFile sets the location of the history file.

func (*Uploader) SetHistorySize

func (up *Uploader) SetHistorySize(nb int)

SetHistorySize sets the size of the history.

func (*Uploader) SetOnResult

func (up *Uploader) SetOnResult(call func(Links))

SetOnResult sets the result return method.

func (*Uploader) SetPostCheck

func (up *Uploader) SetPostCheck(call func())

SetPostCheck sets the post-upload action.

func (*Uploader) SetPreCheck

func (up *Uploader) SetPreCheck(call func())

SetPreCheck sets the pre-upload action.

func (*Uploader) SiteFile

func (up *Uploader) SiteFile(site string) error

SiteFile sets the text upload backend.

func (*Uploader) SiteImage

func (up *Uploader) SiteImage(site string) error

SiteImage sets the image upload backend.

func (*Uploader) SiteText

func (up *Uploader) SiteText(site string) error

SiteText sets the text upload backend.

func (*Uploader) SiteVideo

func (up *Uploader) SiteVideo(site string) error

SiteVideo sets the text upload backend.

func (*Uploader) UploadGuess

func (up *Uploader) UploadGuess(data string)

UploadGuess data to the configured server for file type.

func (*Uploader) Walk

func (up *Uploader) Walk(call func(Links) bool)

Walk parse the links list.

Jump to

Keyboard shortcuts

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