forked from gipsh/miradetodo-scrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdt-link-extractor.go
97 lines (64 loc) · 1.57 KB
/
mdt-link-extractor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"log"
"github.com/PuerkitoBio/goquery"
"strings"
"net/url"
"encoding/base64"
"os"
)
func fixString(s string) string {
out := []byte(s)
out[0] = (out[0] - 1)
return string(out)
}
func extractLinks(url string) {
doc, err := goquery.NewDocument(url)
if err != nil {
log.Fatal(err)
}
doc.Find("a[href]").Each(func(index int, item *goquery.Selection) {
href, _ := item.Attr("href")
decodedId := extractId(href)
fmt.Printf("\t %d. %s\n", index, decodedId)
})
}
func extractId(movieUrl string) string {
u, err := url.Parse(movieUrl)
if err != nil {
panic(err)
}
m, _ := url.ParseQuery(u.RawQuery)
return decodeId(m["id"][0])
}
func decodeId(id string) string {
ss := strings.Split(id, "!Ar")
if len(ss) == 1 {
dcd, _ := base64.StdEncoding.DecodeString(id)
return string(dcd)
}
for i := 1; i < len(ss); i++ {
ss[i] = fixString(ss[i])
}
finalout := strings.Join(ss[:], "")
dd, _ := base64.StdEncoding.DecodeString(string(finalout))
return string(dd)
}
func main() {
if len(os.Args) < 2 {
fmt.Printf("Usage: %s https://miradetodo.co/episodio/westworld-3x3/ \n", os.Args[0])
os.Exit(0)
}
doc, err := goquery.NewDocument(os.Args[1])
if err != nil {
log.Fatal(err)
}
doc.Find("iframe[data-lazy-src]").Each(func(index int, item *goquery.Selection) {
href, _ := item.Attr("data-lazy-src")
if strings.Contains(href, "generator") {
fmt.Printf("[*] link: [%s] \n", href)
extractLinks(href)
}
})
}