SourceForge has been redesigned. Learn more.
Close

[1bac28]: / plugin.video.giga_de / default.py  Maximize  Restore  History

Download this file

175 lines (151 with data), 6.6 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
170
171
172
173
174
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib
import urllib2
import socket
import sys
import re
import xbmcplugin
import xbmcaddon
import xbmcgui
socket.setdefaulttimeout(30)
addonID = 'plugin.video.giga_de'
pluginhandle = int(sys.argv[1])
xbox = xbmc.getCondVisibility("System.Platform.xbox")
settings = xbmcaddon.Addon(id=addonID)
translation = settings.getLocalizedString
forceViewMode = settings.getSetting("forceViewMode") == "true"
viewMode = str(settings.getSetting("viewMode"))
maxVideoQuality = settings.getSetting("maxVideoQuality")
qual = ["360p", "720p"]
maxVideoQuality = qual[int(maxVideoQuality)]
def index():
addDir(translation(30001), "http://www.giga.de/tv/alle-videos/", 'listVideos', "")
content = getUrl("http://www.giga.de/games/videos/")
content = content[content.find('<section class="channels">'):]
content = content[:content.find('</section>')]
spl = content.split('<li>')
for i in range(1, len(spl), 1):
entry = spl[i]
match = re.compile('href="(.+?)"', re.DOTALL).findall(entry)
url = match[0]
match = re.compile('src="(.+?)"', re.DOTALL).findall(entry)
thumb = match[0]
match = re.compile('<h3>(.+?)</h3>', re.DOTALL).findall(entry)
title = match[0]
addDir(title, url, 'listVideos', thumb)
xbmcplugin.endOfDirectory(pluginhandle)
def listVideos(url):
mainUrl = url
content = getUrl(url)
spl = content.split('<article class="videos smallimg">')
for i in range(1, len(spl), 1):
entry = spl[i]
match = re.compile('href="(.+?)"', re.DOTALL).findall(entry)
url = match[0]
titleTemp = entry[entry.find("<a"):]
match = re.compile('>(.+?)</a>', re.DOTALL).findall(titleTemp)
title = match[0]
title = cleanTitle(title)
thumb = ""
match = re.compile('data-original="(.+?)"', re.DOTALL).findall(entry)
if match:
thumb = match[0].replace("-300x190.jpg",".jpg")
addLink(title, url, 'playVideo', thumb)
if "/page/" in mainUrl:
match = re.compile('/page/(.+?)/', re.DOTALL).findall(mainUrl)
nr = str(int(match[0])+1)
newUrl = mainUrl[:-2]+nr+"/"
else:
nr = "2"
newUrl = mainUrl+"page/2/"
if 'class="next"' in content:
addDir(translation(30002)+" ("+nr+")", newUrl, 'listVideos', "")
xbmcplugin.endOfDirectory(pluginhandle)
if forceViewMode:
xbmc.executebuiltin('Container.SetViewMode('+viewMode+')')
def playVideo(url):
content = getUrl(url)
match = re.compile('"VIDEO_ID":"(.+?)"', re.DOTALL).findall(content)
matchYT0 = re.compile('data-youtube-id="(.+?)"', re.DOTALL).findall(content)
matchYT1 = re.compile('value="http://www.youtube.com/v/(.+?)\\?', re.DOTALL).findall(content)
matchYT2 = re.compile('href="https://www.youtube.com/watch\\?v=(.+?)"', re.DOTALL).findall(content)
matchYT3 = re.compile('src="http://www.youtube.com/embed/(.+?)"', re.DOTALL).findall(content)
url = ""
if match:
content = getUrl("http://video.giga.de/xml/"+match[0]+".xml")
match1 = re.compile('<high width="1280" height="720">(.+?)<filename>(.+?)</filename>', re.DOTALL).findall(content)
match2 = re.compile('<medium width="640" height="360">(.+?)<filename>(.+?)</filename>', re.DOTALL).findall(content)
if match1 and maxVideoQuality == "720p":
url = "http://video.giga.de/data/"+match1[0][1]
elif match2:
url = "http://video.giga.de/data/"+match2[0][1]
elif matchYT0:
url = getYoutubeUrl(matchYT0[0])
elif matchYT1:
url = getYoutubeUrl(matchYT1[0])
elif matchYT2:
url = getYoutubeUrl(matchYT2[0])
elif matchYT3:
url = getYoutubeUrl(matchYT3[0])
if url:
listitem = xbmcgui.ListItem(path=url)
xbmcplugin.setResolvedUrl(pluginhandle, True, listitem)
def queueVideo(url, name):
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
listitem = xbmcgui.ListItem(name)
playlist.add(url, listitem)
def getYoutubeUrl(id):
if xbox:
url = "plugin://video/YouTube/?path=/root/video&action=play_video&videoid=" + id
else:
url = "plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=" + id
return url
def cleanTitle(title):
return title.replace("<b>", "").replace("</b>", "").replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&").replace("&#038;", "&").replace("&#039;", "\\").replace("&#8211;", "-").replace("&#8220;", "-").replace("&#8221;", "-").replace("&#8217;", "'").replace("&quot;", "\"").strip()
def getUrl(url):
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0')
response = urllib2.urlopen(req)
link = response.read()
response.close()
return link
def parameters_string_to_dict(parameters):
paramDict = {}
if parameters:
paramPairs = parameters[1:].split("&")
for paramsPair in paramPairs:
paramSplits = paramsPair.split('=')
if (len(paramSplits)) == 2:
paramDict[paramSplits[0]] = paramSplits[1]
return paramDict
def addLink(name, url, mode, iconimage):
u = sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)
ok = True
liz = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
liz.setInfo(type="Video", infoLabels={"Title": name})
liz.setProperty('IsPlayable', 'true')
liz.addContextMenuItems([(translation(30003), 'RunPlugin(plugin://'+addonID+'/?mode=queueVideo&url='+urllib.quote_plus(u)+'&name='+urllib.quote_plus(name)+')',)])
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz)
return ok
def addDir(name, url, mode, iconimage):
u = sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)
ok = True
liz = xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo(type="Video", infoLabels={"Title": name})
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True)
return ok
params = parameters_string_to_dict(sys.argv[2])
mode = urllib.unquote_plus(params.get('mode', ''))
url = urllib.unquote_plus(params.get('url', ''))
name = urllib.unquote_plus(params.get('name', ''))
if mode == 'listVideosTop':
listVideosTop(url)
elif mode == 'listVideos':
listVideos(url)
elif mode == 'playVideo':
playVideo(url)
elif mode == "queueVideo":
queueVideo(url, name)
else:
index()