-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvk.groovy
More file actions
91 lines (80 loc) · 2.87 KB
/
vk.groovy
File metadata and controls
91 lines (80 loc) · 2.87 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
import org.serviio.library.online.*
import groovy.json.*
/**
* <h1>vk.com Serviio plugin</h1>
*
* @version 2
* @author commandercool
*
* Changes:
* - new quality string added: 480p;
* - added support for search result links.
*/
class Vk extends WebResourceUrlExtractor {
final Integer VERSION = 2;
final String VALID_URL = /http:\/\/vk.com\/video(\d+)_(\d+)/;
final String VALID_SEARCH_URL = /http:\/\/vk.com\/video\?(.*)video(\d+_\d+)/;
final String NVARS = /nvar vars = (\{.*\});/;
final String[] quals = ['240', '360', '480', '720', '1080'];
int getVersion() {
return VERSION;
}
String getExtractorName() {
return 'vk.com'
}
boolean extractorMatches(URL feedUrl) {
return (feedUrl ==~ VALID_URL || feedUrl ==~ VALID_SEARCH_URL)
}
WebResourceContainer extractItems(URL resourceUrl, int maxItemsToRetrieve) {
def container = new WebResourceContainer()
if (resourceUrl ==~ VALID_SEARCH_URL) {
def urlstr = "http://vk.com/video" + (resourceUrl =~ VALID_SEARCH_URL)[0][2]
resourceUrl = new URL(urlstr)
}
def http = resourceUrl.text
def jsonstr = (http =~ NVARS)[0][1]
jsonstr = jsonstr.replaceAll('\\\\', '')
def json = new JsonSlurper().parseText(jsonstr)
log("${json}")
def title = "${json.md_title}"
def items = []
for (qual in quals) {
def url = json."url${qual}"
log(url)
if (url != null) {
def fulltitle = title + " [${qual}p]"
def item = new WebResourceItem(title: fulltitle, additionalInfo: [
expiresImmediately: false,
cacheKey: fulltitle,
url: url,
thumbnailUrl: json.jpg,
live: false
])
items += item
}
}
container.setTitle(title)
container.setItems(items)
return container
}
ContentURLContainer extractUrl(WebResourceItem arg0, PreferredQuality arg1) {
def c = new ContentURLContainer()
if(arg0 != null) {
c.setExpiresImmediately(arg0.additionalInfo.expiresImmediately)
c.setCacheKey(arg0.additionalInfo.cacheKey)
c.setContentUrl(arg0.additionalInfo.url)
c.setLive(arg0.additionalInfo.live)
c.setThumbnailUrl(arg0.additionalInfo.thumbnailUrl)
}
return c
}
static void main(args) {
Vk vk = new Vk()
def url = "http://vk.com/video?q=black%20keys§ion=search&z=video7555330_165618061"
println vk.extractorMatches(new URL(url))
vk.extractItems(new URL(url), 123).getItems().each { it->
ContentURLContainer result = vk.extractUrl(it, PreferredQuality.HIGH)
println result
}
}
}