Skip to content

Commit 310e28b

Browse files
committed
engine_BASE: separating downloadCollector
1 parent 9e7d1b6 commit 310e28b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

engine/engines.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ func Scrape(engine Engine) ([]Movie, error) {
5252
// Cache responses to prevent multiple download of pages
5353
// even if the collector is restarted
5454
colly.CacheDir("./gophie_cache"),
55-
colly.Async(true),
55+
// colly.Async(true),
5656
// colly.Debugger(&debug.LogDebugger{}),
5757
)
5858
// Another collector for download Links
59-
downloadLinkCollector := c.Clone()
59+
downloadLinkCollector := colly.NewCollector(
60+
colly.CacheDir("./gophie-cache"),
61+
colly.Async(true)
62+
)
6063

6164
var movies = make(map[string]*Movie)
6265

@@ -75,9 +78,13 @@ func Scrape(engine Engine) ([]Movie, error) {
7578
} else {
7679
// Using DownloadLink as key to movie makes it unique
7780
movies[movie.DownloadLink.String()] = &movie
78-
downloadLinkCollector.Visit(movie.DownloadLink.String())
81+
// downloadLinkCollector.Visit(movie.DownloadLink.String())
7982
}
8083
})
84+
85+
for _, movie := range movies{
86+
downloadLinkCollector.Visit(movie.DownloadLink.String())
87+
}
8188
})
8289

8390
c.OnRequest(func(r *colly.Request) {
@@ -109,6 +116,7 @@ func Scrape(engine Engine) ([]Movie, error) {
109116
})
110117

111118
downloadLinkCollector.OnResponse(func(r *colly.Response) {
119+
log.Debug(r.Request.URL.String)
112120
// movie := movies[r.Request.URL.String()]
113121
// log.Infof("%s %v %s", r.Request.URL.String(), movie.DownloadLink, movie.Title)
114122
// log.Debugf("Retrieved Download Link %v\n", movie.DownloadLink)

engine/fzmovies.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ func (engine *FzEngine) updateDownloadProps(downloadCollector *colly.Collector,
107107
})
108108

109109
// Update Download Link if "Download" HTML on page
110-
downloadCollector.OnHTML("p", func(e *colly.HTMLElement) {
111-
if strings.HasSuffix(strings.TrimSpace(e.ChildAttr("input", "value")), "mp4") {
112-
downloadLink, err := url.Parse(e.Request.AbsoluteURL(e.ChildAttr("input", "value")))
110+
downloadCollector.OnHTML("input[name=download1]", func(e *colly.HTMLElement) {
111+
if strings.HasSuffix(strings.TrimSpace(e.Attr("value")), "mp4") {
112+
downloadLink, err := url.Parse(e.Request.AbsoluteURL(e.Attr("value")))
113113
if err != nil {
114114
log.Fatal(err)
115115
}

0 commit comments

Comments
 (0)