Skip to content

Commit

Permalink
add support for .jpe (#24), fix long file path issue (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis972602 committed Jul 31, 2023
1 parent 54a875b commit 69bfc75
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
6 changes: 5 additions & 1 deletion downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ func SetLog(log Log) DownloadOption {

func defaultSavePath(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string {
var name string
if filepath.Ext(attachment.Path) == ".zip" {
ext := filepath.Ext(attachment.Name)
if ext == "" {
ext = filepath.Ext(attachment.Path)
}
if ext == ".zip" {
name = attachment.Name
} else {
name = filepath.Base(attachment.Path)
Expand Down
12 changes: 8 additions & 4 deletions kemono/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ func AddIndexToAttachments(attachments []File) []FileWithIndex {
images := 0
others := 0
for _, a := range attachments {
if isImage(a.Path) {
ext := filepath.Ext(a.Name)
if ext == "" {
ext = filepath.Ext(a.Path)
}
if isImage(ext) {
files = append(files, a.Index(images))
images++
} else {
Expand All @@ -166,9 +170,9 @@ func AddIndexToAttachments(attachments []File) []FileWithIndex {
return files
}

func isImage(filename string) bool {
switch filepath.Ext(filename) {
case ".jpg", ".png", ".gif", ".webp", ".bmp", ".tiff", ".svg", ".ico", ".jpeg", ".jfif":
func isImage(ext string) bool {
switch ext {
case ".jpg", ".png", ".gif", ".webp", ".bmp", ".tiff", ".svg", ".ico", ".jpeg", ".jfif", ".jpe":
return true
default:
return false
Expand Down
6 changes: 6 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ func main() {
}
downloaderOptions = append(downloaderOptions, downloader.SavePath(func(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string {
ext := filepath.Ext(attachment.Name)
if ext == "" {
ext = filepath.Ext(attachment.Path)
}
filehash := filepath.Base(attachment.Path)[0 : len(filepath.Base(attachment.Path))-len(filepath.Ext(attachment.Path))]
filename := attachment.Name[0 : len(attachment.Name)-len(ext)]
pathConfig := &PathConfig{
Expand All @@ -309,6 +312,9 @@ func main() {

downloaderOptions = append(downloaderOptions, downloader.SavePath(func(creator kemono.Creator, post kemono.Post, i int, attachment kemono.File) string {
ext := filepath.Ext(attachment.Name)
if ext == "" {
ext = filepath.Ext(attachment.Path)
}
filehash := filepath.Base(attachment.Path)[0 : len(filepath.Base(attachment.Path))-len(filepath.Ext(attachment.Path))]
filename := attachment.Name[0 : len(attachment.Name)-len(ext)]
pathConfig := &PathConfig{
Expand Down
2 changes: 1 addition & 1 deletion main/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (t *TmplCache) Execute(typ string, config *PathConfig) string {

func getTyp(ext string) string {
switch ext {
case ".jpg", ".png", ".gif", ".webp", ".bmp", ".tiff", ".svg", ".ico", ".jpeg", ".jfif":
case ".jpg", ".png", ".gif", ".webp", ".bmp", ".tiff", ".svg", ".ico", ".jpeg", ".jfif", ".jpe":
return "image"
case ".mp4", ".webm", ".mkv", ".avi", ".mov", ".wmv", ".flv", ".f4v", ".m4v", ".rmvb", ".rm", ".3gp", ".dat", ".ts", ".mts", ".vob":
return "video"
Expand Down
8 changes: 4 additions & 4 deletions utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func ValidDirectoryName(name string) string {
return r
}
s := strings.TrimSpace(strings.Map(validate, name))
if len(s) > 255 {
s = s[:255]
if len(s) > 200 {
s = s[:200]
}
if s[len(s)-1] == '.' {
s = s[:len(s)-1]
Expand All @@ -68,8 +68,8 @@ func ValidDirectoryName(name string) string {
return r
}
s := strings.TrimSpace(strings.Map(validate, name))
if len(s) > 255 {
s = s[:255]
if len(s) > 200 {
s = s[:200]
}
if s[0] == '.' {
s = s[1:]
Expand Down

0 comments on commit 69bfc75

Please sign in to comment.