Advertisement
k1m05

Dailymotion Resolver

Sep 29th, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. '''
  2. dailymotion urlresolver plugin
  3. Copyright (C) 2011 cyrus007
  4.  
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. '''
  18. import os
  19. import xbmc
  20. from t0mm0.common.net import Net
  21. from urlresolver.plugnplay.interfaces import UrlResolver
  22. from urlresolver.plugnplay.interfaces import PluginSettings
  23. from urlresolver.plugnplay import Plugin
  24. import re
  25. import urllib2, urllib
  26. from urlresolver import common
  27.  
  28. logo=os.path.join(common.addon_path, 'resources', 'images', 'redx.png')
  29.  
  30. class DailymotionResolver(Plugin, UrlResolver, PluginSettings):
  31. implements = [UrlResolver, PluginSettings]
  32. name = "dailymotion"
  33.  
  34. def __init__(self):
  35. p = self.get_setting('priority') or 100
  36. self.priority = int(p)
  37. self.net = Net()
  38.  
  39.  
  40. def get_media_url(self, host, media_id):
  41. try:
  42. web_url = self.get_url(host, media_id)
  43. link = self.net.http_GET(web_url).content
  44. if link.find('"error":') >= 0:
  45. err_title = re.compile('"title":"(.+?)"').findall(link)[0]
  46. if not err_title:
  47. err_title = 'Content not available.'
  48.  
  49. err_message = re.compile('"message":"(.+?)"').findall(link)[0]
  50. if not err_message:
  51. err_message = 'No such video or the video has been removed due to copyright infringement issues.'
  52.  
  53. common.addon.log_error(self.name + ' - fetching %s - %s - %s ' % (web_url,err_title,err_message))
  54. xbmc.executebuiltin('XBMC.Notification([B][COLOR white]DAILYMOTION[/COLOR][/B] - '+err_title+',[COLOR red]'+err_message+'[/COLOR],8000,'+logo+')')
  55. return self.unresolvable()
  56.  
  57. imgSrc = re.compile('"thumbnail_url":"(.+?)"').findall(link)[0]
  58. common.addon.log('img:' + imgSrc)
  59.  
  60. dm_live = re.compile('live_rtsp_url":"(.+?)"', re.DOTALL).findall(link)
  61. dm_1080p = re.compile('"stream_h264_hd1080_url":"(.+?)"', re.DOTALL).findall(link)
  62. dm_720p = re.compile('"stream_h264_hd_url":"(.+?)"', re.DOTALL).findall(link)
  63. dm_high = re.compile('"stream_h264_hq_url":"(.+?)"', re.DOTALL).findall(link)
  64. dm_low = re.compile('"stream_h264_url":"(.+?)"', re.DOTALL).findall(link)
  65. dm_low2 = re.compile('"stream_h264_ld_url":"(.+?)"', re.DOTALL).findall(link)
  66.  
  67. videoUrl = []
  68.  
  69. if dm_live:
  70. liveVideoUrl = urllib.unquote_plus(dm_live[0]).replace("\\/", "/")
  71. liveVideoUrl = liveVideoUrl.replace("protocol=rtsp", "protocol=rtmp")
  72. liveVideoUrl = self.net.http_GET(liveVideoUrl).content
  73. videoUrl.append(liveVideoUrl)
  74. else:
  75. if dm_1080p:
  76. videoUrl.append( urllib.unquote_plus(dm_1080p[0]).replace("\\/", "/") )
  77. if dm_720p:
  78. videoUrl.append( urllib.unquote_plus(dm_720p[0]).replace("\\/", "/") )
  79. if dm_high:
  80. videoUrl.append( urllib.unquote_plus(dm_high[0]).replace("\\/", "/") )
  81. if dm_low:
  82. videoUrl.append( urllib.unquote_plus(dm_low[0]).replace("\\/", "/") )
  83. if dm_low2:
  84. videoUrl.append( urllib.unquote_plus(dm_low2[0]).replace("\\/", "/") )
  85.  
  86. vUrl = ''
  87. vUrlsCount = len(videoUrl)
  88. if vUrlsCount > 0:
  89. q = self.get_setting('quality')
  90. if q == '0':
  91. # Highest Quality
  92. vUrl = videoUrl[0]
  93. elif q == '1':
  94. # Medium Quality
  95. vUrl = videoUrl[(int)(vUrlsCount / 2)]
  96. elif q == '2':
  97. # Lowest Quality
  98. vUrl = videoUrl[vUrlsCount - 1]
  99.  
  100. common.addon.log('url:' + vUrl)
  101.  
  102. return vUrl
  103.  
  104. except BaseException, e:
  105. common.addon.log_error(self.name + ' - Exception: %s' % e)
  106. return False
  107.  
  108.  
  109. def get_url(self, host, media_id):
  110. return 'http://www.dailymotion.com/embed/video/%s' % media_id
  111.  
  112.  
  113. def get_host_and_id(self, url):
  114. r = re.search('//(.+?)/embed/video/([0-9A-Za-z]+)', url)
  115. if r:
  116. return r.groups()
  117. else:
  118. r = re.search('//(.+?)/swf/video/([0-9A-Za-z]+)', url)
  119. if r:
  120. return r.groups()
  121. else:
  122. r = re.search('//(.+?)/video/([0-9A-Za-z]+)', url)
  123. if r:
  124. return r.groups()
  125. else:
  126. r = re.search('//(.+?)/swf/([0-9A-Za-z]+)', url)
  127. if r:
  128. return r.groups()
  129. else:
  130. r = re.search('//(.+?)/sequence/([0-9A-Za-z]+)', url)
  131. if r:
  132. return r.groups()
  133. else:
  134. return False
  135.  
  136.  
  137. def valid_url(self, url, host):
  138. if self.get_setting('enabled') == 'false': return False
  139. return re.match('http://(www.)?dailymotion.com/sequence/[0-9A-Za-z]+', url) or \
  140. re.match('http://(www.)?dailymotion.com/video/[0-9A-Za-z]+', url) or \
  141. re.match('http://(www.)?dailymotion.com/swf/[0-9A-Za-z]+', url) or \
  142. re.match('http://(www.)?dailymotion.com/embed/[0-9A-Za-z]+', url) or \
  143. self.name in host
  144.  
  145. #PluginSettings methods
  146. def get_settings_xml(self):
  147. xml = PluginSettings.get_settings_xml(self)
  148. xml += '<setting label="Video Quality" id="%s_quality" ' % self.__class__.__name__
  149. xml += 'type="enum" values="High|Medium|Low" default="0" />\n'
  150. return xml
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement