summaryrefslogtreecommitdiff
path: root/plugin.video.charge/resources/lib/scraper.py
blob: b3e1116e071278e0adcebe8c05da97e3f33af638 (plain)
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
# -*- coding: utf-8 -*-
# KodiAddon (Charge! TV Live)
#
from t1mlib import t1mAddon
import json
import re
import urllib
import xbmcplugin
import xbmcgui
import calendar
import datetime
import sys

UTF8 = 'utf-8'

class myAddon(t1mAddon):

  def getAddonMenu(self,url,ilist):
      xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
      html = self.getRequest('http://watchcharge.com/watch-live/')
      print "html = "+str(html)
      url = re.compile('file: "(.+?)"', re.DOTALL).search(html).group(1)
      thumb  = self.addonIcon
      fanart = self.addonFanart
      d = datetime.datetime.utcnow()
      now = calendar.timegm(d.utctimetuple())
      html = self.getRequest('http://mobilelistings.tvguide.com/Listingsweb/ws/rest/airings/20517/start/'+str(now)+'/duration/20160?channelsourceids=34067%7C43.2&formattype=json')
      a = json.loads(html)
      for b in a[:10]:
         infoList = {}
         b = b['ProgramSchedule']
         st = datetime.datetime.fromtimestamp(float(b['StartTime'])).strftime('%H:%M')
         et = datetime.datetime.fromtimestamp(float(b['EndTime'])).strftime('%H:%M')
         infoList['duration'] = int(float(b['EndTime']) - float(b['StartTime']))
         name = b['Title']
         if b['EpisodeTitle'] != '':
            infoList['TVShowTitle'] = name
            season = b['TVObject'].get('SeasonNumber')
            if season is not None: 
                infoList['Season'] = int(season)
            episode = b['TVObject']['EpisodeNumber']
            if episode is not None:
                infoList['Episode'] = int(episode)
         plot = '%s - %s                 %s min.[CR][COLOR blue]%s[/COLOR][CR]%s' % (st, et, infoList['duration'] / 60,  b['EpisodeTitle'], b['CopyText'])
         infoList['Plot'] = plot
         infoList['MPAA'] = b.get('Rating')
         infoList['mediatype'] = 'episode'
         ilist = self.addMenuItem(name,'GV', ilist, url, thumb, fanart, infoList, isFolder=False)
      return(ilist)

  def getAddonVideo(self,url):
      liz = xbmcgui.ListItem(path = url)
      xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)