PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/addons/plugin.video.arjlover.net/default.py

http://seppius-xbmc-repo.googlecode.com/
Python | 216 lines | 193 code | 4 blank | 19 comment | 0 complexity | 7d39355e285cfa200f8855220645b79d MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Writer (c) 23/06/2011, Khrysev D.A., E-mail: x86demon@gmail.com
  5. #
  6. # This Program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This Program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; see the file COPYING. If not, write to
  18. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. # http://www.gnu.org/licenses/gpl.html
  20. import httplib
  21. import urllib
  22. import urllib2
  23. import re
  24. import sys
  25. import os
  26. import Cookie
  27. import xbmcplugin
  28. import xbmcgui
  29. import xbmcaddon
  30. import xbmc
  31. from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
  32. import socket
  33. socket.setdefaulttimeout(50)
  34. icon = xbmc.translatePath(os.path.join(os.getcwd().replace(';', ''), 'icon.png'))
  35. siteUrl = 'arjlover.net'
  36. httpSiteUrl = 'http://' + siteUrl
  37. sid_file = os.path.join(xbmc.translatePath('special://temp/'), 'plugin.video.arjlover.net.cookies.sid')
  38. h = int(sys.argv[1])
  39. def construct_request(params):
  40. return '%s?%s' % (sys.argv[0], urllib.urlencode(params))
  41. def htmlEntitiesDecode(string):
  42. return BeautifulStoneSoup(string, convertEntities=BeautifulStoneSoup.HTML_ENTITIES).contents[0]
  43. def showMessage(heading, message, times = 3000):
  44. xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s, "%s")'%(heading, message, times, icon))
  45. headers = {
  46. 'User-Agent' : 'Opera/9.80 (X11; Linux i686; U; ru) Presto/2.7.62 Version/11.00',
  47. 'Accept' :' text/html, application/xml, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*',
  48. 'Accept-Language':'ru-RU,ru;q=0.9,en;q=0.8',
  49. 'Accept-Charset' :'utf-8, utf-16, *;q=0.1',
  50. 'Accept-Encoding':'identity, *;q=0'
  51. }
  52. def GET(target, referer, post_params = None, accept_redirect = True, get_redirect_url = False):
  53. try:
  54. connection = httplib.HTTPConnection(siteUrl)
  55. if post_params == None:
  56. method = 'GET'
  57. post = None
  58. else:
  59. method = 'POST'
  60. post = urllib.urlencode(post_params)
  61. headers['Content-Type'] = 'application/x-www-form-urlencoded'
  62. if os.path.isfile(sid_file):
  63. fh = open(sid_file, 'r')
  64. csid = fh.read()
  65. fh.close()
  66. headers['Cookie'] = 'session=%s' % csid
  67. headers['Referer'] = referer
  68. connection.request(method, target, post, headers = headers)
  69. response = connection.getresponse()
  70. if response.status == 403:
  71. raise Exception("Forbidden, check credentials")
  72. if response.status == 404:
  73. raise Exception("File not found")
  74. if accept_redirect and response.status in (301, 302):
  75. target = response.getheader('location', '')
  76. if target.find("://") < 0:
  77. target = httpSiteUrl + target
  78. if get_redirect_url:
  79. return target
  80. else:
  81. return GET(target, referer, post_params, False)
  82. try:
  83. sc = Cookie.SimpleCookie()
  84. sc.load(response.msg.getheader('Set-Cookie'))
  85. fh = open(sid_file, 'w')
  86. fh.write(sc['session'].value)
  87. fh.close()
  88. except: pass
  89. if get_redirect_url:
  90. return False
  91. else:
  92. http = response.read()
  93. return http
  94. except Exception, e:
  95. showMessage('Error', e, 5000)
  96. return None
  97. def mainScreen(params):
  98. li = xbmcgui.ListItem('???????????')
  99. uri = construct_request({
  100. 'href': 'http://multiki.arjlover.net/multiki/',
  101. 'mode': 'getFiles'
  102. })
  103. xbmcplugin.addDirectoryItem(h, uri, li, True)
  104. li = xbmcgui.ListItem('??????')
  105. uri = construct_request({
  106. 'href': 'http://film.arjlover.net/film/',
  107. 'mode': 'getFiles'
  108. })
  109. xbmcplugin.addDirectoryItem(h, uri, li, True)
  110. li = xbmcgui.ListItem('??????? ??????')
  111. uri = construct_request({
  112. 'href': 'http://filmiki.arjlover.net/filmiki/',
  113. 'mode': 'getFiles'
  114. })
  115. xbmcplugin.addDirectoryItem(h, uri, li, True)
  116. xbmcplugin.endOfDirectory(h)
  117. def getFiles(params):
  118. categoryUrl = urllib.unquote_plus(params['href'])
  119. http = GET(categoryUrl, httpSiteUrl)
  120. if http == None: return False
  121. beautifulSoup = BeautifulSoup(http)
  122. links = beautifulSoup.findAll('td', 'l')
  123. if len(links) == 0:
  124. showMessage('??????', '???????? ????????', 3000)
  125. return False
  126. else:
  127. for link in links:
  128. try:
  129. titleText = link.find('a').string
  130. tds = link.findNextSiblings('td')
  131. href = tds[-1].find('a')['href']
  132. parts = href.split('/')
  133. li = xbmcgui.ListItem(titleText)
  134. li.setProperty('IsPlayable', 'true')
  135. li.setInfo(type='video', infoLabels={'title': titleText})
  136. uri = construct_request({
  137. 'mode': 'play',
  138. 'file': categoryUrl + parts[-1],
  139. 'referer': categoryUrl
  140. })
  141. xbmcplugin.addDirectoryItem(h, uri, li)
  142. except:
  143. pass
  144. xbmcplugin.endOfDirectory(h)
  145. def play(params):
  146. referer = urllib.unquote_plus(params['referer'])
  147. file = urllib.unquote_plus(params['file'])
  148. headers['Referer'] = referer
  149. # file = urllib.urlopen(file)
  150. # fileUrl = file.geturl()
  151. # i = xbmcgui.ListItem(path = fileUrl)
  152. i = xbmcgui.ListItem(path = file)
  153. xbmcplugin.setResolvedUrl(h, True, i)
  154. def get_params(paramstring):
  155. param=[]
  156. if len(paramstring)>=2:
  157. params=paramstring
  158. cleanedparams=params.replace('?','')
  159. if (params[len(params)-1]=='/'):
  160. params=params[0:len(params)-2]
  161. pairsofparams=cleanedparams.split('&')
  162. param={}
  163. for i in range(len(pairsofparams)):
  164. splitparams={}
  165. splitparams=pairsofparams[i].split('=')
  166. if (len(splitparams))==2:
  167. param[splitparams[0]]=splitparams[1]
  168. return param
  169. params = get_params(sys.argv[2])
  170. mode = None
  171. func = None
  172. try:
  173. mode = urllib.unquote_plus(params['mode'])
  174. except:
  175. mainScreen(params)
  176. if (mode != None):
  177. try:
  178. func = globals()[mode]
  179. except:
  180. pass
  181. if func: func(params)