more fixes idk this history gonna be public n fun
This commit is contained in:
parent
c5ceea00fb
commit
0849c99d3c
9
main.go
9
main.go
|
@ -21,6 +21,7 @@ func main() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s <submission id/url>\n", os.Args[0])
|
fmt.Fprintf(os.Stderr, "Usage: %s <submission id/url>\n", os.Args[0])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
LoadMimetypes()
|
||||||
submissionUrl, err := url.Parse(os.Args[1])
|
submissionUrl, err := url.Parse(os.Args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error when parsing submission url: %s\n", err)
|
fmt.Fprintf(os.Stderr, "Error when parsing submission url: %s\n", err)
|
||||||
|
@ -196,10 +197,10 @@ func main() {
|
||||||
} else if submission.IsRedditMediaDomain && submission.Preview != nil {
|
} else if submission.IsRedditMediaDomain && submission.Preview != nil {
|
||||||
preview := submission.Preview.Images[0]
|
preview := submission.Preview.Images[0]
|
||||||
if pathExt == ".gif" {
|
if pathExt == ".gif" {
|
||||||
if preview.Variants.Mp4 != nil {
|
if preview.Variants.Mp4.Source != nil {
|
||||||
urls[0] = preview.Variants.Mp4.Url
|
urls[0] = preview.Variants.Mp4.Source.Url
|
||||||
} else if preview.Variants.Gif != nil {
|
} else if preview.Variants.Gif.Source != nil {
|
||||||
urls[0] = preview.Variants.Gif.Url
|
urls[0] = preview.Variants.Gif.Source.Url
|
||||||
}
|
}
|
||||||
} else if submission.IsVideo {
|
} else if submission.IsVideo {
|
||||||
urls[0] = preview.Source.Url
|
urls[0] = preview.Source.Url
|
||||||
|
|
|
@ -64,8 +64,12 @@ type Submission struct {
|
||||||
Preview *struct {
|
Preview *struct {
|
||||||
Images []struct {
|
Images []struct {
|
||||||
Variants struct {
|
Variants struct {
|
||||||
Mp4 *PreviewSource `json:"mp4"`
|
Mp4 struct {
|
||||||
Gif *PreviewSource `json:"gif"`
|
Source *PreviewSource `json:"source"`
|
||||||
|
} `json:"mp4"`
|
||||||
|
Gif struct {
|
||||||
|
Source *PreviewSource `json:"source"`
|
||||||
|
} `json:"gif"`
|
||||||
} `json:"variants"`
|
} `json:"variants"`
|
||||||
Source *PreviewSource `json:"source"`
|
Source *PreviewSource `json:"source"`
|
||||||
} `json:"images"`
|
} `json:"images"`
|
||||||
|
|
29
utils.go
29
utils.go
|
@ -20,6 +20,7 @@ var (
|
||||||
configDir string
|
configDir string
|
||||||
config *Config
|
config *Config
|
||||||
data *Data
|
data *Data
|
||||||
|
mimeOverride map[string]string
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadConfigAndData() error {
|
func LoadConfigAndData() error {
|
||||||
|
@ -74,6 +75,30 @@ func LoadConfigAndData() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a jpeg file can have a jpe extension and i personally don't like it
|
||||||
|
// https://github.com/LonamiWebs/Telethon/blob/2e1be01ad4f6462de2e9e1f96a33537e51f44980/telethon/utils.py#L33
|
||||||
|
func LoadMimetypes() {
|
||||||
|
mimeOverride = make(map[string]string)
|
||||||
|
mimeOverride["image/png"] = ".png"
|
||||||
|
mimeOverride["image/jpeg"] = ".jpeg"
|
||||||
|
mimeOverride["image/webp"] = ".webp"
|
||||||
|
mimeOverride["image/gif"] = ".gif"
|
||||||
|
mimeOverride["image/bmp"] = ".bmp"
|
||||||
|
mimeOverride["image/x-tga"] = ".tga"
|
||||||
|
mimeOverride["image/tiff"] = ".tiff"
|
||||||
|
mimeOverride["image/vnd.adobe.photoshop"] = ".psd"
|
||||||
|
|
||||||
|
mimeOverride["video/mp4"] = ".mp4"
|
||||||
|
mimeOverride["video/quicktime"] = ".mov"
|
||||||
|
mimeOverride["video/avi"] = ".avi"
|
||||||
|
|
||||||
|
mimeOverride["audio/mpeg"] = ".mp3"
|
||||||
|
mimeOverride["audio/m4a"] = ".m4a"
|
||||||
|
mimeOverride["audio/aac"] = ".aac"
|
||||||
|
mimeOverride["audio/ogg"] = ".ogg"
|
||||||
|
mimeOverride["audio/flac"] = ".flac"
|
||||||
|
}
|
||||||
|
|
||||||
func WriteData() error {
|
func WriteData() error {
|
||||||
contents, err := json.Marshal(data)
|
contents, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -256,6 +281,10 @@ func GetExtension(mimeType string) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Failed to parse media type of %s: %s", mimeType, err)
|
return "", fmt.Errorf("Failed to parse media type of %s: %s", mimeType, err)
|
||||||
}
|
}
|
||||||
|
ext, exists := mimeOverride[mediaType]
|
||||||
|
if exists {
|
||||||
|
return ext, nil
|
||||||
|
}
|
||||||
exts, err := mime.ExtensionsByType(mediaType)
|
exts, err := mime.ExtensionsByType(mediaType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Failed to find file extensions of %s: %s", mediaType, err)
|
return "", fmt.Errorf("Failed to find file extensions of %s: %s", mediaType, err)
|
||||||
|
|
Reference in New Issue