Esempio n. 1
0
    def _set_video_analyser_path(self):
        """
        Set the path of the video analyser.

        The path set depends on the current platform.
        :return:
        """
        if sys.platform == 'win32':
            # TODO: Remove this when migrating to Python 3
            #  This is to work around the case where windows has non-ASCII chars on %PATH% contents.
            from Tribler.Main.hacks import get_environment_variable
            path_env = get_environment_variable(u"PATH")
        elif is_android():
            path_env = unicode(os.environ["PYTHONPATH"])
        else:
            path_env = os.environ["PATH"]

        # Set video_analyser_path
        if sys.platform == 'win32':
            ffmpeg_name = u"ffmpeg.exe"
        elif sys.platform == 'darwin':
            ffmpeg_name = u"ffmpeg"
        elif find_executable("avconv", path_env):
            ffmpeg_name = u"avconv"
        else:
            ffmpeg_name = u"ffmpeg"

        ffmpeg_path = find_executable(ffmpeg_name, path_env)

        if ffmpeg_path is None:
            if sys.platform == 'darwin':
                self.config['general']['videoanalyserpath'] = "vlc/ffmpeg"
            else:
                self.config['general']['videoanalyserpath'] = os.path.abspath(
                    ffmpeg_name)
        else:
            self.config['general']['videoanalyserpath'] = os.path.abspath(
                ffmpeg_path)
Esempio n. 2
0
    def __init__(self, sessconfig=None):
        """ Constructor.
        @param sessconfig Optional dictionary used internally
        to make this a copy constructor.
        """
        self._logger = logging.getLogger(self.__class__.__name__)

        self.selected_ports = {}
        self.sessconfig = sessconfig or CallbackConfigParser()

        # Poor man's versioning of SessionConfig, add missing default values.
        for section, sect_dict in sessdefaults.iteritems():
            if not self.sessconfig.has_section(section):
                self.sessconfig.add_section(section)
            for k, v in sect_dict.iteritems():
                if not self.sessconfig.has_option(section, k):
                    self.sessconfig.set(section, k, v)

        if not sessconfig:
            return

        if sys.platform == 'win32':
            # TODO(emilon): This is to work around the case where windows has
            # non-ASCI chars on %PATH% contents. Should be removed if we migrate to
            # python 3.
            from Tribler.Main.hacks import get_environment_variable
            path_env = get_environment_variable(u"PATH")
        elif is_android():
            path_env = unicode(os.environ["PYTHONPATH"])
        else:
            path_env = os.environ["PATH"]

        # Set video_analyser_path
        if sys.platform == 'win32':
            ffmpegname = u"ffmpeg.exe"
        elif sys.platform == 'darwin':
            ffmpegname = u"ffmpeg"
        elif find_executable("avconv", path_env):
            ffmpegname = u"avconv"
        else:
            ffmpegname = u"ffmpeg"

        ffmpegpath = find_executable(ffmpegname, path_env)

        if ffmpegpath is None:
            if sys.platform == 'darwin':
                self.sessconfig.set(u'general', u'videoanalyserpath',
                                    u"vlc/ffmpeg")
            else:
                self.sessconfig.set(u'general', u'videoanalyserpath',
                                    os.path.abspath(ffmpegname))
        else:
            self.sessconfig.set(u'general', u'videoanalyserpath',
                                os.path.abspath(ffmpegpath))

        # Set videoplayer path
        if sys.platform == 'win32':
            videoplayerpath = os.path.expandvars(
                '${PROGRAMFILES}') + '\\Windows Media Player\\wmplayer.exe'
        elif sys.platform == 'darwin':
            videoplayerpath = find_executable("vlc") or (
                "/Applications/VLC.app"
                if os.path.exists("/Applications/VLC.app") else
                None) or "/Applications/QuickTime Player.app"
        else:
            videoplayerpath = find_executable("vlc") or "vlc"

        self.sessconfig.set(u'video', u'path', videoplayerpath)

        self.sessconfig.set(u'general', u'ipv6_binds_v4',
                            autodetect_socket_style())
Esempio n. 3
0
    def __init__(self, sessconfig=None):
        """ Constructor.
        @param sessconfig Optional dictionary used internally
        to make this a copy constructor.
        """
        self._logger = logging.getLogger(self.__class__.__name__)

        self.selected_ports = {}
        self.sessconfig = sessconfig or CallbackConfigParser()

        # Poor man's versioning of SessionConfig, add missing default values.
        for section, sect_dict in sessdefaults.iteritems():
            if not self.sessconfig.has_section(section):
                self.sessconfig.add_section(section)
            for k, v in sect_dict.iteritems():
                if not self.sessconfig.has_option(section, k):
                    self.sessconfig.set(section, k, v)

        if not sessconfig:
            return

        # TODO(emilon): This is to work around the case where windows has
        # non-ASCI chars on %PATH% contents. Should be removed if we migrate to
        # python 3.
        if sys.platform == 'win32':
            from Tribler.Main.hacks import get_environment_variable
            path_env = get_environment_variable(u"PATH")
        else:
            path_env = os.environ["PATH"]

        # Set video_analyser_path
        if sys.platform == 'win32':
            ffmpegname = u"ffmpeg.exe"
        elif sys.platform == 'darwin':
            ffmpegname = u"ffmpeg"
        elif find_executable("avconv"):
            ffmpegname = u"avconv"
        else:
            ffmpegname = u"ffmpeg"

        ffmpegpath = find_executable(ffmpegname, path_env)

        if ffmpegpath is None:
            if sys.platform == 'darwin':
                self.sessconfig.set(u'general', u'videoanalyserpath', u"vlc/ffmpeg")
            elif is_android(strict=True):
                self.sessconfig.set(u'general', u'videoanalyserpath', os.path.join(
                    os.environ['ANDROID_PRIVATE'], 'ffmpeg'))
            else:
                self.sessconfig.set(u'general', u'videoanalyserpath', ffmpegname)
        else:
            self.sessconfig.set(u'general', u'videoanalyserpath', ffmpegpath)

        # Set videoplayer path
        if sys.platform == 'win32':
            videoplayerpath = os.path.expandvars('${PROGRAMFILES}') + '\\Windows Media Player\\wmplayer.exe'
        elif sys.platform == 'darwin':
            videoplayerpath = find_executable("vlc") or ("/Applications/VLC.app" if os.path.exists(
                "/Applications/VLC.app") else None) or "/Applications/QuickTime Player.app"
        else:
            videoplayerpath = find_executable("vlc") or "vlc"

        self.sessconfig.set(u'video', u'path', videoplayerpath)

        self.sessconfig.set(u'general', u'ipv6_binds_v4', autodetect_socket_style())