Enigma2 plugin to to play various online streams (mostly Latvian).

anyfilesresolver.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # -*- coding: UTF-8 -*-
  2. # * GNU General Public License for more details.
  3. # *
  4. # *
  5. # * You should have received a copy of the GNU General Public License
  6. # * along with this program; see the file COPYING. If not, write to
  7. # * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  8. # * http://www.gnu.org/copyleft/gpl.html
  9. # *
  10. # *
  11. # * thanks to http://code.google.com/p/sd-xbmc/
  12. # */
  13. import re
  14. import urllib
  15. import urllib2
  16. import random
  17. import decimal
  18. import util
  19. __name__='anyfiles'
  20. BASE_URL = 'http://video.anyfiles.pl'
  21. def supports(url):
  22. return not _regex(url) == None
  23. def _gen_random_decimal(i, d):
  24. return decimal.Decimal('%d.%d' % (random.randint(0, i), random.randint(0, d)))
  25. def _decode(param):
  26. #-- define variables
  27. loc_3 = [0,0,0,0]
  28. loc_4 = [0,0,0]
  29. loc_2 = ''
  30. #-- define hash parameters for decoding
  31. dec = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  32. hash1 = ["L", "y", "c", "X", "2", "M", "a", "l", "p", "5", "Q", "e", "R", "t", "Z", "Y", "9", "m", "d", "0", "s", "V", "b", "3", "7", "="]
  33. hash2 = ["i", "B", "v", "U", "H", "4", "D", "n", "k", "8", "x", "T", "u", "G", "w", "f", "N", "J", "6", "W", "1", "g", "z", "o", "I", "r"]
  34. hash1 = ["c", "u", "4", "V", "z", "5", "k", "m", "y", "p", "L", "J", "I", "d", "0", "M", "9", "e", "3", "8", "v", "l", "i", "7", "n", "="];
  35. hash2 = ["t", "Y", "T", "x", "B", "g", "G", "b", "2", "X", "1", "R", "a", "N", "w", "Q", "f", "W", "U", "D", "Z", "s", "6", "H", "o", "r"]
  36. #-- decode
  37. for i in range(0, len(hash1)):
  38. re1 = hash1[i]
  39. re2 = hash2[i]
  40. param = param.replace(re1, '___')
  41. param = param.replace(re2, re1)
  42. param = param.replace('___', re2)
  43. i = 0
  44. while i < len(param):
  45. j = 0
  46. while j < 4 and i+j < len(param):
  47. loc_3[j] = dec.find(param[i+j])
  48. j = j + 1
  49. loc_4[0] = (loc_3[0] << 2) + ((loc_3[1] & 48) >> 4);
  50. loc_4[1] = ((loc_3[1] & 15) << 4) + ((loc_3[2] & 60) >> 2);
  51. loc_4[2] = ((loc_3[2] & 3) << 6) + loc_3[3];
  52. j = 0
  53. while j < 3:
  54. if loc_3[j + 1] == 64:
  55. break
  56. try:
  57. loc_2 += unichr(loc_4[j])
  58. except:
  59. pass
  60. j = j + 1
  61. i = i + 4;
  62. return loc_2
  63. def resolve(url):
  64. m = _regex(url)
  65. if m:
  66. resp = urllib2.urlopen(url)
  67. sessc = resp.headers.get('Set-Cookie').split(';')[0]
  68. resp.close()
  69. furl = "%s/w.jsp?id=%s&width=620&height=349&pos=&skin=0" % (BASE_URL,m.group('id'))
  70. headers = {'Cookie':sessc, 'Referer':url}
  71. data = util.request(furl,headers)
  72. m1 = re.search('document.cookie = "([^"]+?)"',data)
  73. m2 = re.search('src="(\/pcsevlet\?code=[^"]+)', data)
  74. if m1 and m2:
  75. headers['Cookie'] = headers['Cookie'] + '; ' + m1.group(1)
  76. headers['Referer'] = BASE_URL + '/flowplayer/flowplayer.commercial-3.2.16.swf'
  77. data = util.request(BASE_URL + m2.group(1),headers)
  78. m_vurl = re.search("'url':.*?'(http[^']+?mp4)'", data, re.DOTALL)
  79. m_surl = re.search("'captionUrl':.*?'(http[^']+)'",data, re.DOTALL)
  80. if m_vurl:
  81. resolved = {'url':m_vurl.group(1).strip(),'quality':'???'}
  82. if m_surl:
  83. resolved['subs'] = m_surl.group(1).strip()
  84. return [resolved]
  85. else:
  86. return []
  87. def _regex(url):
  88. return re.search('video\.anyfiles\.pl/w\.jsp\?id=(?P<id>\d+)',url,re.IGNORECASE | re.DOTALL)