def model_params(model_filename): '''Converts the given model_filename (or absolute path) into a dict of key -> tuple of **strings** (single values parameters will be mapped to a 1-element tuple) ''' pth = basename(model_filename) pth_, ext = splitext(pth) if ext == '.sklmodel': pth = pth_ pars = pth.split('&') ret = odict() for par in pars: key, val = par.split('=') ret[uq(key)] = tuple(uq(_) for _ in val.split(',')) return ret
def unquote(x, encoding='utf-8', errors='replace'): binary = isinstance(x, bytes) if binary: x = x.decode(encoding, errors) ans = uq(x, encoding, errors) if binary: ans = ans.encode(encoding, errors) return ans
def unquote(x, encoding='utf-8', errors='replace'): # unquote must run on a bytestring and will return a bytestring # If it runs on a unicode object, it returns a double encoded unicode # string: unquote(u'%C3%A4') != unquote(b'%C3%A4').decode('utf-8') # and the latter is correct binary = isinstance(x, bytes) if not binary: x = x.encode(encoding, errors) ans = uq(x) if not binary: ans = ans.decode(encoding, errors) return ans
def manualSelect(args): args = uq(args) header, episode_link, handle_ = args.split('|') handle_ = int(handle_) raw_html = sh.getHTML(episode_link) dirty_links = sh.getDirtyEpisodeLinks(raw_html[0], type_='all') #hostings = ('sibnet.ru', 'smotret-anime.ru', 'vk.com', \ # 'sovetromantica.com') pr_hosts = data.PriorityDataList hostings = [hosting[1] for hosting in pr_hosts._hostings] print('HOSTINGS IS', hostings) rel_vid_by_hostings = [] for link in dirty_links: if link['hosting'] in hostings: rel_vid_by_hostings.append(link) f = lambda x: u'({}){}({})'.format(x['type'], x['author'], x['hosting']) video_headers = [f(i) for i in rel_vid_by_hostings] video_items = [] for video in video_headers: item = xbmcgui.ListItem(label=video) item.setProperty('IsPlayeble', 'true') video_items.append(item) dialog = xbmcgui.Dialog() ret = dialog.select(header, video_items) selected = rel_vid_by_hostings[ret] direct_link = sh.getDirectEpisodeLink(selected['dirty_link'], \ selected['hosting']) if direct_link: video, ass = direct_link to_play = video_items[ret] if ass: to_play.setSubtitles([ass]) if video: to_play.setPath(path=video) else: alert('Что-то пошло не так', 'Невозможно воспроизвести это видео') return None else: alert('Что-то пошло не так', 'Невозможно воспроизвести это видео') return None xbmc.Player().play(video, listitem=to_play) if re.search(r'127\.0\.0\.1', video): xbmcgui.Dialog().notification('Перемотка не работает', \ 'Перемотка для этого видео не работает. См. xbmc.ru', \ xbmcgui.NOTIFICATION_INFO, 5000)
def get_url_from_ad_link(self, product_url) -> str: url = product_url[product_url.rindex("https")::] return uq(url)
def do_GET(self): # отправка видео по запросу из плейлиста if re.match('.*p\d+\.ts', self.path): print('REQUEST', self.path) idx = int(re.match('.*p(\d).ts', self.path).groups()[0]) self.send_response(200, 'OK') self.send_header('content-type', 'video/vnd.dlna.mpeg-tts') self.end_headers() parts = PartsHandler.parts popen = PartsHandler.popen if parts[idx]['hosting'] == 'google': # через ffmpeg кусок скачивается и преобразуется в .ts popen = subprocess.Popen(parts[idx]['cmd'], stdout=subprocess.PIPE) # выхлоп отправляется напрямую по запросу while True: line = popen.stdout.readline() if line: try: self.wfile.write(line) except Exception as e: print('EXCEPTION: ', e) popen.stdout.close() popen.kill() else: popen.stdout.close() popen.kill() print('ffmpeg killed') break elif parts[idx]['hosting'] == 'big-sword': # из-за особенностей сервера big-sword качать пришлось # отдельно, pipe'ить в ffmpeg, а оттуда уже отправлять # код с дополнительным процессом ниже необходим, т.к. # баг в Popen под windows ffmpeg = subprocess.Popen(parts[idx]['cmd'], \ stdin=subprocess.PIPE, stdout=subprocess.PIPE) stop_event = Event() gvp = Process(target=self.get_video, args=(ffmpeg, parts[idx]['url'], stop_event)) gvp.start() while True: line = ffmpeg.stdout.readline() if line: try: self.wfile.write(line) except Exception as e: print('Exception occured when sending ffmpeg ' \ 'output:\n', e) break else: break ffmpeg.stdout.close() ffmpeg.kill() stop_event.set() gvp.join() # генерация и отправка плейлистов, при получении # в запросе elif re.search(r'playlist\.m3u8', self.path): if re.search(r'http://lh3.googleusercontent', self.path): hosting = 'google' elif re.search(r'\.big-sword', self.path): hosting = 'big-sword' else: return print('PLAYLIST REQUEST:', self.path) paths = uq(self.path) self.urls = paths.lstrip('/playlist.m3u8?').split(' ') PartsHandler.parts = get_video_info(self.urls, hosting) playlist = build_playlist(PartsHandler.parts) self.send_response(200, 'OK') self.send_header('Content-Length', len(playlist)) self.send_header('Content-Type', 'application/vnd.apple.mpegurl') self.end_headers() self.wfile.write(playlist.encode())