def read_favs(params): href = httpSiteUrl + "/myfavourites.aspx?ajax§ion=" + params['section'] \ + "&subsection=" + params['subsection'] \ + "&rows=1&curpage=" + params['page'] \ + "&action=get_list&setrows=1&page=" + params['type'] favorites = read_fav_data(urllib.unquote_plus(href)) if len(favorites) == 0: show_message('ОШИБКА', 'В избранном пусто', 3000) return False for item in favorites: additional = '' if item['season'] > 0: additional = ' (s%se%s)' % (item['season'], item['episode']) li = xbmcgui.ListItem( strutils.html_entities_decode(item['title']) + additional, iconImage=fs_ua.thumbnail(item['cover']), thumbnailImage=fs_ua.poster(item['cover']) ) li.setProperty('IsPlayable', 'false') id = item['href'].split('/')[-1] li.addContextMenuItems([ ( __language__(50003), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'favorites', 'id': id, 'title': item['title'] }) ), ( __language__(50004), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'playlist', 'id': id, 'title': item['title'] }) ) ]) uri = strutils.construct_request({ 'href': item['href'], 'referer': href, 'mode': 'read_dir', 'cover': item['cover'], 'folder': 0, 'isMusic': item['isMusic'] }) xbmcplugin.addDirectoryItem(h, uri, li, True) li = xbmcgui.ListItem('[NEXT PAGE >]') li.setProperty('IsPlayable', 'false') params['page'] = int(params['page']) + 1 uri = strutils.construct_request(params) xbmcplugin.addDirectoryItem(h, uri, li, True) xbmcplugin.endOfDirectory(h)
def read_favs(params): href = httpSiteUrl + "/myfavourites.aspx?ajax§ion=" + params['section'] \ + "&subsection=" + params['subsection'] \ + "&rows=1&curpage=" + params['page'] \ + "&action=get_list&setrows=1&page=" + params['type'] favorites = read_fav_data(urllib.unquote_plus(href)) if len(favorites) == 0: show_message('ОШИБКА', 'В избранном пусто', 3000) return False for item in favorites: additional = '' if item['season'] > 0: additional = ' (s%se%s)' % (item['season'], item['episode']) li = xbmcgui.ListItem(strutils.html_entities_decode(item['title']) + additional, iconImage=fs_ua.thumbnail(item['cover']), thumbnailImage=fs_ua.poster(item['cover'])) li.setProperty('IsPlayable', 'false') id = item['href'].split('/')[-1] li.addContextMenuItems([ (__language__(50003), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'favorites', 'id': id, 'title': item['title'] })), (__language__(50004), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'playlist', 'id': id, 'title': item['title'] })) ]) uri = strutils.construct_request({ 'href': item['href'], 'referer': href, 'mode': 'read_dir', 'cover': item['cover'], 'folder': 0, 'isMusic': item['isMusic'] }) xbmcplugin.addDirectoryItem(h, uri, li, True) li = xbmcgui.ListItem('[NEXT PAGE >]') li.setProperty('IsPlayable', 'false') params['page'] = int(params['page']) + 1 uri = strutils.construct_request(params) xbmcplugin.addDirectoryItem(h, uri, li, True) xbmcplugin.endOfDirectory(h)
def add_folder_file(item): title = item['title'] cover = item['cover'] href = item['href'] referer = item['referer'] item_type = item['type'] li = xbmcgui.ListItem( strutils.html_entities_decode(title), iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover), path=href ) li.setProperty('IsPlayable', 'true') li.setInfo(type=item_type, infoLabels={'title': title}) playCount = kodi.get_play_count(strutils.html_entities_decode(title)) if playCount: li.setInfo(type=item_type, infoLabels={'title': title, 'playcount': 1}) li.addContextMenuItems([ ( __language__(40001), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'download', 'file_url': str(href.encode('utf-8')), 'file_name': strutils.html_entities_decode(title) }) ) ]) if item_type == 'music' or (__settings__.getSetting('Autoplay next') == 'true'): uri = strutils.construct_request({ 'file': str(href.encode('utf-8')), 'referer': referer, 'mode': 'play', 'playLink': item['playLink'] }) else: uri = client.get_full_url(href) xbmcplugin.addDirectoryItem(h, uri, li, False)
def read_fav_data(favoritesUrl): favorites = [] http = client.GET(favoritesUrl, httpSiteUrl) if http is None: return favorites data = json.loads(str(http)) http = data['content'].encode('utf-8') beautifulSoup = BeautifulSoup(http) container = beautifulSoup.find('div', 'b-posters') if container is None: return favorites items = container.findAll('div', 'b-poster-thin__wrapper ') if len(items) == 0: return favorites cover_regexp = re.compile("url\s*\('([^']+)") episode_regexp = re.compile("s(\d+)e(\d+)") for wrapper in items: item = wrapper.find('a', 'b-poster-thin') season = 0 episode = 0 episode_data = episode_regexp.findall(str(wrapper)) if episode_data is not None and len(episode_data) > 0: season = episode_data[0][0] episode = episode_data[0][1] cover = cover_regexp.findall(str(item['style']))[0] title = str(item.find('b', 'subject-link').find('span').string) href = client.get_full_url(item['href']) isMusic = "no" if re.search('audio', href): isMusic = "yes" #get_material_details(href) favorites.append({ 'href': href, 'title': strutils.html_entities_decode(title), 'cover': cover, 'season': season, 'episode': episode, 'isMusic': isMusic }) return favorites
def add_folder_file(item): title = item['title'] cover = item['cover'] href = item['href'] referer = item['referer'] item_type = item['type'] li = xbmcgui.ListItem(strutils.html_entities_decode(title), iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover), path=href) li.setProperty('IsPlayable', 'true') li.setInfo(type=item_type, infoLabels={'title': title}) playCount = kodi.get_play_count(strutils.html_entities_decode(title)) if playCount: li.setInfo(type=item_type, infoLabels={'title': title, 'playcount': 1}) li.addContextMenuItems([ (__language__(40001), "XBMC.RunPlugin(%s)" % strutils.construct_request( { 'mode': 'download', 'file_url': str(href.encode('utf-8')), 'file_name': strutils.html_entities_decode(title) })) ]) if item_type == 'music' or (__settings__.getSetting('Autoplay next') == 'true'): uri = strutils.construct_request({ 'file': str(href.encode('utf-8')), 'referer': referer, 'mode': 'play', 'playLink': item['playLink'] }) else: uri = client.get_full_url(href) xbmcplugin.addDirectoryItem(h, uri, li, False)
def render_search_results(params): searchUrl = urllib.unquote_plus(params['href']) http = client.GET(searchUrl, httpSiteUrl) if http is None: return False beautifulSoup = BeautifulSoup(http) results = beautifulSoup.find('div', 'b-search-page__results') if results is None: show_message('ОШИБКА', 'Ничего не найдено', 3000) return False else: items = results.findAll('a','b-search-page__results-item') if len(items) == 0: show_message('ОШИБКА', 'Ничего не найдено', 3000) return False for item in items: title = str(item.find('span', 'b-search-page__results-item-title').text.encode('utf-8')) href = client.get_full_url(item['href']) cover = item.find('span', 'b-search-page__results-item-image').find('img')['src'] section = item.find('span', 'b-search-page__results-item-subsection').text if title is not None: li = xbmcgui.ListItem('[%s] %s' % (strutils.html_entities_decode(section), strutils.html_entities_decode(title)), iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover)) li.setProperty('IsPlayable', 'false') id = item['href'].split('/')[-1] li.addContextMenuItems([ ( __language__(50001), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'favorites', 'id': id }) ), ( __language__(50002), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'playlist', 'id': id }) ) ]) isMusic = 'no' if params['section'] == 'audio': isMusic = 'yes' uri = strutils.construct_request({ 'href': href, 'referer': searchUrl, 'mode': 'read_dir', 'cover': cover, 'folder': 0, 'isMusic': isMusic }) xbmcplugin.addDirectoryItem(h, uri, li, True) xbmcplugin.endOfDirectory(h)
def add_directory_item(linkItem, isFolder, playLink, playLinkClass, cover, folderUrl, folder, isMusic, quality = None, itemsCount = None): lang = None langRegexp = re.compile('\s*m\-(\w+)\s*') lang_data = langRegexp.findall(linkItem['class']) if len(lang_data) > 0: lang = str(lang_data[0]) title = "" if isFolder: title = strutils.fix_string(linkItem.text) if (itemsCount): title = "%s (%s)" % (title, strutils.fix_string(itemsCount.text)) lang_quality_el = linkItem.find('font') if lang_quality_el: lang_quality = strutils.fix_string(lang_quality_el.text) title = title.replace(lang_quality, ' ' + lang_quality) if quality is not None: title = "%s [%s]" % (title, quality) else: try: title = str(playLink.find('span', playLinkClass + '-filename-text').string) except: pass if lang is not None: title = lang.upper() + ' - ' + title if playLink is not None and playLink.name == 'a': if 'href' in playLink: playLink = client.get_full_url(str(playLink['href'])) elif 'rel' in playLink: playLink = client.get_full_url(str(playLink['rel'])) else: playLink = '' else: playLink = '' href = linkItem['href'] try: folderRegexp = re.compile("parent_id:\s*'([^']+)") folder = folderRegexp.findall(linkItem['rel'])[0] except: pass if isFolder: li = xbmcgui.ListItem( strutils.html_entities_decode(title), iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover) ) li.setProperty('IsPlayable', 'false') uri = strutils.construct_request({ 'cover': cover, 'href': folderUrl, 'referer': folderUrl, 'mode': 'read_dir', 'folder': folder, 'isMusic': isMusic, 'quality': quality }) xbmcplugin.addDirectoryItem(h, uri, li, isFolder) else: item_type = 'video' if isMusic == 'yes': item_type = 'music' add_folder_file({ 'title': title, 'cover': cover, 'href': href, 'referer': folderUrl, 'type': item_type, 'playLink': playLink })
def readcategory(params): start = int(params['start']) category_href = urllib.unquote_plus(params['href']) categoryUrl = category_href if 'disableFilters' not in params: categoryUrl = fs_ua.get_url_with_sort_by( category_href, params['section'], params['start'], 'detailed' ) http = client.GET(categoryUrl, httpSiteUrl) if http is None: return False try: params['filter'] except: params['filter'] = '' beautifulSoup = BeautifulSoup(http) itemsClass = 'b-poster-detail' items = beautifulSoup.findAll('div', itemsClass) if len(items) == 0: show_message('ОШИБКА', 'Неверная страница', 3000) return False else: if start == 0 and 'hideFirstPageData' not in params: load_first_page_sections(category_href, params) for item in items: cover = None href = None img = item.find('img') link = item.find('a', itemsClass + '__link') title = item.find('span', 'b-poster-detail__title').contents[0] if img is not None: cover = img['src'] href = client.get_full_url(link['href']) if title is not None: plot = [] details = item.find('span', 'b-poster-detail__description').contents for detail in details: try: plot.append(detail.encode('utf8')) except: pass titleText = strutils.html_entities_decode(title.encode('utf8')) li = xbmcgui.ListItem(titleText, iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover)) if plot != '': li.setInfo(type=params['section'], infoLabels={'title': titleText, 'plot': plot}) li.setProperty('IsPlayable', 'false') id = str(link['href'].split('/')[-1]) li.addContextMenuItems([ ( __language__(50001), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'favorites', 'id': id }) ), ( __language__(50002), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'playlist', 'id': id }) ) ]) isMusic = 'no' if params['section'] == 'audio': isMusic = 'yes' uri = strutils.construct_request({ 'href': href, 'referer': categoryUrl, 'mode': 'read_dir', 'cover': cover, 'folder': 0, 'isMusic': isMusic }) xbmcplugin.addDirectoryItem(h, uri, li, True) li = xbmcgui.ListItem('[NEXT PAGE >]') li.setProperty('IsPlayable', 'false') uri = strutils.construct_request({ 'href': category_href, 'mode': 'readcategory', 'section': params['section'], 'filter': params['filter'], 'start': start + 1, 'firstPage': 'no' }) xbmcplugin.addDirectoryItem(h, uri, li, True) xbmcplugin.endOfDirectory(h)
def get_material_details(url): data = {} cache_file_name = '%s.json' % hashlib.md5(url).hexdigest() cache_file_path = os.path.join(cache_path, cache_file_name) if xbmcvfs.exists(cache_file_path): fp = open(cache_file_path, 'r') data = json.load(fp) fp.close() return data http = client.GET(url, httpSiteUrl) if http is None: return data cover_regexp = re.compile("url\s*\(([^\)]+)") beautifulSoup = BeautifulSoup(http) info = beautifulSoup.find('div', 'item-info') genre_element_container = info.findAll('span', {"itemprop" : "genre"}) genres = [] for genre_element in genre_element_container: genres.append(strutils.fix_string(genre_element.find('span').string.strip())) title = strutils.fix_string(beautifulSoup.find('div', 'b-tab-item__title-inner').find('span').string) original_title = strutils.html_entities_decode(beautifulSoup.find('div', 'b-tab-item__title-origin').string) description = beautifulSoup.find('p', 'item-decription').string.encode('utf-8') poster = fs_ua.poster(client.get_full_url(beautifulSoup.find('div', 'poster-main').find('img')['src'])) print poster images_container = beautifulSoup.find('div', 'b-tab-item__screens') image_elements = images_container.findAll('a') images = [] for image_element in image_elements: images.append( client.get_full_url( fs_ua.poster( cover_regexp.findall(str(image_element['style']).strip())[0] ) ) ) rating_positive = beautifulSoup.find('div', 'm-tab-item__vote-value_type_yes').string.strip() rating_negative = beautifulSoup.find('div', 'm-tab-item__vote-value_type_no').string.strip() data = { 'title': title.strip(), 'original_title': original_title.strip(), 'poster': poster, 'description': description, 'images': images, 'genres': genres, 'rating_positive': rating_positive, 'rating_negative': rating_negative } fp = open(cache_file_path, 'w') json.dump(data, fp) fp.close() return data
def render_search_results(params): searchUrl = urllib.unquote_plus(params['href']) http = client.GET(searchUrl, httpSiteUrl) if http is None: return False beautifulSoup = BeautifulSoup(http) results = beautifulSoup.find('div', 'b-search-page__results') if results is None: show_message('ОШИБКА', 'Ничего не найдено', 3000) return False else: items = results.findAll('a', 'b-search-page__results-item') if len(items) == 0: show_message('ОШИБКА', 'Ничего не найдено', 3000) return False for item in items: title = str( item.find( 'span', 'b-search-page__results-item-title').text.encode('utf-8')) href = client.get_full_url(item['href']) cover = item.find( 'span', 'b-search-page__results-item-image').find('img')['src'] section = item.find('span', 'b-search-page__results-item-subsection').text if title is not None: li = xbmcgui.ListItem('[%s] %s' % (strutils.html_entities_decode(section), strutils.html_entities_decode(title)), iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover)) li.setProperty('IsPlayable', 'false') id = item['href'].split('/')[-1] li.addContextMenuItems([ (__language__(50001), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'favorites', 'id': id })), (__language__(50002), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'playlist', 'id': id })) ]) isMusic = 'no' if params['section'] == 'audio': isMusic = 'yes' uri = strutils.construct_request({ 'href': href, 'referer': searchUrl, 'mode': 'read_dir', 'cover': cover, 'folder': 0, 'isMusic': isMusic }) xbmcplugin.addDirectoryItem(h, uri, li, True) xbmcplugin.endOfDirectory(h)
def add_directory_item(linkItem, isFolder, playLink, playLinkClass, cover, folderUrl, folder, isMusic, quality=None, itemsCount=None): folderRegexp = re.compile('(\d+)') lang = None langRegexp = re.compile('\s*m\-(\w+)\s*') lang_data = langRegexp.findall(linkItem['class']) if len(lang_data) > 0: lang = str(lang_data[0]) title = "" if isFolder: title = strutils.fix_string(linkItem.text) if (itemsCount): title = "%s (%s)" % (title, strutils.fix_string(itemsCount.text)) lang_quality_el = linkItem.find('font') if lang_quality_el: lang_quality = strutils.fix_string(lang_quality_el.text) title = title.replace(lang_quality, ' ' + lang_quality) if quality is not None: title = "%s [%s]" % (title, quality) else: try: title = str( playLink.find('span', playLinkClass + '-filename-text').string) except: pass if lang is not None: title = lang.upper() + ' - ' + title if playLink is not None and playLink.name == 'a': if 'href' in playLink: playLink = client.get_full_url(str(playLink['href'])) elif 'rel' in playLink: playLink = client.get_full_url(str(playLink['rel'])) else: playLink = '' else: playLink = '' href = linkItem['href'] try: folder = folderRegexp.findall(linkItem['rel'])[0] except: pass if isFolder: li = xbmcgui.ListItem(strutils.html_entities_decode(title), iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover)) li.setProperty('IsPlayable', 'false') uri = strutils.construct_request({ 'cover': cover, 'href': folderUrl, 'referer': folderUrl, 'mode': 'read_dir', 'folder': folder, 'isMusic': isMusic, 'quality': quality }) xbmcplugin.addDirectoryItem(h, uri, li, isFolder) else: item_type = 'video' if isMusic == 'yes': item_type = 'music' add_folder_file({ 'title': title, 'cover': cover, 'href': href, 'referer': folderUrl, 'type': item_type, 'playLink': playLink })
def readcategory(params): start = int(params['start']) category_href = urllib.unquote_plus(params['href']) categoryUrl = fs_ua.get_url_with_sort_by(category_href, params['section'], params['start'], 'detailed') http = client.GET(categoryUrl, httpSiteUrl) if http is None: return False try: params['filter'] except: params['filter'] = '' beautifulSoup = BeautifulSoup(http) itemsClass = 'b-poster-detail' items = beautifulSoup.findAll('div', itemsClass) if len(items) == 0: show_message('ОШИБКА', 'Неверная страница', 3000) return False else: if start == 0 and 'hideFirstPageData' not in params: load_first_page_sections(category_href, params) for item in items: cover = None href = None img = item.find('img') link = item.find('a', itemsClass + '__link') title = item.find('span', 'b-poster-detail__title').contents[0] if img is not None: cover = img['src'] href = client.get_full_url(link['href']) if title is not None: plot = [] details = item.find('span', 'b-poster-detail__description').contents for detail in details: try: plot.append(detail.encode('utf8')) except: pass titleText = strutils.html_entities_decode(title.encode('utf8')) li = xbmcgui.ListItem(titleText, iconImage=fs_ua.thumbnail(cover), thumbnailImage=fs_ua.poster(cover)) if plot != '': li.setInfo(type=params['section'], infoLabels={ 'title': titleText, 'plot': plot }) li.setProperty('IsPlayable', 'false') id = str(link['href'].split('/')[-1]) li.addContextMenuItems([ (__language__(50001), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'favorites', 'id': id })), (__language__(50002), "XBMC.RunPlugin(%s)" % strutils.construct_request({ 'mode': 'addto', 'section': 'playlist', 'id': id })) ]) isMusic = 'no' if params['section'] == 'audio': isMusic = 'yes' uri = strutils.construct_request({ 'href': href, 'referer': categoryUrl, 'mode': 'read_dir', 'cover': cover, 'folder': 0, 'isMusic': isMusic }) xbmcplugin.addDirectoryItem(h, uri, li, True) li = xbmcgui.ListItem('[NEXT PAGE >]') li.setProperty('IsPlayable', 'false') uri = strutils.construct_request({ 'href': category_href, 'mode': 'readcategory', 'section': params['section'], 'filter': params['filter'], 'start': start + 1, 'firstPage': 'no' }) xbmcplugin.addDirectoryItem(h, uri, li, True) xbmcplugin.endOfDirectory(h)
def get_material_details(url): data = {} cache_file_name = '%s.json' % hashlib.md5(url).hexdigest() cache_file_path = os.path.join(cache_path, cache_file_name) if xbmcvfs.exists(cache_file_path): fp = open(cache_file_path, 'r') data = json.load(fp) fp.close() return data http = client.GET(url, httpSiteUrl) if http is None: return data cover_regexp = re.compile("url\s*\(([^\)]+)") beautifulSoup = BeautifulSoup(http) info = beautifulSoup.find('div', 'item-info') genre_element_container = info.findAll('span', {"itemprop": "genre"}) genres = [] for genre_element in genre_element_container: genres.append( strutils.fix_string(genre_element.find('span').string.strip())) title = strutils.fix_string( beautifulSoup.find('div', 'b-tab-item__title-inner').find('span').string) original_title = strutils.html_entities_decode( beautifulSoup.find('div', 'b-tab-item__title-origin').string) description = beautifulSoup.find('p', 'item-decription').string.encode('utf-8') poster = fs_ua.poster( client.get_full_url( beautifulSoup.find('div', 'poster-main').find('img')['src'])) print poster images_container = beautifulSoup.find('div', 'b-tab-item__screens') image_elements = images_container.findAll('a') images = [] for image_element in image_elements: images.append( client.get_full_url( fs_ua.poster( cover_regexp.findall(str( image_element['style']).strip())[0]))) rating_positive = beautifulSoup.find( 'div', 'm-tab-item__vote-value_type_yes').string.strip() rating_negative = beautifulSoup.find( 'div', 'm-tab-item__vote-value_type_no').string.strip() data = { 'title': title.strip(), 'original_title': original_title.strip(), 'poster': poster, 'description': description, 'images': images, 'genres': genres, 'rating_positive': rating_positive, 'rating_negative': rating_negative } fp = open(cache_file_path, 'w') json.dump(data, fp) fp.close() return data