forked from jrudio/go-plex-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
78 lines (59 loc) · 1.45 KB
/
search.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
package plex
import "regexp"
// SearchPlex searches just like Search, but omits the last 4 results which are not relevant
func (p *Plex) SearchPlex(title string) (SearchResults, error) {
results, err := p.Search(title)
if err != nil {
return SearchResults{}, err
}
results.MediaContainer.Metadata = results.MediaContainer.Metadata[:4]
return results, nil
}
// ExtractKeyAndThumbFromURL extracts the rating key and thumbnail id from the url
func (p *Plex) ExtractKeyAndThumbFromURL(_url string) (string, string) {
count := len(_url)
var key string
var thumbID string
if count > 18 {
k := _url[18:]
keyCount := len(k)
if keyCount > 7 {
// Get key
for ii := 0; ii < keyCount; ii++ {
if k[ii:ii+1] == "/" {
key = k[:ii]
thumbID = k[ii+7:]
break
}
}
}
}
return key, thumbID
}
// ExtractKeyFromRatingKey extracts the key from the rating key url
func (*Plex) ExtractKeyFromRatingKey(key string) string {
keyCount := len(key)
if keyCount > 18 {
key = key[18:]
keyCount = len(key)
if keyCount > 9 {
for ii := 0; ii < keyCount; ii++ {
if key[ii:ii+1] == "/" {
key = key[:ii]
break
}
}
}
return key
}
return key
}
// ExtractKeyFromRatingKeyRegex extracts the key from a rating key url via regex
func (p *Plex) ExtractKeyFromRatingKeyRegex(key string) string {
r := regexp.MustCompile(`\d+`)
result := r.FindStringSubmatch(key)
if len(key) == 0 {
return ""
}
return result[0]
}