Repository navigation
Expand file tree
/
Copy pathfeed_extensions.go
More file actions
169 lines (137 loc) · 3.26 KB
/
Copy pathfeed_extensions.go
File metadata and controls
169 lines (137 loc) · 3.26 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
"html"
"io/ioutil"
"log"
"net/http"
"regexp"
"strings"
"github.com/mitchellh/mapstructure"
ext "github.com/mmcdole/gofeed/extensions"
)
type Dailymotion struct {
Media DailymotionMedia
}
type DailymotionMedia struct {
Player []ext.Extension
Thumbnail []ext.Extension
}
func decodeDailymotion(item ext.Extensions, dailymotion Dailymotion) (string, string) {
var (
content string
image string
)
err := mapstructure.Decode(item, &dailymotion)
checkError(err)
for _, this := range dailymotion.Media.Player {
r, _ := regexp.Compile(`\/.*\/(.*)`)
match := r.FindAllStringSubmatch(this.Attrs["url"], 1)
content = "http://www.dailymotion.com/embed/video/" + match[0][1]
}
for _, this := range dailymotion.Media.Thumbnail {
image = this.Attrs["url"]
}
return content, image
}
type Liveleak struct {
Media LiveleakMedia
}
type LiveleakMedia struct {
Content []ext.Extension
}
func decodeLiveleak(item ext.Extensions, liveleak Liveleak) (string, string) {
var (
content string
image string
)
err := mapstructure.Decode(item, &liveleak)
checkError(err)
for _, this := range liveleak.Media.Content[0].Children {
if this[0].Name == "thumbnail" {
r, _ := regexp.Compile(`\/.*\/(.*)_thumb_`)
match := r.FindAllStringSubmatch(this[0].Attrs["url"], 1)
if match != nil {
embed := "https://www.liveleak.com/ll_embed?f=" + match[0][1]
//content = embed
// Grab the source location from remote player
response, err := http.Get(embed)
if err != nil {
log.Fatal(err)
} else {
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
} else {
//fmt.Println(string(body))
r, _ := regexp.Compile(`(?U)source src="(.*)"`)
match := r.FindAllStringSubmatch(string(body), 1)
if match != nil {
content = embed
}
}
}
}
image = this[0].Attrs["url"]
}
}
return content, image
}
type Vimeo struct {
Media VimeoMedia
}
type VimeoMedia struct {
Content []ext.Extension
}
func decodeVimeo(item ext.Extensions, vimeo Vimeo) (string, string) {
var (
content string
image string
)
err := mapstructure.Decode(item, &vimeo)
checkError(err)
for _, this := range vimeo.Media.Content[0].Children {
if this[0].Name == "player" {
content = this[0].Attrs["url"]
}
if this[0].Name == "thumbnail" {
image = this[0].Attrs["url"]
}
}
return content, image
}
type Youtube struct {
YT YoutubeVideo
Media YoutubeMedia
}
type YoutubeChannel struct {
ChannelID []ext.Extension
}
type YoutubeVideo struct {
ChannelID []ext.Extension
VideoID []ext.Extension
}
type YoutubeMedia struct {
Group []ext.Extension
}
func decodeYoutube(item ext.Extensions, youtube Youtube) (string, string, string) {
var (
content string
image string
description string
)
err := mapstructure.Decode(item, &youtube)
checkError(err)
for _, this := range youtube.Media.Group[0].Children {
if this[0].Name == "content" {
content = this[0].Attrs["url"]
}
if this[0].Name == "thumbnail" {
image = this[0].Attrs["url"]
}
if this[0].Name == "description" {
description = html.EscapeString(strings.Replace(this[0].Value, "'", "\\'", -1))
}
}
return content, image, description
}