def openDir(self, dir=None):
        
        if not dir:
            directories = set()
            for item in self.active_tree_widget.selectedItems():
                download = item.getDownload()
                directories.add(os.path.split(download.dest_file)[0])
            
            filemanager = None
        else:
            directories = (dir,)
        
        for manager in c.FILEMANAGERS:
            if is_command(manager):
                filemanager = manager
                break

        if filemanager:
            for directory in directories:
                subprocess.Popen((filemanager, directory))
            
            self.ui.statusbar.showMessage(self.tr("Opening download directory %s with %s") % (" ".join(directories), filemanager), 5000)
ICON_START = PATH_MEDIA + "start.png"
ICON_STOP = PATH_MEDIA + "stop.png"
ICON_PAUSE = PATH_MEDIA + "pause.png"
ICON_OPEN_FOLDER = PATH_MEDIA + "folder-open.png"
ICON_ERROR = PATH_MEDIA + "error.png"
ICON_VALID = PATH_MEDIA + "dialog-ok-apply.png"
ICON_ADD = PATH_MEDIA + "list-add.svg"
ICON_REMOVE = PATH_MEDIA + "list-remove.png"
ICON_DELETE = PATH_MEDIA + "trash.png"
ICON_COPY = PATH_MEDIA + "edit-copy.png"
ICON_REPEAT = PATH_MEDIA + "refresh.png"
ICON_PLAYLIST_REPEAT = PATH_MEDIA + "playlist_refresh.png"
ICON_LOW_QUALITY = PATH_MEDIA + "low-quality.png"
ICON_HIGH_QUALITY = PATH_MEDIA + "high-quality.png"
ICON_ASK_QUALITY = PATH_MEDIA + "ask-quality.png"
ICON_CUSTOM_QUALITY = PATH_MEDIA + "custom-quality.png"



#FileManagers
FILEMANAGERS=["xdg-open","dolphin","d3lphin","konqueror","gnome-open","nautilus",\
            "thunar","rox"]

TEMP_PATH = tempfile.gettempdir()

HAS_FFMPEG = is_command("ffmpeg")
HAS_FFMPEG2THEORA = is_command("ffmpeg2theora")



def run():
    """Main function"""
    try:
        parser = OptionParser(usage="usage: %prog [options] URL", version=c.VERSION)
        parser.add_option(
            "-d", "--download", action="store_true", dest="down", default=False, help="download the video"
        )
        parser.add_option(
            "-L",
            "--list-plugins",
            action="store_true",
            dest="list_plugins",
            default=False,
            help="list plugins used and exit",
        )
        parser.add_option("-p", "--player", dest="player", default=False, help="use your favourite player")
        parser.add_option("-o", "--output", dest="output", default=False, help="save video to a certain location")
        parser.add_option(
            "-q",
            "--quality",
            dest="quality",
            default="all",
            help="list all, lowest or highest " "quality video formats",
        )
        (options, args) = parser.parse_args()
        # Validate player option
        if not options.player:
            options.player = None
        elif is_command(options.player):
            options.player = options.player
        else:
            options.player = None
            print (" *ERROR* " + '"' + str(options.player) + '"' + " is NOT a valid player! Using default player...\n")
        # Validate quality option.
        chosen_quality = None
        for quality in ("all", "lowest", "highest"):
            if quality.startswith(options.quality):
                if chosen_quality is None:
                    chosen_quality = quality
                else:
                    parser.error("ambiguous quality setting")
        if chosen_quality is not None:
            options.quality = chosen_quality
        else:
            parser.error("unknown quality chosen")
        if options.list_plugins:
            print "Installed plugins:"
            print ", ".join(plugin for plugin in MATCHER.plugins.iterkeys())
            print ""
            print "Disabled plugins:"
            for plugin, reasons in MATCHER.disabled.iteritems():
                print plugin
                print "\n".join("\t" + reason for reason in reasons)
        else:
            valid_videos = []
            for url in args:
                plugin = MATCHER.match(url)
                if plugin is not None:
                    for medium in plugin:
                        valid_videos.append(medium)

            if not valid_videos:
                print "No valid links found."
            else:
                handle_videos(valid_videos, options)

    except KeyboardInterrupt:
        print "\r"
        sys.exit()
Exemple #4
0
    def test_is_command(self):
        """Test that the default player is a command"""
        from watchvideo.main import get_default_player
        from watchvideo.utils import is_command

        self.assertTrue(is_command(get_default_player()))
 def media_player(self, value):
     if not is_command(value):
         raise ValueError("player must be a command")
     self.settings.setValue("media_player", value)