PageRenderTime 845ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/IPTVPlayer/hosts/hosthdprofili.py

https://gitlab.com/kamoula77/iptvplayer-for-e2
Python | 311 lines | 276 code | 18 blank | 17 comment | 14 complexity | b8e3cbcb2ea6fcc63d7155215dfd55c4 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. ###################################################
  3. # LOCAL import
  4. ###################################################
  5. from Plugins.Extensions.IPTVPlayer.components.iptvplayerinit import TranslateTXT as _, SetIPTVPlayerLastHostError
  6. from Plugins.Extensions.IPTVPlayer.components.ihost import CHostBase, CBaseHostClass, CDisplayListItem, RetHost, CUrlItem, ArticleContent
  7. from Plugins.Extensions.IPTVPlayer.tools.iptvtools import printDBG, printExc, CSearchHistoryHelper, remove_html_markup, GetLogoDir, GetCookieDir, byteify
  8. from Plugins.Extensions.IPTVPlayer.libs.pCommon import common, CParsingHelper
  9. import Plugins.Extensions.IPTVPlayer.libs.urlparser as urlparser
  10. from Plugins.Extensions.IPTVPlayer.libs.youtube_dl.utils import clean_html
  11. from Plugins.Extensions.IPTVPlayer.tools.iptvtypes import strwithmeta
  12. from Plugins.Extensions.IPTVPlayer.libs.moonwalkcc import MoonwalkParser
  13. from Plugins.Extensions.IPTVPlayer.libs.youtubeparser import YouTubeParser
  14. ###################################################
  15. ###################################################
  16. # FOREIGN import
  17. ###################################################
  18. import copy
  19. import re
  20. import urllib
  21. import base64
  22. try: import json
  23. except Exception: import simplejson as json
  24. from datetime import datetime
  25. from Components.config import config, ConfigSelection, ConfigYesNo, ConfigText, getConfigListEntry
  26. ###################################################
  27. ###################################################
  28. # E2 GUI COMMPONENTS
  29. ###################################################
  30. from Plugins.Extensions.IPTVPlayer.components.asynccall import MainSessionWrapper
  31. from Screens.MessageBox import MessageBox
  32. ###################################################
  33. ###################################################
  34. # Config options for HOST
  35. ###################################################
  36. def GetConfigList():
  37. optionList = []
  38. return optionList
  39. ###################################################
  40. def gettytul():
  41. return 'http://hdprofili.weebly.com/'
  42. class HDProfili(CBaseHostClass):
  43. MAIN_URL = 'http://hdprofili.weebly.com/'
  44. SEARCH_URL = MAIN_URL + 'index.php?q='
  45. DEFAULT_ICON_URL = 'http://hdprofili.weebly.com/uploads/3/0/9/8/30985093/1449164652.png'
  46. MAIN_CAT_TAB = [
  47. {'category':'movie_cats', 'title': _('Movie'), 'url':MAIN_URL+'filma-me-titra-shqip', 'icon':DEFAULT_ICON_URL },
  48. {'category':'list_items1', 'title': _('Animation [dubbing]'), 'url':MAIN_URL+'filma-te-dubluar-ne-shqip.html', 'icon':DEFAULT_ICON_URL },
  49. {'category':'list_items3', 'title': _('Series [dubbing]'), 'url':MAIN_URL+'seriale-dubluar-ne-shqip.html', 'icon':DEFAULT_ICON_URL },
  50. {'category':'list_items2', 'title': _('Animation [subtitles]'), 'url':MAIN_URL+'filma-te-animuar-me-titra-shqip.html', 'icon':DEFAULT_ICON_URL },
  51. {'category':'list_items3', 'title': _('Series [subtitles]'), 'url':MAIN_URL+'seriale-te-animuar-me-titra-shqip.html', 'icon':DEFAULT_ICON_URL },
  52. ]
  53. def __init__(self):
  54. CBaseHostClass.__init__(self, {'history':'HDProfili', 'cookie':'HDProfili.cookie'})
  55. def _getFullUrl(self, url):
  56. mainUrl = self.MAIN_URL
  57. if 0 < len(url) and not url.startswith('http'):
  58. if url.startswith('/'):
  59. url = url[1:]
  60. url = mainUrl + url
  61. if not mainUrl.startswith('https://'):
  62. url = url.replace('https://', 'http://')
  63. return url
  64. def listsTab(self, tab, cItem, type='dir'):
  65. printDBG("HDProfili.listsTab")
  66. for item in tab:
  67. params = dict(cItem)
  68. params.update(item)
  69. params['name'] = 'category'
  70. if type == 'dir':
  71. self.addDir(params)
  72. else: self.addVideo(params)
  73. def listMainMenu(self):
  74. printDBG("HDProfili.listMainMenu")
  75. self.listsTab(self.MAIN_CAT_TAB, {'name':'category'})
  76. def listCategories(self, cItem, category):
  77. printDBG("HDProfili.listCategories")
  78. sts, data = self.cm.getPage(cItem['url'])
  79. if not sts: return
  80. data = self.cm.ph.getDataBeetwenMarkers(data, '<p class="blog-category-list">', '</p>', False)[1]
  81. data = re.compile('<a[^<]+?href="([^"]+?)"[^<]*?>([^<]+?)</a>').findall(data)
  82. for item in data:
  83. params = dict(cItem)
  84. params.update({'title':item[1], 'url':self._getFullUrl(item[0]), 'category':category})
  85. self.addDir(params)
  86. def listItems1(self, cItem):
  87. printDBG("HDProfili.listItems1")
  88. page = cItem.get('page', 1)
  89. url = cItem['url']
  90. sts, data = self.cm.getPage(url)
  91. if not sts: return
  92. nextPageUrl = self.cm.ph.getDataBeetwenMarkers(data, '<div class="blog-page-nav-previous">', '</div>', False)[1]
  93. nextPageUrl = self.cm.ph.getSearchGroups(nextPageUrl, '<a[^<]+?href="([^"]+?)"[^<]*?>')[0]
  94. data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<div class="blog-header">', '</table>', False)
  95. for item in data:
  96. url = self.cm.ph.getSearchGroups(item, 'href="([^"]+?)"')[0]
  97. title = self.cm.ph.getDataBeetwenMarkers(item, '<h2 class="blog-title">', '</h2>', False)[1]
  98. title = self.cleanHtmlStr( title )
  99. if title == '': continue
  100. icon = self.cm.ph.getSearchGroups(item, '<img[^>]+?src="([^"]+?)"')[0]
  101. desc = self.cm.ph.getDataBeetwenMarkers(item, '<span class="date-text">', '</span>', False)[1]
  102. params = dict(cItem)
  103. params.update({'title':title, 'icon':self._getFullUrl(icon), 'desc':self.cleanHtmlStr(desc), 'url':self._getFullUrl(url)})
  104. self.addVideo(params)
  105. if nextPageUrl != '':
  106. params = dict(cItem)
  107. params.update({'title':_('Next page'), 'page':cItem.get('page', 1)+1, 'url':self._getFullUrl(nextPageUrl)})
  108. self.addDir(params)
  109. def listItems2(self, cItem, data=None, serTitle=''):
  110. printDBG("HDProfili.listItems2")
  111. if data == None:
  112. url = cItem['url']
  113. sts, data = self.cm.getPage(url)
  114. if not sts: return
  115. data = self.cm.ph.getAllItemsBeetwenMarkers(data, "<div class='galleryInnerImageHolder'>", '</a>', True)
  116. for item in data:
  117. url = self.cm.ph.getSearchGroups(item, '''href=["']([^"^']+?)["']''')[0]
  118. title = self.cleanHtmlStr( item )
  119. if title == '': title = self.cm.ph.getSearchGroups(item, '''title=["']([^"^']+?)["']''')[0]
  120. if title == '': continue
  121. icon = self.cm.ph.getSearchGroups(item, '''<img[^>]+?src=["']([^"^']+?)["']''')[0]
  122. desc = ''
  123. params = dict(cItem)
  124. params.update({'title':serTitle+title, 'icon':self._getFullUrl(icon), 'desc':self.cleanHtmlStr(desc), 'url':self._getFullUrl(url)})
  125. self.addVideo(params)
  126. def listItems3(self, cItem):
  127. printDBG("HDProfili.listItems3")
  128. sts, data = self.cm.getPage(cItem['url'])
  129. if not sts: return
  130. sp = '<h2 class="wsite-content-title" style="text-align:center;">'
  131. data = self.cm.ph.getDataBeetwenMarkers(data, sp, '</script>', False)[1]
  132. data = data.split(sp)
  133. for serItem in data:
  134. serieTitle = self.cleanHtmlStr( serItem.split('</h2>')[0] )
  135. self.listItems2(cItem, serItem, serieTitle + ': ')
  136. def getLinksForVideo(self, cItem):
  137. printDBG("HDProfili.getLinksForVideo [%s]" % cItem)
  138. urlTab = []
  139. if 'hdprofili.weebly.com' in cItem['url']:
  140. sts, data = self.cm.getPage(cItem['url'])
  141. if not sts: return []
  142. playerUrlTab = re.compile('''<iframe[^>]+?src=["']([^"^']+?)["']''', re.IGNORECASE).findall(data)
  143. for url in playerUrlTab:
  144. if url.startswith('//'):
  145. url = 'http:' + url
  146. if not url.startswith('http'): continue
  147. if 1 != self.up.checkHostSupport(url): continue
  148. urlTab.append({'name':self.up.getHostName(url), 'url':url, 'need_resolve':1})
  149. else:
  150. urlTab.append({'name':'main', 'url':cItem['url'], 'need_resolve':1})
  151. return urlTab
  152. def getVideoLinks(self, videoUrl):
  153. printDBG("HDProfili.getVideoLinks [%s]" % videoUrl)
  154. urlTab = []
  155. if videoUrl.startswith('http'):
  156. urlTab = self.up.getVideoLinkExt(videoUrl)
  157. return urlTab
  158. def getFavouriteData(self, cItem):
  159. return cItem['url']
  160. def getLinksForFavourite(self, fav_data):
  161. return self.getLinksForVideo({'url':fav_data})
  162. def handleService(self, index, refresh = 0, searchPattern = '', searchType = ''):
  163. printDBG('handleService start')
  164. CBaseHostClass.handleService(self, index, refresh, searchPattern, searchType)
  165. name = self.currItem.get("name", '')
  166. category = self.currItem.get("category", '')
  167. printDBG( "handleService: |||||||||||||||||||||||||||||||||||| name[%s], category[%s] " % (name, category) )
  168. self.currList = []
  169. #MAIN MENU
  170. if name == None:
  171. self.listMainMenu()
  172. elif category == 'movie_cats':
  173. self.listCategories(self.currItem, 'list_items1')
  174. elif category == 'list_items1':
  175. self.listItems1(self.currItem)
  176. elif category == 'list_items2':
  177. self.listItems2(self.currItem)
  178. elif category == 'list_items3':
  179. self.listItems3(self.currItem)
  180. else:
  181. printExc()
  182. CBaseHostClass.endHandleService(self, index, refresh)
  183. class IPTVHost(CHostBase):
  184. def __init__(self):
  185. CHostBase.__init__(self, HDProfili(), True, [CDisplayListItem.TYPE_VIDEO, CDisplayListItem.TYPE_AUDIO])
  186. def getLogoPath(self):
  187. return RetHost(RetHost.OK, value = [GetLogoDir('HDProfililogo.png')])
  188. def getLinksForVideo(self, Index = 0, selItem = None):
  189. retCode = RetHost.ERROR
  190. retlist = []
  191. if not self.isValidIndex(Index): return RetHost(retCode, value=retlist)
  192. urlList = self.host.getLinksForVideo(self.host.currList[Index])
  193. for item in urlList:
  194. retlist.append(CUrlItem(item["name"], item["url"], item['need_resolve']))
  195. return RetHost(RetHost.OK, value = retlist)
  196. # end getLinksForVideo
  197. def getResolvedURL(self, url):
  198. # resolve url to get direct url to video file
  199. retlist = []
  200. urlList = self.host.getVideoLinks(url)
  201. for item in urlList:
  202. need_resolve = 0
  203. retlist.append(CUrlItem(item["name"], item["url"], need_resolve))
  204. return RetHost(RetHost.OK, value = retlist)
  205. def converItem(self, cItem):
  206. hostList = []
  207. searchTypesOptions = [] # ustawione alfabetycznie
  208. hostLinks = []
  209. type = CDisplayListItem.TYPE_UNKNOWN
  210. possibleTypesOfSearch = None
  211. if 'category' == cItem['type']:
  212. if cItem.get('search_item', False):
  213. type = CDisplayListItem.TYPE_SEARCH
  214. possibleTypesOfSearch = searchTypesOptions
  215. else:
  216. type = CDisplayListItem.TYPE_CATEGORY
  217. elif cItem['type'] == 'video':
  218. type = CDisplayListItem.TYPE_VIDEO
  219. elif 'more' == cItem['type']:
  220. type = CDisplayListItem.TYPE_MORE
  221. elif 'audio' == cItem['type']:
  222. type = CDisplayListItem.TYPE_AUDIO
  223. if type in [CDisplayListItem.TYPE_AUDIO, CDisplayListItem.TYPE_VIDEO]:
  224. url = cItem.get('url', '')
  225. if '' != url:
  226. hostLinks.append(CUrlItem("Link", url, 1))
  227. title = cItem.get('title', '')
  228. description = cItem.get('desc', '')
  229. icon = cItem.get('icon', '')
  230. return CDisplayListItem(name = title,
  231. description = description,
  232. type = type,
  233. urlItems = hostLinks,
  234. urlSeparateRequest = 1,
  235. iconimage = icon,
  236. possibleTypesOfSearch = possibleTypesOfSearch)
  237. # end converItem
  238. def getSearchItemInx(self):
  239. try:
  240. list = self.host.getCurrList()
  241. for i in range( len(list) ):
  242. if list[i]['category'] == 'search':
  243. return i
  244. except Exception:
  245. printDBG('getSearchItemInx EXCEPTION')
  246. return -1
  247. def setSearchPattern(self):
  248. try:
  249. list = self.host.getCurrList()
  250. if 'history' == list[self.currIndex]['name']:
  251. pattern = list[self.currIndex]['title']
  252. search_type = list[self.currIndex]['search_type']
  253. self.host.history.addHistoryItem( pattern, search_type)
  254. self.searchPattern = pattern
  255. self.searchType = search_type
  256. except Exception:
  257. printDBG('setSearchPattern EXCEPTION')
  258. self.searchPattern = ''
  259. self.searchType = ''
  260. return