Skip to content

Commit e885321

Browse files
authored
Merge pull request #43 from Go-phie/bugfix/besthdmovies-search-crash
Fix Best HD movies search crash
2 parents f005fcf + c9d9874 commit e885321

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

engine/besthdmovies.go

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type BestHDEngine struct {
1919

2020
// NewBestHDEngine : A Movie Engine Constructor for BestHDEngine
2121
func NewBestHDEngine() *BestHDEngine {
22-
base := "https://www.besthdmovies.top/"
22+
base := "https://www.besthdmovies.fit/"
2323
baseURL, err := url.Parse(base)
2424
if err != nil {
2525
log.Fatal(err)
@@ -90,7 +90,7 @@ func (engine *BestHDEngine) parseSingleMovie(el *colly.HTMLElement, index int) (
9090
}
9191

9292
func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collector, movies *[]Movie) {
93-
submissionDetails := make(map[string]string)
93+
// submissionDetails := make(map[string]string)
9494
// Update movie download link if div.post-single-content on page
9595
downloadCollector.OnHTML("div.post-single-content", func(e *colly.HTMLElement) {
9696
movie := &(*movies)[getMovieIndexFromCtx(e.Request)]
@@ -123,14 +123,16 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
123123
})
124124

125125
downloadCollector.OnHTML("div.content-area", func(e *colly.HTMLElement) {
126-
movie := &(*movies)[getMovieIndexFromCtx(e.Request)]
126+
movieIndex := getMovieIndexFromCtx(e.Request)
127+
movie := &(*movies)[movieIndex]
127128
links := e.ChildAttrs("a", "href")
128129
for _, link := range links {
129130
if strings.HasPrefix(link, "https://zeefiles") || strings.HasPrefix(link, "http://zeefiles") {
130131
// change all http to https
131132
if strings.HasPrefix(link, "http://") {
132133
link = "https://" + strings.TrimPrefix(link, "http://")
133134
}
135+
link = link + "?movieIndex=" + strconv.Itoa(movieIndex)
134136
downloadlink, err := url.Parse(link)
135137
if err == nil {
136138
movie.DownloadLink = downloadlink
@@ -145,21 +147,13 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
145147
downloadCollector.OnHTML("div.freeDownload", func(e *colly.HTMLElement) {
146148
movieIndex := getMovieIndexFromCtx(e.Request)
147149
movie := &(*movies)[movieIndex]
148-
zeesubmission := make(map[string]string)
149150
if e.ChildAttr("a.link_button", "href") != "" {
150151
downloadlink, err := url.Parse(e.ChildAttr("a.link_button", "href"))
151152
if err == nil {
152153
movie.DownloadLink = downloadlink
153154
}
154155
} else {
155-
156-
inputNames := e.ChildAttrs("input", "name")
157-
inputValues := e.ChildAttrs("input", "value")
158-
159-
for index := range inputNames {
160-
zeesubmission[inputNames[index]] = inputValues[index]
161-
}
162-
156+
zeesubmission := getFormDetails(e)
163157
err := downloadCollector.Post(movie.DownloadLink.String(), zeesubmission)
164158
if err != nil {
165159
log.Fatal(err)
@@ -172,15 +166,10 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
172166
var err error
173167
movie := &(*movies)[movieIndex]
174168
downloadlink := movie.DownloadLink
175-
inputNames := e.ChildAttrs("input", "name")
176-
inputValues := e.ChildAttrs("input", "value")
177-
178-
for index := range inputNames {
179-
submissionDetails[inputNames[index]] = inputValues[index]
180-
}
169+
submissionDetails := getFormDetails(e)
181170
requestlink := e.Request.URL.String()
182171
if !(strings.HasPrefix(requestlink, "https://zeefiles") || strings.HasPrefix(requestlink, "http://zeefiles")) {
183-
downloadlink, err = url.Parse("https://udown.me/watchonline/?movieIndex=" + strconv.Itoa(movieIndex))
172+
downloadlink, err = url.Parse("https://freeload.best/downloading/?movieIndex=" + strconv.Itoa(movieIndex))
184173
if err == nil {
185174
movie.DownloadLink = downloadlink
186175
}
@@ -191,6 +180,38 @@ func (engine *BestHDEngine) updateDownloadProps(downloadCollector *colly.Collect
191180
}
192181
})
193182

183+
downloadCollector.OnHTML("meta[http-equiv=refresh]", func(e *colly.HTMLElement) {
184+
// Retrieve link when on freeload.best/downloading
185+
movieIndex := getMovieIndexFromCtx(e.Request)
186+
movie := &(*movies)[movieIndex]
187+
content := e.Attr("content")
188+
re := regexp.MustCompile(`url=(.*)`)
189+
link := re.FindStringSubmatch(content)
190+
if len(link) >= 1 {
191+
downloadLink, _ := url.Parse(link[1])
192+
movie.DownloadLink = downloadLink
193+
}
194+
})
195+
196+
downloadCollector.OnHTML("div.freeDownload", func(e *colly.HTMLElement) {
197+
// Retrieve link when on zeefiles.download/id
198+
movieIndex := getMovieIndexFromCtx(e.Request)
199+
movie := &(*movies)[movieIndex]
200+
linkButton := e.ChildAttr("a.link_button", "href")
201+
if linkButton != "" {
202+
movie.DownloadLink, _ = url.Parse(linkButton)
203+
} else {
204+
submissionDetails := getFormDetails(e)
205+
downloadCollector.AllowURLRevisit = true
206+
if !strings.Contains(movie.DownloadLink.String(), "download_token") {
207+
err := downloadCollector.Post(movie.DownloadLink.String(), submissionDetails)
208+
if err != nil {
209+
log.Fatal(err)
210+
}
211+
}
212+
}
213+
})
214+
194215
downloadCollector.OnHTML("video", func(e *colly.HTMLElement) {
195216
downloadlink := e.ChildAttr("source", "src")
196217
movieIndex := getMovieIndexFromCtx(e.Request)

engine/engines.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,15 @@ func getMovieIndexFromCtx(r *colly.Request) int {
279279
}
280280
return movieIndex
281281
}
282+
283+
// Get all form details into a neat map
284+
func getFormDetails(element *colly.HTMLElement) map[string]string {
285+
submission := make(map[string]string)
286+
inputNames := element.ChildAttrs("input", "name")
287+
inputValues := element.ChildAttrs("input", "value")
288+
289+
for index := range inputNames {
290+
submission[inputNames[index]] = inputValues[index]
291+
}
292+
return submission
293+
}

0 commit comments

Comments
 (0)