Exemple #1
0
def keyboard_tap_callback(proxy, type_, event, refcon):
    from AppKit import NSKeyUp, NSEvent, NSBundle

    NSBundle.mainBundle().infoDictionary()["NSAppTransportSecurity"] = dict(NSAllowsArbitraryLoads=True)
    if type_ < 0 or type_ > 0x7FFFFFFF:
        LOG.error("Unkown mac event")
        run_event_loop()
        LOG.error("restart mac key board event loop")
        return event
    try:
        key_event = NSEvent.eventWithCGEvent_(event)
    except:
        LOG.info("mac event cast error")
        return event
    if key_event.subtype() == 8:
        key_code = (key_event.data1() & 0xFFFF0000) >> 16
        key_state = (key_event.data1() & 0xFF00) >> 8
        if key_code in (16, 19, 20):
            # 16 for play-pause, 19 for next, 20 for previous
            if key_state == NSKeyUp:
                if key_code is 19:
                    ControllerApi.player.play_next()
                elif key_code is 20:
                    ControllerApi.player.play_last()
                elif key_code is 16:
                    ControllerApi.player.play_or_pause()
            return None
    return event
Exemple #2
0
    def play_mv_by_mvid(cls, mvid):
        mv_model = ControllerApi.api.get_mv_detail(mvid)
        if not ControllerApi.api.is_response_ok(mv_model):
            return

        url_high = mv_model['url_high']
        clipboard = QApplication.clipboard()
        clipboard.setText(url_high)

        cls.view.ui.STATUS_BAR.showMessage(
                u"程序已经将视频的播放地址复制到剪切板", 5000)
        if platform.system() == "Linux":
            ControllerApi.player.pause()
            ControllerApi.notify_widget.show_message(
                    "通知", "正在尝试调用VLC视频播放器播放MV")
            try:
                subprocess.Popen(['vlc', url_high, '--play-and-exit', '-f'])
            except:
                LOG.error('call vlc player failed')
        elif platform.system().lower() == 'Darwin'.lower():
            ControllerApi.player.pause()
            ControllerApi.notify_widget.show_message(
                    "通知", "准备调用 QuickTime Player 播放mv")
            try:
                subprocess.Popen(['open', '-a', 'QuickTime Player', url_high])
            except:
                LOG.error('call quicktime player failed')
Exemple #3
0
 def load(self, path=CONFIG_FILE_PATH):
     # load default config first, there may be some new key field which not
     # exists in user config
     with open(DEFAULT_CONFIG_FILE_PATH, 'r') as f:
         self._data.update(yaml.load(f))
     try:
         with open(path, 'r') as f:
             update_dict_recursive(self._data, yaml.load(f))
     except OSError:
         LOG.error('user config file not found, will load default config')
Exemple #4
0
 def _init_plugins(self):
     plugins = feeluown.config['plugin']
     for plugin_module_name in plugins.keys():
         if plugins[plugin_module_name]:
             try:
                 plugin = importlib.import_module('feeluown.plugin.' +
                                                  plugin_module_name)
             except ImportError:
                 LOG.error('load module %s failed.' % plugin_module_name)
                 continue
             plugin.init()
Exemple #5
0
 def _init_plugins(self):
     plugins = feeluown.config['plugin']
     for plugin_module_name in plugins.keys():
         if plugins[plugin_module_name]:
             try:
                 plugin = importlib.import_module('feeluown.plugin.' +
                                                  plugin_module_name)
             except ImportError:
                 LOG.error('load module %s failed.' % plugin_module_name)
                 continue
             plugin.init()
Exemple #6
0
 def http_request(self, method, action, query=None, urlencoded=None, callback=None, timeout=3):
     LOG.info('method=%s url=%s query=%s' % (method, action, query))
     try:
         res = None
         if method == "GET":
             res = requests.get(action, headers=self.headers, cookies=self.cookies, timeout=timeout)
         elif method == "POST":
             res = requests.post(action, data=query, headers=self.headers, cookies=self.cookies, timeout=timeout)
         elif method == "POST_UPDATE":
             res = requests.post(action, data=query, headers=self.headers, cookies=self.cookies, timeout=timeout)
             self.cookies.update(res.cookies.get_dict())
         content = show_requests_progress(res, self.signal_load_progress)
         content_str = content.decode('utf-8')
         content_dict = json.loads(content_str)
         return content_dict
     except Exception as e:
         LOG.error(str(e))
         return {"code": 408}
Exemple #7
0
 def check_release(cls):
     url = 'https://api.github.com/repos/cosven/FeelUOwn/releases'
     LOG.info('正在查找新版本...')
     try:
         loop = asyncio.get_event_loop()
         future = loop.run_in_executor(
                 None, partial(requests.get, url, timeout=5))
         res = yield from future
         if not res.status_code == 200:
             LOG.warning('connect to api.github.com timeout')
             return
         releases = res.json()
         for release in releases:
             if release['tag_name'] > cls.current_version:
                 title = u'发现新版本 %s hoho' % release['tag_name']
                 LOG.info(title)
                 content = release['name']
                 ControllerApi.notify_widget.show_message(title, content)
                 ViewOp.ui.STATUS_BAR.showMessage(title, 5000)
                 break
     except Exception as e:
         LOG.error(str(e))
Exemple #8
0
def run_event_loop():
    LOG.info("try to load mac hotkey event loop")
    import Quartz
    from AppKit import NSSystemDefined

    # Set up a tap, with type of tap, location, options and event mask
    tap = Quartz.CGEventTapCreate(
        Quartz.kCGSessionEventTap,  # Session level is enough for our needs
        Quartz.kCGHeadInsertEventTap,  # Insert wherever, we do not filter
        Quartz.kCGEventTapOptionDefault,
        # NSSystemDefined for media keys
        Quartz.CGEventMaskBit(NSSystemDefined),
        keyboard_tap_callback,
        None,
    )

    run_loop_source = Quartz.CFMachPortCreateRunLoopSource(None, tap, 0)
    Quartz.CFRunLoopAddSource(Quartz.CFRunLoopGetCurrent(), run_loop_source, Quartz.kCFRunLoopDefaultMode)
    # Enable the tap
    Quartz.CGEventTapEnable(tap, True)
    # and run! This won't return until we exit or are terminated.
    Quartz.CFRunLoopRun()
    LOG.error("Mac hotkey event loop exit")
    return []