SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/usr/bin/python | |
| 2 | # -*- coding: utf-8 -* | |
| 3 | import xbmcplugin | |
| 4 | import xbmc | |
| 5 | import xbmcgui | |
| 6 | - | import urllib |
| 6 | + | |
| 7 | import re | |
| 8 | import sys | |
| 9 | from BeautifulSoup import BeautifulStoneSoup | |
| 10 | import resources.lib._common as common | |
| 11 | import resources.lib.m3u8 as m3u8 | |
| 12 | ||
| 13 | - | import base64 |
| 13 | + | |
| 14 | ||
| 15 | BRANDID = '001' | |
| 16 | PARTNERID = '585231' | |
| 17 | SITE = 'abc' | |
| 18 | SHOWLIST = 'http://abc.go.com/vp2/ws/s/contents/2012/shows/' + BRANDID + '/001/-1?rand=2.0.0000' | |
| 19 | VIDEOLIST = 'http://abc.go.com/vp2/ws/s/contents/2012/videos/' + BRANDID + '/001/' | |
| 20 | CLOSEDCAPTIONHOST = 'http://cdn.video.abc.com' | |
| 21 | ||
| 22 | def masterlist(): | |
| 23 | return rootlist(db=True) | |
| 24 | ||
| 25 | def rootlist(db=False): | |
| 26 | root_data = common.getURL(SHOWLIST) | |
| 27 | root_tree = BeautifulStoneSoup(root_data, convertEntities=BeautifulStoneSoup.XML_ENTITIES) | |
| 28 | - | root_tree = BeautifulStoneSoup(root_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) |
| 28 | + | |
| 29 | db_shows = [] | |
| 30 | for root_item in root_menu: | |
| 31 | root_name = root_item('title')[0].string
| |
| 32 | season_id = root_item['id'] | |
| 33 | if db == True: | |
| 34 | db_shows.append(root_name, SITE,'seasons',season_id) | |
| 35 | else: | |
| 36 | common.addShow(root_name, SITE,'seasons',season_id) | |
| 37 | if db == True: | |
| 38 | return db_shows | |
| 39 | else: | |
| 40 | common.setView('tvshows')
| |
| 41 | ||
| 42 | def seasons(url=common.args.url): | |
| 43 | show_id = url | |
| 44 | show_url = VIDEOLIST + 'lf/' + show_id + '/-1/-1/-1/-1?rand=2.0.0000' | |
| 45 | show_data = common.getURL(show_url) | |
| 46 | show_menu = sorted(set(re.findall(r'<season id\=\"(.+?)\"',show_data))) | |
| 47 | for show_item in show_menu: | |
| 48 | show_name = 'Season ' + show_item | |
| 49 | show_url = VIDEOLIST + 'lf/' + show_id + '/' + show_item + '/-1/-1/-1?rand=2.0.0000' | |
| 50 | common.addDirectory(show_name, SITE, 'episodes', show_url) | |
| 51 | clip_id = url | |
| 52 | clip_url = VIDEOLIST + 'sf/' + show_id + '/-1/-1/-1/-1?rand=2.0.0000' | |
| 53 | clip_data = common.getURL(clip_url) | |
| 54 | clip_menu = sorted(set(re.findall(r'<season id\=\"(.+?)\"',clip_data))) | |
| 55 | for clip_item in clip_menu: | |
| 56 | clip_name = 'Clips Season ' + clip_item | |
| 57 | clip_url = VIDEOLIST + 'sf/' + clip_id + '/' + clip_item + '/-1/-1/-1?rand=2.0.0000' | |
| 58 | common.addDirectory(clip_name, SITE, 'episodes', clip_url) | |
| 59 | common.setView('seasons')
| |
| 60 | ||
| 61 | def episodes(url=common.args.url): | |
| 62 | episode_data = common.getURL(url) | |
| 63 | episode_tree = BeautifulStoneSoup(episode_data, convertEntities=BeautifulStoneSoup.XML_ENTITIES) | |
| 64 | - | episode_tree = BeautifulStoneSoup(episode_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) |
| 64 | + | |
| 65 | for episode_item in episode_menu: | |
| 66 | episode_name = episode_item('title')[1].string
| |
| 67 | try: | |
| 68 | episode_thumb = episode_item('thumbnails')[1]('thumbnail')[1].string
| |
| 69 | except: | |
| 70 | try: | |
| 71 | episode_thumb = episode_item('thumbnails')[1]('thumbnail')[0].string
| |
| 72 | except: | |
| 73 | episode_thumb = episode_item('thumbnail')[0].string
| |
| 74 | if (episode_item('asset')[0]['format'] == 'MOV'):
| |
| 75 | sitemode = 'playVideoMOV' | |
| 76 | elif (episode_item('asset')[0]['format'] == 'MP4'):
| |
| 77 | sitemode = 'playVideoMP4' | |
| 78 | else: | |
| 79 | sitemode = 'playVideoULNK' | |
| 80 | - | sitemode = 'playVideoUPL' |
| 80 | + | url = episode_item['id'].replace('VDKA', '')
|
| 81 | - | url = episode_item['id'] |
| 81 | + | |
| 82 | description = episode_item('longdescription')[0].string
| |
| 83 | except: | |
| 84 | description = episode_item('description')[0].string
| |
| 85 | try: | |
| 86 | closedcaption = episode_item('closedcaption')[0]('src')[0].string
| |
| 87 | closedcaption = CLOSEDCAPTIONHOST + closedcaption.split('.com')[1]
| |
| 88 | except: | |
| 89 | closedcaption = 'false' | |
| 90 | episode_airDate = re.sub(r" P(.)T","",episode_item('airdate')[0].string)
| |
| 91 | - | u += '?url="' + urllib.quote_plus(url) + '"' |
| 91 | + | |
| 92 | episode_number = episode_item('number')[0].string
| |
| 93 | season_number = episode_item('season')[0]['id']
| |
| 94 | u = sys.argv[0] | |
| 95 | u += '?url="' + url + '#' + closedcaption + '"' | |
| 96 | u += '&mode="' + SITE + '"' | |
| 97 | u += '&sitemode="' + sitemode + '"' | |
| 98 | infoLabels={ "Title":episode_name,
| |
| 99 | "Plot":description, | |
| 100 | "premiered":common.formatDate(episode_airDate,'%a, %d %b %Y %H:%M:%S','%d.%m.%Y'), | |
| 101 | "Duration":episode_duration, | |
| 102 | "Episode":episode_number, | |
| 103 | "Season":season_number | |
| 104 | } | |
| 105 | - | video_id = url.replace('VDKA', '')
|
| 105 | + | |
| 106 | common.setView('episodes')
| |
| 107 | ||
| 108 | def playVideoMOV(url=common.args.url): | |
| 109 | video_id = url.split('#')[0]
| |
| 110 | - | video_tree = BeautifulStoneSoup(video_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) |
| 110 | + | closedcaption = url.split('#')[1]
|
| 111 | if (common.settings['enablesubtitles'] == 'true'): | |
| 112 | if (closedcaption != 'false'): | |
| 113 | convert_subtitles(closedcaption) | |
| 114 | hbitrate = -1 | |
| 115 | sbitrate = int(common.settings['quality']) | |
| 116 | video_url = 'http://www.kaltura.com/p/' + PARTNERID + '/sp/' + PARTNERID + '00/playManifest/format/rtmp/entryId/' + video_id | |
| 117 | video_data = common.getURL(video_url) | |
| 118 | video_tree = BeautifulStoneSoup(video_data, convertEntities=BeautifulStoneSoup.XML_ENTITIES) | |
| 119 | base_url = video_tree('baseurl')[0].string
| |
| 120 | video_url2 = video_tree.findAll('media')
| |
| 121 | for video_index in video_url2: | |
| 122 | bitrate = int(video_index['bitrate']) | |
| 123 | - | video_id = url.replace('VDKA', '')
|
| 123 | + | |
| 124 | hbitrate = bitrate | |
| 125 | playpath_url = video_index['url'] | |
| 126 | swf_url = 'http://livepassdl.conviva.com/ver/2.61.0.65970/LivePassModuleMain.swf' | |
| 127 | finalurl = base_url + ' playpath=' + playpath_url + ' swfUrl=' + swf_url + ' swfVfy=true' | |
| 128 | xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path = finalurl)) | |
| 129 | if (common.settings['enablesubtitles'] == 'true') and (closedcaption != 'false'): | |
| 130 | while not xbmc.Player().isPlaying(): | |
| 131 | xbmc.sleep(100) | |
| 132 | subtitles = os.path.join(common.pluginpath,'resources','cache','subtitle.srt') | |
| 133 | xbmc.Player().setSubtitles(subtitles) | |
| 134 | ||
| 135 | def playVideoMP4(url=common.args.url): | |
| 136 | - | def playVideoUPL(url=common.args.url): |
| 136 | + | video_id = url.split('#')[0]
|
| 137 | - | video_id = url.replace('VDKA', '')
|
| 137 | + | closedcaption = url.split('#')[1]
|
| 138 | if (common.settings['enablesubtitles'] == 'true'): | |
| 139 | if (closedcaption != 'false'): | |
| 140 | convert_subtitles(closedcaption) | |
| 141 | hbitrate = -1 | |
| 142 | - | video_tree = BeautifulStoneSoup(video_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) |
| 142 | + | |
| 143 | video_url = 'http://www.kaltura.com/p/' + PARTNERID + '/sp/' + PARTNERID + '00/playManifest/format/applehttp/entryId/' + video_id | |
| 144 | video_data = common.getURL(video_url) | |
| 145 | video_url2 = m3u8.parse(video_data) | |
| 146 | for video_index in video_url2.get('playlists'):
| |
| 147 | bitrate = int(video_index.get('stream_info')['bandwidth'])
| |
| 148 | if bitrate > hbitrate and bitrate <= (sbitrate * 1000): | |
| 149 | hbitrate = bitrate | |
| 150 | finalurl = video_index.get('uri')
| |
| 151 | - | xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path=finalurl)) |
| 151 | + | |
| 152 | if (common.settings['enablesubtitles'] == 'true') and (closedcaption != 'false'): | |
| 153 | while not xbmc.Player().isPlaying(): | |
| 154 | xbmc.sleep(100) | |
| 155 | subtitles = os.path.join(common.pluginpath,'resources','cache','subtitle.srt') | |
| 156 | xbmc.Player().setSubtitles(subtitles) | |
| 157 | ||
| 158 | def playVideoULNK(url=common.args.url): | |
| 159 | video_id = url.split('#')[0]
| |
| 160 | closedcaption = url.split('#')[1]
| |
| 161 | if (common.settings['enablesubtitles'] == 'true'): | |
| 162 | if (closedcaption != 'false'): | |
| 163 | convert_subtitles(closedcaption) | |
| 164 | hbitrate = -1 | |
| 165 | sbitrate = int(common.settings['quality']) | |
| 166 | video_url = 'http://www.kaltura.com/p/' + PARTNERID + '/sp/' + PARTNERID + '00/playManifest/format/http/entryId/' + video_id + '/a.f4m?playbackContext=brand%3D' + BRANDID + '%26device%3D001' | |
| 167 | video_data = common.getURL(video_url) | |
| 168 | video_tree = BeautifulStoneSoup(video_data, convertEntities=BeautifulStoneSoup.XML_ENTITIES) | |
| 169 | video_url2 = video_tree.find('media')['url']
| |
| 170 | video_data2 = common.getURL(video_url2) | |
| 171 | video_url3 = m3u8.parse(video_data2) | |
| 172 | for video_index in video_url3.get('playlists'):
| |
| 173 | bitrate = int(video_index.get('stream_info')['bandwidth'])
| |
| 174 | if bitrate > hbitrate and bitrate <= (sbitrate * 1000): | |
| 175 | hbitrate = bitrate | |
| 176 | video_url4 = video_index.get('uri')
| |
| 177 | video_data3 = re.sub(r"\#EXT-X-DISCONTINUITY\n","",common.getURL(video_url4)) | |
| 178 | file = open(os.path.join(common.pluginpath,'resources','cache','play.m3u8'), 'w') | |
| 179 | file.write(video_data3) | |
| 180 | file.close() | |
| 181 | finalurl = os.path.join(common.pluginpath,'resources','cache','play.m3u8') | |
| 182 | xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path=finalurl)) | |
| 183 | if (common.settings['enablesubtitles'] == 'true') and (closedcaption != 'false'): | |
| 184 | while not xbmc.Player().isPlaying(): | |
| 185 | xbmc.sleep(100) | |
| 186 | subtitles = os.path.join(common.pluginpath,'resources','cache','subtitle.srt') | |
| 187 | xbmc.Player().setSubtitles(subtitles) | |
| 188 | ||
| 189 | def clean_subs(data): | |
| 190 | br = re.compile(r'<br.*?>') | |
| 191 | br_2 = re.compile(r'\n') | |
| 192 | tag = re.compile(r'<.*?>') | |
| 193 | space = re.compile(r'\s\s\s+') | |
| 194 | sub = br.sub('\n', str(data))
| |
| 195 | sub = tag.sub(' ', sub)
| |
| 196 | sub = br_2.sub('<br/>', sub)
| |
| 197 | sub = space.sub(' ', sub)
| |
| 198 | return sub | |
| 199 | ||
| 200 | def convert_subtitles(xml_closedcaption): | |
| 201 | subtitle_array = [] | |
| 202 | srt_output = '' | |
| 203 | subtitle_data = common.getURL(xml_closedcaption) | |
| 204 | subtitle_data = BeautifulStoneSoup(subtitle_data, convertEntities=BeautifulStoneSoup.XML_ENTITIES) | |
| 205 | lines = subtitle_data.findAll('p')
| |
| 206 | for line in lines: | |
| 207 | if line is not None: | |
| 208 | sub = str(clean_subs(line)) | |
| 209 | try: | |
| 210 | newsub=sub | |
| 211 | sub = BeautifulStoneSoup(sub, convertEntities=BeautifulStoneSoup.ALL_ENTITIES) | |
| 212 | except: | |
| 213 | sub=newsub | |
| 214 | start_time_hours, start_time_rest = line['begin'].split(':',1)
| |
| 215 | start_time_hours = "%02d" % (int(start_time_hours) - 1) | |
| 216 | start_time = start_time_hours + ":" + start_time_rest.replace('.',',')
| |
| 217 | end_time_hours, end_time_rest = line['end'].split(':',1)
| |
| 218 | end_time_hours = "%02d" % (int(end_time_hours) - 1) | |
| 219 | end_time = end_time_hours + ":" + end_time_rest.replace('.',',')
| |
| 220 | temp_dict = {'start':start_time, 'end':end_time, 'text':sub}
| |
| 221 | subtitle_array.append(temp_dict) | |
| 222 | for i, subtitle in enumerate(subtitle_array): | |
| 223 | line = str(i+1)+"\n"+str(subtitle['start'])+" --> "+str(subtitle['end'])+"\n"+str(subtitle['text'])+"\n\n" | |
| 224 | srt_output += line | |
| 225 | file = open(os.path.join(common.pluginpath,'resources','cache','subtitle.srt'), 'w') | |
| 226 | file.write(srt_output) | |
| 227 | file.close() | |
| 228 | return True |