def ffmpeg_file_info(file): """Get information on the file: - number of streams - duration - artist - album - date - track :rtype: FileInfo :return: The file info instance containing all the meta information. """ info = FileInfo() info.n_streams = file.context.contents.nb_streams info.start_time = file.context.contents.start_time info.duration = file.context.contents.duration entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('title'), None, 0) if entry: info.title = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('artist'), None, 0) \ or \ avutil.av_dict_get(file.context.contents.metadata, asbytes('album_artist'), None, 0) if entry: info.author = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('copyright'), None, 0) if entry: info.copyright = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('comment'), None, 0) if entry: info.comment = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('album'), None, 0) if entry: info.album = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('date'), None, 0) if entry: info.year = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('track'), None, 0) if entry: info.track = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('genre'), None, 0) if entry: info.genre = asstr(entry.contents.value) return info
def _install_restore_mode_child(): global _mode_write_pipe global _restore_mode_child_installed if _restore_mode_child_installed: return # Parent communicates to child by sending "mode packets" through a pipe: mode_read_pipe, _mode_write_pipe = os.pipe() if os.fork() == 0: # Child process (watches for parent to die then restores video mode(s). os.close(_mode_write_pipe) # Set up SIGHUP to be the signal for when the parent dies. PR_SET_PDEATHSIG = 1 libc = ctypes.cdll.LoadLibrary('libc.so.6') libc.prctl.argtypes = (ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong) libc.prctl(PR_SET_PDEATHSIG, signal.SIGHUP, 0, 0, 0) # SIGHUP indicates the parent has died. The child lock is unlocked, it # stops reading from the mode packet pipe and restores video modes on # all displays/screens it knows about. def _sighup(signum, frame): parent_wait_lock.release() parent_wait_lock = threading.Lock() parent_wait_lock.acquire() signal.signal(signal.SIGHUP, _sighup) # Wait for parent to die and read packets from parent pipe packets = [] buffer = asbytes('') while parent_wait_lock.locked(): try: data = os.read(mode_read_pipe, ModePacket.size) buffer += data # Decode packets while len(buffer) >= ModePacket.size: packet = ModePacket.decode(buffer[:ModePacket.size]) packets.append(packet) buffer = buffer[ModePacket.size:] except OSError: pass # Interrupted system call for packet in packets: packet.set() os._exit(0) else: # Parent process. Clean up pipe then continue running program as # normal. Send mode packets through pipe as additional # displays/screens are mode switched. os.close(mode_read_pipe) _restore_mode_child_installed = True
def _set_string(self, name, value): assert self._pattern assert name assert self._fontconfig if not value: return value = value.encode('utf8') self._fontconfig.FcPatternAddString(self._pattern, name, asbytes(value))
def __call__(self, *args, **kwargs): from pyglet.gl import current_context if not current_context: raise Exception('Call to function "%s" before GL context created' % self.name) address = wglGetProcAddress(asbytes(self.name)) if cast(address, POINTER(c_int)): # check cast because address is func self.func = cast(address, self.ftype) decorate_function(self.func, self.name) else: self.func = missing_function(self.name, self.requires, self.suggestions) self.__class__ = makeWGLFunction(self.func) return self.func(*args, **kwargs)
def link_EGL(name, restype, argtypes, requires=None, suggestions=None): try: func = getattr(egl_lib, name) func.restype = restype func.argtypes = argtypes return func except AttributeError: bname = cast(pointer(create_string_buffer(asbytes(name))), POINTER(c_ubyte)) addr = eglGetProcAddress(bname) if addr: ftype = CFUNCTYPE(*((restype, ) + tuple(argtypes))) func = cast(addr, ftype) return func return missing_function(name, requires, suggestions)
def get_logfont(name, size, bold, italic, dpi): # Create a dummy DC for coordinate mapping dc = user32.GetDC(0) if dpi is None: dpi = 96 logpixelsy = dpi logfont = LOGFONT() # Conversion of point size to device pixels logfont.lfHeight = int(-size * logpixelsy // 72) if bold: logfont.lfWeight = FW_BOLD else: logfont.lfWeight = FW_NORMAL logfont.lfItalic = italic logfont.lfFaceName = asbytes(name) logfont.lfQuality = ANTIALIASED_QUALITY user32.ReleaseDC(0, dc) return logfont
def link_GL(name, restype, argtypes, requires=None, suggestions=None): try: func = getattr(gl_lib, name) func.restype = restype func.argtypes = argtypes decorate_function(func, name) return func except AttributeError: if _have_getprocaddress: # Fallback if implemented but not in ABI bname = cast(pointer(create_string_buffer(asbytes(name))), POINTER(c_ubyte)) addr = glXGetProcAddressARB(bname) if addr: ftype = CFUNCTYPE(*((restype,) + tuple(argtypes))) func = cast(addr, ftype) decorate_function(func, name) return func return missing_function(name, requires, suggestions)
def test_sub_subfolder_trailing_slash(loader): loader.path = ['dir1/dir1/'] assert loader.file('f3.txt').read().strip() == asbytes('F3')
def test_sub_subfolder(loader): loader.path = ['dir1/dir1'] assert loader.file('f3.txt').read().strip() == asbytes('F3')
def test_subfolder_trailing_slash(loader): loader.path = ['dir1/', 'dir2/'] assert loader.file('f2.txt').read().strip() == asbytes('F2') assert loader.file('f6.txt').read().strip() == asbytes('F6')
def test_subfolder(loader): loader.path = ['dir1', 'dir2'] assert loader.file('f2.txt').read().strip() == asbytes('F2') assert loader.file('f6.txt').read().strip() == asbytes('F6')
def test_zipfile_subdirs(loader): loader.path = ['dir1/res.zip/dir1', 'dir1/res.zip/dir1/dir1/'] assert loader.file('f8.txt').read().strip() == asbytes('F8') assert loader.file('f9.txt').read().strip() == asbytes('F9')
default_device = ctypes.cast( alc.alcGetString(None, alc.ALC_DEFAULT_DEVICE_SPECIFIER), ctypes.c_char_p).value capture_default_device = ctypes.cast( alc.alcGetString(None, alc.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER), ctypes.c_char_p).value print('Default device: %s' % default_device) print('Default capture device: %s' % capture_default_device) if alc.alcIsExtensionPresent( None, ctypes.create_string_buffer(b'ALC_ENUMERATION_EXT')): devices = split_nul_strings( alc.alcGetString(None, alc.ALC_DEVICE_SPECIFIER)) capture_devices = split_nul_strings( alc.alcGetString(None, alc.ALC_CAPTURE_DEVICE_SPECIFIER)) print('Devices: %s' % b', '.join(devices)) print('Capture devices: %s\n' % b', '.join(capture_devices)) if options.device: print('Using device "%s"...' % options.device) driver = openal.create_audio_driver(asbytes(options.device)) else: print('Using default device...') driver = openal.create_audio_driver() print('OpenAL version %d.%d' % driver.get_version()) print('Extensions: %s' % ', '.join(driver.get_extensions()))
def from_file(cls, file_name): ft_library = ft_get_library() ft_face = FT_Face() FT_New_Face(ft_library, asbytes(file_name), 0, byref(ft_face)) return cls(ft_face)
def set(self): self._event.set() os.write(self._sync_file_write, asbytes('1'))
def test_zipfile(loader): loader.path = ['dir1/res.zip'] assert loader.file('f7.txt').read().strip() == asbytes('F7')
def test_zipfile_trailing_slash(loader): loader.path = ['dir1/res.zip/'] assert loader.file('f7.txt').read().strip() == asbytes('F7')
def test_base_path_only(loader): assert loader.file('f1.txt').read().strip() == asbytes('F1')
""" from collections import OrderedDict from ctypes import * import pyglet.lib from pyglet.util import asbytes, asstr from pyglet.font.base import FontException # fontconfig library definitions (FcResultMatch, FcResultNoMatch, FcResultTypeMismatch, FcResultNoId, FcResultOutOfMemory) = range(5) FcResult = c_int FC_FAMILY = asbytes('family') FC_SIZE = asbytes('size') FC_SLANT = asbytes('slant') FC_WEIGHT = asbytes('weight') FC_FT_FACE = asbytes('ftface') FC_FILE = asbytes('file') FC_WEIGHT_REGULAR = 80 FC_WEIGHT_BOLD = 200 FC_SLANT_ROMAN = 0 FC_SLANT_ITALIC = 100 (FcTypeVoid, FcTypeInteger, FcTypeDouble, FcTypeString, FcTypeBool, FcTypeMatrix, FcTypeCharSet, FcTypeFTFace, FcTypeLangSet) = range(9) FcType = c_int
def test_blank_base_path(loader): loader.path = [''] assert loader.file('f1.txt').read().strip() == asbytes('F1')
def decode(cls, data): display, screen, width, height, rate = struct.unpack(cls.format, data) return cls(display.strip(asbytes('\0')), screen, width, height, rate)
def test_unused_paths(loader): loader.path = ['foo', 'bar', '.'] assert loader.file('f1.txt').read().strip() == asbytes('F1')