forked from haofree/opendmm-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aventertainments.go
111 lines (101 loc) · 2.99 KB
/
aventertainments.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package opendmm
import (
"fmt"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"sync"
"github.com/junzh0u/httpx"
"github.com/PuerkitoBio/goquery"
"github.com/deckarep/golang-set"
"github.com/golang/glog"
)
func aveSearch(query string, wg *sync.WaitGroup, metach chan MovieMeta) {
keywords := aveGuess(query)
for keyword := range keywords.Iter() {
wg.Add(1)
go func(keyword string) {
defer wg.Done()
aveSearchKeyword(keyword, wg, metach)
}(keyword.(string))
}
}
func aveGuess(query string) mapset.Set {
re := regexp.MustCompile("(?i)([a-z2-3]{2,8})[-_]?([sm]?)(\\d{2,5})")
matches := re.FindAllStringSubmatch(query, -1)
keywords := mapset.NewSet()
for _, match := range matches {
series := strings.ToUpper(match[1])
prefix := strings.ToUpper(match[2])
keywords.Add(fmt.Sprintf("%s-%s%s", series, prefix, match[3]))
number, _ := strconv.Atoi(match[3])
keywords.Add(fmt.Sprintf("%s-%s%d", series, prefix, number))
}
return keywords
}
func aveSearchKeyword(keyword string, wg *sync.WaitGroup, metach chan MovieMeta) {
glog.Info("Keyword: ", keyword)
urlstr := fmt.Sprintf(
"http://www.aventertainments.com/search_Products.aspx?keyword=%s",
url.QueryEscape(keyword),
)
glog.V(2).Info("Search page: ", urlstr)
doc, err := newDocument(urlstr, httpx.GetContentInUTF8(http.Get))
if err != nil {
glog.V(2).Infof("Error parsing %s: %v", urlstr, err)
return
}
doc.Find("div.main-unit2 > table a").Each(
func(i int, a *goquery.Selection) {
href, ok := a.Attr("href")
if ok {
wg.Add(1)
go func() {
defer wg.Done()
aveParse(href, keyword, metach)
}()
}
})
}
func aveParse(urlstr string, keyword string, metach chan MovieMeta) {
glog.V(2).Info("Product page: ", urlstr)
doc, err := newDocument(urlstr, httpx.GetContentInUTF8(http.Get))
if err != nil {
glog.V(2).Infof("Error parsing %s: %v", urlstr, err)
return
}
var meta MovieMeta
var ok bool
meta.Page = urlstr
meta.Title = doc.Find("#mini-tabet > h2").Text()
meta.CoverImage, ok = doc.Find("#titlebox > div.list-cover > img").Attr("src")
if ok {
meta.CoverImage = strings.Replace(meta.CoverImage, "jacket_images", "bigcover", -1)
}
meta.Code = strings.Replace(doc.Find("#mini-tabet > div").Text(), "商品番号:", "", -1)
doc.Find("#titlebox > ul > li").Each(
func(i int, li *goquery.Selection) {
k := li.Find("span").Text()
if strings.Contains(k, "主演女優") {
meta.Actresses = li.Find("a").Map(
func(i int, a *goquery.Selection) string {
return a.Text()
})
} else if strings.Contains(k, "スタジオ") {
meta.Maker = li.Find("a").Text()
} else if strings.Contains(k, "シリーズ") {
meta.Series = li.Find("a").Text()
} else if strings.Contains(k, "発売日") {
meta.ReleaseDate = li.Text()
} else if strings.Contains(k, "収録時間") {
meta.MovieLength = li.Text()
}
})
if strings.TrimSpace(meta.Code) != keyword {
glog.V(2).Infof("Code mismatch: Expected %s, got %s", keyword, meta.Code)
} else {
metach <- meta
}
}