Advertisement
sweetgdx

raiplay

Feb 3rd, 2018
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.27 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import urllib2
  3. import json
  4.  
  5. class RaiPlay:
  6.     # From http://www.raiplay.it/mobile/prod/config/RaiPlay_Config.json
  7.     baseUrl = "http://www.rai.it/"
  8.     channelsUrl = "http://www.rai.it/dl/RaiPlay/2016/PublishingBlock-9a2ff311-fcf0-4539-8f8f-c4fee2a71d58.html?json"
  9.     localizeUrl = "http://mediapolisgs.rai.it/relinker/relinkerServlet.htm?cont=201342"
  10.     menuUrl = "http://www.rai.it/dl/RaiPlay/2016/menu/PublishingBlock-20b274b1-23ae-414f-b3bf-4bdc13b86af2.html?homejson"
  11.     palinsestoUrl = "http://www.rai.it/dl/palinsesti/Page-e120a813-1b92-4057-a214-15943d95aa68-json.html?canale=[nomeCanale]&giorno=[dd-mm-yyyy]"
  12.     AzTvShowPath = "/dl/RaiTV/RaiPlayMobile/Prod/Config/programmiAZ-elenco.json"
  13.     noThumbUrl = "http://www.rai.it/cropgd/256x144/dl/components/img/imgPlaceholder.png"   
  14.    
  15.    
  16.     def __init__(self):
  17.         opener = urllib2.build_opener()
  18.         opener.addheaders = [('User-Agent', "Mozilla/5.0 (Windows NT 10; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36")]
  19.         urllib2.install_opener(opener) 
  20.    
  21.     def getCountry(self):
  22.         response = urllib2.urlopen(self.localizeUrl).read()
  23.         return response
  24.        
  25.     def getChannels(self):
  26.         response = json.load(urllib2.urlopen(self.channelsUrl))
  27.         return response["dirette"]
  28.        
  29.     def getProgrammes(self, channelName, epgDate):
  30.         channelTag = channelName.replace(" ", "")
  31.         url = self.palinsestoUrl
  32.         url = url.replace("[nomeCanale]", channelTag)
  33.         url = url.replace("[dd-mm-yyyy]", epgDate)
  34.         response = json.load(urllib2.urlopen(url))
  35.         return response[channelName][0]["palinsesto"][0]["programmi"]
  36.        
  37.     def getMainMenu(self):
  38.         response = json.load(urllib2.urlopen(self.menuUrl))
  39.         return response["menu"]
  40.  
  41.     # RaiPlay Genere Page
  42.     # RaiPlay Tipologia Page
  43.     def getCategory(self, pathId):
  44.         url = self.getUrl(pathId)
  45.         response = json.load(urllib2.urlopen(url))
  46.         return response["blocchi"]
  47.  
  48.     # Raiplay Tipologia Item
  49.     def getProgrammeList(self, pathId):
  50.         url = self.getUrl(pathId)
  51.         response = json.load(urllib2.urlopen(url))
  52.         return response
  53.    
  54.     #  PLR programma Page
  55.     def getProgramme(self, pathId):
  56.         url = self.getUrl(pathId)
  57.         response = json.load(urllib2.urlopen(url))
  58.         return response["Blocks"]
  59.    
  60.     def getContentSet(self, url):
  61.         url = self.getUrl(url)
  62.         response = json.load(urllib2.urlopen(url))
  63.         return response["items"]
  64.    
  65.     def getVideoUrl(self, pathId):
  66.         url = self.getUrl(pathId)
  67.         response = json.load(urllib2.urlopen(url))
  68.         url = response["video"]["contentUrl"]
  69.         return url
  70.  
  71.     def getUrl(self, pathId):
  72.         pathId = pathId.replace(" ", "%20")
  73.         if pathId[0:2] == "//":
  74.             url = "http:" + pathId
  75.         elif pathId[0] == "/":
  76.             url = self.baseUrl[:-1] + pathId
  77.         else:
  78.             url = pathId
  79.         return url
  80.        
  81.     def getThumbnailUrl(self, pathId):
  82.         if pathId == "":
  83.             url = self.noThumbUrl
  84.         else:
  85.             url = self.getUrl(pathId)
  86.             url = url.replace("[RESOLUTION]", "256x-")
  87.         return url
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement