-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from sekiju/v1.1.0
V1.1.0
- Loading branch information
Showing
44 changed files
with
1,460 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
episode/ | ||
public/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/rs/zerolog/log" | ||
"github.com/sekiju/htt" | ||
"github.com/sekiju/mdl/extractor/util" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
const ( | ||
chapterURL = "https://comic-ogyaaa.com/episode/2550912964910100594" | ||
) | ||
|
||
/* update hosts | ||
127.0.0.1 comic-ogyaaa.com | ||
127.0.0.1 cdn-img.comic-ogyaaa.com | ||
*/ | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
} | ||
|
||
func run() error { | ||
res, err := htt.New().SetHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Mobile/15E148 Safari/604.1").Get(chapterURL) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
html, err := res.Text() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
episode, err := util.ExtractJSONFromHTML[episodeResult](html, `<script id='episode-json' type='text/json' data-value='`, `'></script>`) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, page := range episode.ReadableProduct.PageStructure.Pages { | ||
if page.Type != "main" { | ||
continue | ||
} | ||
|
||
parsedURL, _ := url.Parse(page.Src) | ||
filePath := filepath.Join(".", parsedURL.Path) | ||
|
||
if _, err = os.Stat(filePath); err == nil { | ||
continue | ||
} | ||
|
||
if err = os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
res, err = htt.New().Get(page.Src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
file, err := os.Create(filePath) | ||
if err != nil { | ||
return fmt.Errorf("failed to create file: %w", err) | ||
} | ||
|
||
_, err = file.ReadFrom(res.Body) | ||
if err != nil { | ||
return fmt.Errorf("failed to write file: %w", err) | ||
} | ||
|
||
if err = file.Close(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
parsedURL, _ := url.Parse(chapterURL) | ||
filePath := filepath.Join(".", parsedURL.Path) | ||
|
||
if err = os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
html = strings.ReplaceAll(html, "https://", "http://") | ||
|
||
if err = os.WriteFile(filePath, []byte(html), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
app := fiber.New() | ||
|
||
app.Static("/", ".") | ||
|
||
return app.Listen(":80") | ||
} | ||
|
||
type episodeResult struct { | ||
ReadableProduct struct { | ||
FinishReadingNotificationUri interface{} `json:"finishReadingNotificationUri"` | ||
HasPurchased bool `json:"hasPurchased"` | ||
Id string `json:"id"` | ||
IsPublic bool `json:"isPublic"` | ||
NextReadableProductUri *string `json:"nextReadableProductUri"` | ||
Number int `json:"number"` | ||
PageStructure *struct { | ||
Pages []episodeResultPage `json:"pages"` | ||
} `json:"pageStructure"` | ||
Permalink string `json:"permalink"` | ||
PrevReadableProductUri *string `json:"prevReadableProductUri"` | ||
Title string `json:"title"` | ||
} `json:"readableProduct"` | ||
} | ||
|
||
type episodeResultPage struct { | ||
Type string `json:"type"` | ||
Src string `json:"src,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module bench_server | ||
|
||
go 1.23 | ||
|
||
require ( | ||
github.com/gofiber/fiber/v2 v2.52.5 | ||
github.com/rs/zerolog v1.33.0 | ||
github.com/sekiju/htt v0.1.1 | ||
github.com/sekiju/mdl v0.0.0 | ||
) | ||
|
||
replace github.com/sekiju/mdl v0.0.0 => .. | ||
|
||
require ( | ||
github.com/andybalholm/brotli v1.0.5 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/goccy/go-json v0.10.3 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/klauspost/compress v1.17.0 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mattn/go-runewidth v0.0.15 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/stretchr/testify v1.9.0 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/valyala/fasthttp v1.51.0 // indirect | ||
github.com/valyala/tcplisten v1.0.0 // indirect | ||
golang.org/x/sys v0.27.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/sekiju/mdl/downloader" | ||
"testing" | ||
) | ||
|
||
func Benchmark(b *testing.B) { | ||
chapterURLs := []string{"http://comic-ogyaaa.com/episode/2550912964910100594"} | ||
|
||
b.Run("Raw", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
loader := downloader.NewDownloader() | ||
|
||
for _, chapterURL := range chapterURLs { | ||
loader.Queue(chapterURL) | ||
} | ||
|
||
loader.Stop() | ||
} | ||
}) | ||
} |
Oops, something went wrong.