|
@ -15,22 +15,32 @@ import ( |
|
|
readability "github.com/go-shiori/go-readability" |
|
|
readability "github.com/go-shiori/go-readability" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const version = "v0_20221002" |
|
|
const tmpDir = "link2epubtmpdir" |
|
|
const tmpDir = "link2epubtmpdir" |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
// var typeFlag string
|
|
|
|
|
|
|
|
|
versionFlag := flag.Bool("v", false, "version") |
|
|
linkFlag := flag.String("l", "", "Link to download") |
|
|
linkFlag := flag.String("l", "", "Link to download") |
|
|
typeFlag := flag.String("type", "mobi", "Type of epub. Available: mobi (default), epub") |
|
|
typeFlag := flag.String("type", "mobi", "Type of epub. Available: mobi (default), epub") |
|
|
titleFlag := flag.String("title", "", "Title is automatically getted from article, if want to change it, use this flag") |
|
|
titleFlag := flag.String("title", "", "Title is automatically getted from article, if want to change it, use this flag") |
|
|
|
|
|
|
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("link2epub version:", version) |
|
|
|
|
|
if *versionFlag { |
|
|
|
|
|
os.Exit(0) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if *typeFlag != "mobi" && *typeFlag != "epub" { |
|
|
if *typeFlag != "mobi" && *typeFlag != "epub" { |
|
|
log.Fatal("not valid type") |
|
|
log.Fatal("not valid type") |
|
|
} |
|
|
} |
|
|
err := os.Mkdir(tmpDir, os.ModePerm) |
|
|
err := os.Mkdir(tmpDir, os.ModePerm) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Fatalf("error creating tmp dir %s: %v\n", tmpDir, err) |
|
|
|
|
|
|
|
|
log.Printf("error creating tmp dir %s: %v\nRemoving it and continuing.", tmpDir, err) |
|
|
|
|
|
err = os.RemoveAll(tmpDir) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Fatalf("err removing %s: %v\n", tmpDir, err) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// get link
|
|
|
// get link
|
|
|