Guest User

3.0.7 scraper.py potential patch

a guest
May 7th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.41 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # KodiAddon PBSKids
  3. #
  4. from t1mlib import t1mAddon
  5. import json
  6. import re
  7. import os
  8. import urllib
  9. import urllib2
  10. import xbmc
  11. import xbmcplugin
  12. import xbmcgui
  13. import sys
  14. import HTMLParser
  15. import time
  16.  
  17. h = HTMLParser.HTMLParser()
  18. UTF8 = 'utf-8'
  19.  
  20.  
  21. class myAddon(t1mAddon):
  22.  
  23.   def getAddonMenu(self,url,ilist):
  24.       html = self.getRequest('https://content.services.pbskids.org/v2/kidspbsorg/home/?imgsizes=showLogo:88x88,showLogoSquare:100x100')
  25.       a = json.loads(html)
  26.       a = a["collections"]
  27.       b = a['kids-show-spotlight']["content"]
  28.       b.extend(a["kids-programs-tier-1"]["content"])
  29.       b.extend(a["kids-programs-tier-2"]["content"])
  30.       b.extend(a["kids-programs-tier-3"]["content"])
  31.       for c in b:
  32.           name = c["title"]
  33.           url = c["slug"]
  34.           thumb = c["images"]["mezzanine_16x9"]
  35.           fanart = c["images"]["background"]
  36.           infoList = {}
  37.           infoList['Title'] = name
  38.           infoList['Plot'] = name
  39.           infoList['TVShowTitle'] = name
  40.           infoList['mediatype'] = 'tvshow'
  41.           ilist = self.addMenuItem(name,'GE', ilist, url, thumb, fanart, infoList, isFolder=True)
  42.       return(ilist)
  43.  
  44.  
  45.   def getAddonEpisodes(self,url,ilist):
  46.       # There are two potential valid URLs to search.  Check both addresses to make sure no valid episodes are skipped:
  47.       addressList = ['https://cms-tc.pbskids.org/pbskidsvideoplaylists/'+url+'.json?imgsizes=showLogo:88x88,showLogoSquare:100x100']
  48.       addressList.append('https://content.services.pbskids.org/v2/kidspbsorg/programs/'+url+'?imgsizes=showLogo:88x88,showLogoSquare:100x100')
  49.       titleList = []
  50.       for address in addressList:
  51.           html = self.getRequest(address)
  52.           a = json.loads(html)
  53.           a = a['collections']['episodes']['content']
  54.           for b in a:
  55.               url = b.get('mp4')
  56.               if not url is None:
  57.                   validEpisode = False  # Initialize, assume its not valid unless proven otherwise.
  58.                   name = b.get('title','no title')
  59.                   thumb  = b.get('images',{'x':None}).get('mezzanine', self.addonIcon)
  60.                   fanart  = b.get('images',{'x':None}).get('mezzanine', self.addonFanart)
  61.                   c = b.get('closedCaptions',[])
  62.                   captions = ''
  63.                   for d in c:
  64.                      if d.get('format') == 'SRT':
  65.                          captions = d.get('URI','')
  66.                          break
  67.                   infoList={}
  68.                   infoList['Title'] = name
  69.                   infoList['TVShowTitle'] = xbmc.getInfoLabel('ListItem.TVShowTitle')
  70.                   expireDate = b.get('expire_date')
  71.                   if expireDate == None:  # Null (Means it never expires)
  72.                       validEpisode = True
  73.                       expireString = "N/A"
  74.                   else: # Check the expire date:
  75.                       expireString = expireDate[0:10]
  76.                       expireYear   = int(expireDate[0:4])
  77.                       expireMonth  = int(expireDate[5:7])
  78.                       expireDay    = int(expireDate[8:10])
  79.                       currentYear  = int(time.strftime("%Y"))
  80.                       currentMonth = int(time.strftime("%m"))
  81.                       currentDay   = int(time.strftime("%d"))
  82.                       if currentYear <= expireYear:
  83.                           if currentMonth <= expireMonth:
  84.                               if currentDay < expireDay:    # Assume expires immediately
  85.                                   validEpisode = True
  86.                   infoList['Plot']  = b.get('description') + "  [Expires: %s]"%expireString
  87.                   infoList['mediatype'] = 'episode'
  88.                   if (validEpisode == True) and (name not in titleList):  # Make sure episode is valid, and not apready added
  89.                       ilist = self.addMenuItem(name,'GV', ilist, url+'|'+captions, thumb, fanart, infoList, isFolder=False)
  90.                       titleList.append(name)
  91.       return(ilist)
  92.  
  93.  
  94.   def getAddonVideo(self,url):
  95.       url, captions = url.split('|',1)
  96.       html = self.getRequest('%s?format=json' % url)
  97.       a = json.loads(html)
  98.       url = a.get('url')
  99.       if url is not None:
  100.               liz = xbmcgui.ListItem(path = url)
  101.               if len(captions) > 0:
  102.                   liz.setSubtitles([captions])
  103.               xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
Add Comment
Please, Sign In to add comment