/plugin.video.alfa/channels/porn4days.py

https://github.com/alfa-addon/addon · Python · 147 lines · 125 code · 20 blank · 2 comment · 20 complexity · b1b0ea0ecd2cb86491d3839e2d2d877d MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. #------------------------------------------------------------
  3. import sys
  4. PY3 = False
  5. if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int
  6. if PY3:
  7. import urllib.parse as urlparse # Es muy lento en PY2. En PY3 es nativo
  8. else:
  9. import urlparse # Usamos el nativo de PY2 que es más rápido
  10. import re
  11. from platformcode import config, logger
  12. from core import scrapertools
  13. from core.item import Item
  14. from core import servertools
  15. from core import httptools
  16. from bs4 import BeautifulSoup
  17. host = 'http://porn4days.biz/'
  18. def mainlist(item):
  19. logger.info()
  20. itemlist = []
  21. itemlist.append(item.clone(title="Nuevos" , action="lista", url=host + "newest/page1"))
  22. itemlist.append(item.clone(title="Mas vistos" , action="lista", url=host + "popullar/page1"))
  23. itemlist.append(item.clone(title="Canal" , action="canal", url=host + "paysitelist"))
  24. itemlist.append(item.clone(title="Categorias" , action="categorias", url=host + "tags"))
  25. itemlist.append(item.clone(title="Buscar", action="search"))
  26. return itemlist
  27. def search(item, texto):
  28. logger.info()
  29. texto = texto.replace(" ", "+")
  30. item.url = "%s/search/page1/?s=%s" % (host,texto)
  31. try:
  32. return lista(item)
  33. except:
  34. import sys
  35. for line in sys.exc_info():
  36. logger.error("%s" % line)
  37. return []
  38. def canal(item):
  39. logger.info()
  40. itemlist = []
  41. soup = create_soup(item.url)
  42. matches = soup.find_all('div', class_='col-lg-3')
  43. for elem in matches:
  44. url = elem.a['href']
  45. title = elem.a.text
  46. url = urlparse.urljoin(host,url)
  47. thumbnail = ""
  48. plot = ""
  49. itemlist.append(item.clone(action="lista", title=title, url=url,
  50. thumbnail=thumbnail , plot=plot) )
  51. return itemlist
  52. def categorias(item):
  53. logger.info()
  54. itemlist = []
  55. soup = create_soup(item.url)
  56. matches = soup.find_all('div', class_='col-lg-3')
  57. for elem in matches:
  58. url = elem.a['href']
  59. thumbnail = elem.img['src']
  60. title = elem.img['alt']
  61. url = urlparse.urljoin(host,url)
  62. thumbnail = urlparse.urljoin(host,thumbnail)
  63. plot = ""
  64. itemlist.append(item.clone(action="lista", title=title, url=url,
  65. thumbnail=thumbnail , plot=plot) )
  66. return itemlist
  67. def create_soup(url, referer=None, unescape=False):
  68. logger.info()
  69. if referer:
  70. data = httptools.downloadpage(url, headers={'Referer': referer}).data
  71. else:
  72. data = httptools.downloadpage(url).data
  73. if unescape:
  74. data = scrapertools.unescape(data)
  75. soup = BeautifulSoup(data, "html5lib", from_encoding="utf-8")
  76. return soup
  77. def lista(item):
  78. logger.info()
  79. itemlist = []
  80. soup = create_soup(item.url)
  81. matches = soup.find_all('div', class_='col-lg-3')
  82. for elem in matches:
  83. url = elem.a['href']
  84. title = elem.img['alt']
  85. thumbnail = elem.img['src']
  86. time = elem.find('div', class_='timer')
  87. if time:
  88. time = time.text.strip()
  89. title = "[COLOR yellow]%s[/COLOR] %s" % (time,title)
  90. url = urlparse.urljoin(host,url)
  91. thumbnail = urlparse.urljoin(host,thumbnail)
  92. plot = ""
  93. action = "play"
  94. if logger.info() == False:
  95. action = "findvideos"
  96. itemlist.append(item.clone(action=action, title=title, url=url, thumbnail=thumbnail,
  97. plot=plot, fanart=thumbnail, contentTitle=title ))
  98. next_page = soup.find('a', rel='next')
  99. if next_page:
  100. next_page = next_page['href']
  101. if "/?s=" in item.url and not"/search/" in next_page:
  102. next_page = "/search%s" %next_page
  103. next_page = urlparse.urljoin(host,next_page)
  104. itemlist.append(item.clone(action="lista", title="[COLOR blue]Página Siguiente >>[/COLOR]", url=next_page) )
  105. return itemlist
  106. def findvideos(item):
  107. logger.info(item)
  108. itemlist = []
  109. data = httptools.downloadpage(item.url).data
  110. videos = scrapertools.find_multiple_matches(data, '\("#playerframe"\).attr\("src", "([^"]+)"')
  111. for elem in videos:
  112. url = elem
  113. if url:
  114. itemlist.append(item.clone(action="play", title= "%s", contentTitle = item.title, url=url))
  115. itemlist = servertools.get_servers_itemlist(itemlist, lambda i: i.title % i.server.capitalize())
  116. return itemlist
  117. def play(item):
  118. logger.info(item)
  119. itemlist = []
  120. data = httptools.downloadpage(item.url).data
  121. videos = scrapertools.find_multiple_matches(data, '\("#playerframe"\).attr\("src", "([^"]+)"')
  122. for elem in videos:
  123. url = elem
  124. if url:
  125. itemlist.append(item.clone(action="play", title= "%s", contentTitle = item.title, url=url))
  126. itemlist = servertools.get_servers_itemlist(itemlist, lambda i: i.title % i.server.capitalize())
  127. return itemlist