[1a1f23]: plugin.video.tv2.dk / addon.py Maximize Restore History

Download this file

addon.py    115 lines (93 with data), 3.5 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
#
# Copyright (C) 2013 Tommy Winther
# http://tommy.winther.nu
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this Program; see the file LICENSE.txt. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
#
import sys
import os
import re
import urlparse
import urllib
import urllib2
import xml.etree.ElementTree as ET
import datetime
import time
import xbmcgui
import xbmcplugin
import xbmcaddon
import buggalo
def listFeed():
u = urllib2.urlopen('http://feed.theplatform.com/f/EHsYJC/Q_eFvtpVupQZ')
data = u.read()
u.close()
# strip namespaces
data = re.sub('<[a-z]+:', '<', data)
data = re.sub('</[a-z]+:', '</', data)
items = list()
doc = ET.fromstring(data)
for rssItem in doc.findall('channel/item'):
if not 'video' in rssItem.find('content').get('type'):
continue
image = rssItem.findtext('defaultThumbnailUrl')
if not image:
image = ICON
date = parseDate(rssItem.findtext('pubDate'))
infoLabels = {}
duration = rssItem.find('content').get('duration')
if duration:
infoLabels['duration'] = int(float(duration) / 60) + 1
infoLabels['date'] = date.strftime('%d.%m.%Y')
infoLabels['year'] = int(date.strftime('%Y'))
item = xbmcgui.ListItem(rssItem.findtext('title'), iconImage=image, thumbnailImage=image)
item.setInfo('video', infoLabels)
item.setProperty('Fanart_Image', FANART)
item.setProperty('IsPlayable', 'true')
items.append((PATH + '?' + urllib.urlencode({'url': rssItem.find('content').get('url')}), item, False))
xbmcplugin.addDirectoryItems(HANDLE, items)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_DATE)
xbmcplugin.endOfDirectory(HANDLE)
def playVideo(url):
print url
u = urllib2.urlopen(url)
smil = u.read()
u.close()
# strip namespaces
smil = re.sub('xmlns=[^>]+', '', smil)
doc = ET.fromstring(smil)
src = doc.find('body/seq/switch/video').get('src')
item = xbmcgui.ListItem(path=src)
xbmcplugin.setResolvedUrl(HANDLE, True, item)
def parseDate(dateStr):
try:
return datetime.datetime.strptime(dateStr[0:-4], '%a, %d %b %Y %H:%M:%S')
except TypeError:
return datetime.datetime.fromtimestamp(time.mktime(time.strptime(dateStr[0:-4], '%a, %d %b %Y %H:%M:%S')))
if __name__ == '__main__':
ADDON = xbmcaddon.Addon()
PATH = sys.argv[0]
HANDLE = int(sys.argv[1])
PARAMS = urlparse.parse_qs(sys.argv[2][1:])
ICON = os.path.join(ADDON.getAddonInfo('path'), 'icon.png')
FANART = os.path.join(ADDON.getAddonInfo('path'), 'fanart.jpg')
buggalo.SUBMIT_URL = 'http://tommy.winther.nu/exception/submit.php'
try:
if 'url' in PARAMS:
playVideo(PARAMS['url'][0])
else:
listFeed()
except Exception:
buggalo.onExceptionRaised()