示例#1
0
    def delete(self):
        if "filename" in self.status:
            filename = self.status['filename']
        else:
            return
        try:
            fileutil.delete(filename)
        except OSError:
            logging.exception("Error deleting downloaded file: %s",
                              to_uni(filename))

        parent = os.path.join(fileutil.expand_filename(filename),
                              os.path.pardir)
        parent = os.path.normpath(parent)
        movies_dir = fileutil.expand_filename(
            app.config.get(prefs.MOVIES_DIRECTORY))
        if ((os.path.exists(parent) and os.path.exists(movies_dir)
             and not samefile(parent, movies_dir)
             and len(os.listdir(parent)) == 0)):
            try:
                os.rmdir(parent)
            except OSError:
                logging.exception(
                    "Error deleting empty download directory: %s",
                    to_uni(parent))
示例#2
0
def _yahoo_hack(feedparser_entries):
    """Hack yahoo search to provide enclosures"""
    for entry in feedparser_entries:
        if 'enclosures' not in entry:
            try:
                url = entry['link']
            except KeyError:
                continue
            mimetype = filetypes.guess_mime_type(url)
            if mimetype is not None:
                entry['enclosures'] = [{'url': util.to_uni(url),
                                        'type': util.to_uni(mimetype)}]
            elif flashscraper.is_maybe_flashscrapable(url):
                entry['enclosures'] = [{'url': util.to_uni(url),
                                        'type': util.to_uni("video/flv")}]
示例#3
0
    def delete(self):
        if self.filename is None:
            return
        try:
            fileutil.delete(self.filename)
        except OSError:
            logging.exception("Error deleting downloaded file: %s",
                              to_uni(self.filename))

        parent = os.path.join(fileutil.expand_filename(self.filename),
                              os.path.pardir)
        parent = os.path.normpath(parent)
        movies_dir = fileutil.expand_filename(app.config.get(prefs.MOVIES_DIRECTORY))
        if ((os.path.exists(parent) and os.path.exists(movies_dir)
             and not samefile(parent, movies_dir)
             and len(os.listdir(parent)) == 0)):
            try:
                os.rmdir(parent)
            except OSError:
                logging.exception("Error deleting empty download directory: %s",
                                  to_uni(parent))
        self.filename = None
示例#4
0
文件: utiltest.py 项目: cool-RR/Miro
 def test_to_uni(self):
     # try it twice to make sure the cached value is correct as well
     for i in range(0,2):
         self.assertEqualWithType('', unicode, util.to_uni(''))
         self.assertEqualWithType('', unicode, util.to_uni(u''))
         self.assertEqualWithType('abc', unicode, util.to_uni('abc'))
         self.assertEqualWithType('abc', unicode, util.to_uni(u'abc'))
         self.assertEqualWithType('!@^)!@%I*', unicode, util.to_uni('!@^)!@%I*'))
         self.assertEqualWithType('!@^)!@%I*', unicode, util.to_uni(u'!@^)!@%I*'))
示例#5
0
 def test_to_uni(self):
     # try it twice to make sure the cached value is correct as well
     for i in range(0, 2):
         self.assertEqualWithType('', unicode, util.to_uni(''))
         self.assertEqualWithType('', unicode, util.to_uni(u''))
         self.assertEqualWithType('abc', unicode, util.to_uni('abc'))
         self.assertEqualWithType('abc', unicode, util.to_uni(u'abc'))
         self.assertEqualWithType('!@^)!@%I*', unicode,
                                  util.to_uni('!@^)!@%I*'))
         self.assertEqualWithType('!@^)!@%I*', unicode,
                                  util.to_uni(u'!@^)!@%I*'))
示例#6
0
文件: browser.py 项目: nxmirrors/miro
    def should_load_url(self, url, mimetype=None):
        """Returns True if the Miro browser should handle the url and
        False otherwise.

        Situations which should return false:

        * if the url is something that Miro should download instead
        * other things?
        """
        if mimetype is not None:
            logging.debug("got %s (%s)", url, mimetype)
        else:
            logging.debug("got %s", url)

        if url in self.seen_cache:
            del self.seen_cache[url]
            return True

        url = util.to_uni(url)
        if subscription.is_subscribe_link(url):
            messages.SubscriptionLinkClicked(url).send_to_backend()
            return False

        def unknown_callback(url):
            call_on_ui_thread(self.handle_unknown_url, url)

        if filetypes.is_maybe_rss_url(url):
            logging.debug("miro wants to handle %s", url)
            messages.DownloadURL(url, unknown_callback).send_to_backend()
            return False

        # parse the path out of the url and run that through the filetypes
        # code to see if it might be a video, audio or torrent file.
        # if so, try downloading it.
        ret = urlparse(url)
        if filetypes.is_allowed_filename(ret[2]):
            logging.debug("miro wants to handle %s", url)
            messages.DownloadURL(url, unknown_callback).send_to_backend()
            return False

        if mimetype is not None and filetypes.is_allowed_mimetype(mimetype):
            logging.debug("miro wants to handle %s", url)
            messages.DownloadURL(url, unknown_callback).send_to_backend()
            return False

        return True
示例#7
0
def get_text():
    text = None
    if OpenClipboard(ctypes.c_int(0)):
        try:
            hClipMem = GetClipboardData(CF_TEXT)
            if hClipMem:
                GlobalLock.restype = ctypes.c_char_p
                text = GlobalLock(hClipMem)
                GlobalUnlock(hClipMem)
        finally:
            CloseClipboard()
    else:
        logging.warning("OpenClipboard(0) call failed.")

    if text is not None:
        text = to_uni(text)
    return text
示例#8
0
def get_text():
    text = None
    if OpenClipboard(ctypes.c_int(0)):
        try:
            hClipMem = GetClipboardData(CF_TEXT)
            if hClipMem:
                GlobalLock.restype = ctypes.c_char_p
                text = GlobalLock(hClipMem)
                GlobalUnlock(hClipMem)
        finally:
            CloseClipboard()
    else:
        logging.warning("OpenClipboard(0) call failed.")

    if text is not None:
        text = to_uni(text)
    return text
示例#9
0
文件: browser.py 项目: zjmmjzzjm/miro
    def should_load_url(self, url):
        """Returns True if the Miro browser should handle the url and
        False otherwise.

        Situations which should return false:

        * if the url is something that Miro should download instead
        * other things?
        """
        logging.debug("got %s", url)

        if url in self.seen_cache:
            del self.seen_cache[url]
            return True

        url = util.to_uni(url)
        if subscription.is_subscribe_link(url):
            self.emit('download-started')
            messages.SubscriptionLinkClicked(url).send_to_backend()
            return False


        if filetypes.is_maybe_rss_url(url):
            logging.debug("miro wants to handle %s", url)
            self.emit('download-started')
            messages.DownloadURL(url, self.unknown_callback).send_to_backend()
            return False

        # parse the path out of the url and run that through the filetypes
        # code to see if it might be a video, audio or torrent file.
        # if so, try downloading it.
        ret = urlparse(url)
        if filetypes.is_allowed_filename(ret[2]):
            logging.debug("miro wants to handle %s", url)
            self.emit('download-started')
            messages.DownloadURL(url, self.unknown_callback).send_to_backend()
            return False

        if util.is_magnet_uri(url):
            logging.debug("miro wants to handle %s", url)
            self.emit('download-started')
            messages.DownloadURL(url, self.unknown_callback).send_to_backend()
            return False

        return True