def retrieveVideoLinks(request_obj, response_obj): video_source_id = 1 video_source_img = None video_source_name = None video_part_index = 0 video_playlist_items = [] ignoreAllLinks = False content = BeautifulSoup.SoupStrainer('blockquote', {'class':re.compile(r'\bpostcontent\b')}) soup = HttpClient().getBeautifulSoup(url=request_obj.get_data()['episodeUrl'], parseOnlyThese=content) for e in soup.findAll('br'): e.extract() Logger.logDebug(soup) if soup.has_key('div'): soup = soup.findChild('div', recursive=False) prevChild = '' prevAFont = None for child in soup.findChildren(): if (child.name == 'img' or child.name == 'b' or (child.name == 'font' and not child.findChild('a'))): if (child.name == 'b' and prevChild == 'a') or (child.name == 'font' and child == prevAFont): continue else: if len(video_playlist_items) > 0: response_obj.addListItem(__preparePlayListItem__(video_source_id, video_source_img, video_source_name, video_playlist_items)) if video_source_img is not None: video_source_id = video_source_id + 1 video_source_img = None video_source_name = None video_part_index = 0 video_playlist_items = [] ignoreAllLinks = False elif not ignoreAllLinks and child.name == 'a' and not re.search('multi', str(child['href']), re.IGNORECASE): video_part_index = video_part_index + 1 video_link = {} video_link['videoTitle'] = 'Source #' + str(video_source_id) + ' | ' + 'Part #' + str(video_part_index) + ' | ' + child.getText() video_link['videoLink'] = str(child['href']) try: try: __prepareVideoLink__(video_link) except Exception, e: Logger.logFatal(e) video_hosting_info = SnapVideo.findVideoHostingInfo(video_link['videoLink']) if video_hosting_info is None or video_hosting_info.get_video_hosting_name() == 'UrlResolver by t0mm0': raise video_link['videoSourceImg'] = video_hosting_info.get_video_hosting_image() video_link['videoSourceName'] = video_hosting_info.get_video_hosting_name() video_playlist_items.append(video_link) video_source_img = video_link['videoSourceImg'] video_source_name = video_link['videoSourceName'] item = ListItem() item.add_request_data('videoLink', video_link['videoLink']) item.add_request_data('videoTitle', video_link['videoTitle']) item.set_next_action_name('SnapAndPlayVideo') xbmcListItem = xbmcgui.ListItem(label='Source #' + str(video_source_id) + ' | ' + 'Part #' + str(video_part_index) , iconImage=video_source_img, thumbnailImage=video_source_img) item.set_xbmc_list_item_obj(xbmcListItem) response_obj.addListItem(item) prevAFont = child.findChild('font') except:
def retrieveVideoLinks(request_obj, response_obj): video_source_id = 1 video_source_img = None video_part_index = 0 video_playlist_items = [] ignoreAllLinks = False content = BeautifulSoup.SoupStrainer('blockquote', {'class':re.compile(r'\bpostcontent\b')}) soup = HttpClient().getBeautifulSoup(url=request_obj.get_data()['episodeUrl'], parseOnlyThese=content) if soup.has_key('div'): soup = soup.findChild('div', recursive=False) prevChild = '' for child in soup.findChildren(): if child.name == 'img' or child.name == 'font'or child.name == 'b' : if child.name == 'b' and prevChild == 'a': continue else: if len(video_playlist_items) > 0: response_obj.addListItem(__preparePlayListItem__(video_source_id, video_source_img, video_playlist_items)) if video_source_img is not None: video_source_id = video_source_id + 1 video_source_img = None video_part_index = 0 video_playlist_items = [] ignoreAllLinks = False elif not ignoreAllLinks and child.name == 'a' and not re.search('multi', str(child['href']), re.IGNORECASE): video_part_index = video_part_index + 1 video_link = {} video_link['videoTitle'] = 'Source #' + str(video_source_id) + ' | ' + 'Part #' + str(video_part_index) + ' | ' + child.getText() video_link['videoLink'] = str(child['href']) try: __prepareVideoLink__(video_link) video_playlist_items.append(video_link) video_source_img = video_link['videoSourceImg'] item = ListItem() item.add_request_data('videoLink', video_link['videoLink']) item.add_request_data('videoTitle', video_link['videoTitle']) item.set_next_action_name('SnapAndPlayVideo') xbmcListItem = xbmcgui.ListItem(label='Source #' + str(video_source_id) + ' | ' + 'Part #' + str(video_part_index) , iconImage=video_source_img, thumbnailImage=video_source_img) item.set_xbmc_list_item_obj(xbmcListItem) response_obj.addListItem(item) except: print 'Unable to recognize a source = ' + video_link['videoLink'] video_source_img = None video_part_index = 0 video_playlist_items = [] ignoreAllLinks = True prevChild = child.name if len(video_playlist_items) > 0: response_obj.addListItem(__preparePlayListItem__(video_source_id, video_source_img, video_playlist_items))