def get_video_player(self, ext, videourl, mimetype=None):

        video_player_path = self.utility.config.Read('videoplayerpath')
        if DEBUG:
            print >> sys.stderr, "videoplay: Default player is", video_player_path

        if mimetype is None:
            if sys.platform == 'win32':
                # TODO: Use Python's mailcap facility on Linux to find player
                [mimetype,
                 playcmd] = win32_retrieve_video_play_command(ext, videourl)
                if DEBUG:
                    print >> sys.stderr, "videoplay: Win32 reg said playcmd is", playcmd

            if mimetype is None:
                if ext == '.avi':
                    # Arno, 2010-01-08: Hmmm... video/avi is not official registered at IANA
                    mimetype = 'video/avi'
                elif ext == '.mpegts' or ext == '.ts':
                    mimetype = 'video/mp2t'
                else:
                    mimetype = 'video/mpeg'
        else:
            if sys.platform == 'win32':
                [mimetype, playcmd
                 ] = win32_retrieve_playcmd_from_mimetype(mimetype, videourl)

        if self.playbackmode == PLAYBACKMODE_INTERNAL:
            if DEBUG:
                print >> sys.stderr, "videoplay: using internal player"
            return [mimetype, videourl]
        elif self.playbackmode == PLAYBACKMODE_EXTERNAL_MIME and sys.platform == 'win32':
            if playcmd is not None:
                cmd = 'start /B "TriblerVideo" ' + playcmd
                return [mimetype, cmd]

        if DEBUG:
            print >> sys.stderr, "videoplay: Defaulting to default player", video_player_path
        qprogpath = quote_program_path(video_player_path)
        #print >>sys.stderr,"videoplay: Defaulting to quoted prog",qprogpath
        if qprogpath is None:
            return [None, None]
        qvideourl = self.escape_path(videourl)
        playcmd = qprogpath + ' ' + qvideourl
        if sys.platform == 'win32':
            cmd = 'start /B "TriblerVideo" ' + playcmd
        elif sys.platform == 'darwin':
            cmd = 'open -a ' + playcmd
        else:
            cmd = playcmd
        if DEBUG:
            print >> sys.stderr, "videoplay: using external user-defined player by executing ", cmd
        return [mimetype, cmd]
示例#2
0
    def get_video_player(self, ext, videourl, mimetype=None):

        video_player_path = self.utility.config.Read('videoplayerpath')
        if DEBUG:
            print >> sys.stderr, "videoplay: Default player is", video_player_path

        if mimetype is None:
            if sys.platform == 'win32':
                # TODO: Use Python's mailcap facility on Linux to find player
                [mimetype, playcmd] = win32_retrieve_video_play_command(ext, videourl)
                if DEBUG:
                    print >> sys.stderr, "videoplay: Win32 reg said playcmd is", playcmd

            if mimetype is None:
                if ext == '.avi':
                    # Arno, 2010-01-08: Hmmm... video/avi is not official registered at IANA
                    mimetype = 'video/avi'
                elif ext == '.mpegts' or ext == '.ts':
                    mimetype = 'video/mp2t'
                else:
                    mimetype = 'video/mpeg'
        else:
            if sys.platform == 'win32':
                [mimetype, playcmd] = win32_retrieve_playcmd_from_mimetype(mimetype, videourl)

        if self.playbackmode == PLAYBACKMODE_INTERNAL:
            if DEBUG:
                print >> sys.stderr, "videoplay: using internal player"
            return [mimetype, videourl]
        elif self.playbackmode == PLAYBACKMODE_EXTERNAL_MIME and sys.platform == 'win32':
            if playcmd is not None:
                cmd = 'start /B "TriblerVideo" ' + playcmd
                return [mimetype, cmd]

        if DEBUG:
            print >> sys.stderr, "videoplay: Defaulting to default player", video_player_path
        qprogpath = quote_program_path(video_player_path)
        # print >>sys.stderr,"videoplay: Defaulting to quoted prog",qprogpath
        if qprogpath is None:
            return [None, None]
        qvideourl = self.escape_path(videourl)
        playcmd = qprogpath + ' ' + qvideourl
        if sys.platform == 'win32':
            cmd = 'start /B "TriblerVideo" ' + playcmd
        elif sys.platform == 'darwin':
            cmd = 'open -a ' + playcmd
        else:
            cmd = playcmd
        if DEBUG:
            print >> sys.stderr, "videoplay: using external user-defined player by executing ", cmd
        return [mimetype, cmd]
示例#3
0
    def get_mimetype(self, file):
        (prefix, ext) = os.path.splitext(file)
        ext = ext.lower()
        mimetype = None
        if sys.platform == 'win32':
            # TODO: Use Python's mailcap facility on Linux to find player
            try:
                from Tribler.Video.utils import win32_retrieve_video_play_command

                [mimetype, playcmd] = win32_retrieve_video_play_command(ext, file)
                if DEBUG:
                    print >>sys.stderr, "LibtorrentDownloadImpl: Win32 reg said MIME type is", mimetype
            except:
                if DEBUG:
                    print_exc()
                pass
        else:
            try:
                import mimetypes
                # homedir = os.path.expandvars('${HOME}')
                from Tribler.Core.osutils import get_home_dir
                homedir = get_home_dir()
                homemapfile = os.path.join(homedir, '.mimetypes')
                mapfiles = [homemapfile] + mimetypes.knownfiles
                mimetypes.init(mapfiles)
                (mimetype, encoding) = mimetypes.guess_type(file)
                
                if DEBUG:
                    print >> sys.stderr, "LibtorrentDownloadImpl: /etc/mimetypes+ said MIME type is", mimetype, file
            except:
                print_exc()

        # if auto detect fails
        if mimetype is None:
            if ext == '.avi':
                # Arno, 2010-01-08: Hmmm... video/avi is not official registered at IANA
                mimetype = 'video/avi'
            elif ext == '.mpegts' or ext == '.ts':
                mimetype = 'video/mp2t'
            elif ext == '.mkv':
                mimetype = 'video/x-matroska'
            elif ext in ('.ogg', '.ogv'):
                mimetype = 'video/ogg'
            elif ext in ('.oga'):
                mimetype = 'audio/ogg'
            elif ext == '.webm':
                mimetype = 'video/webm'
            else:
                mimetype = 'video/mpeg'
        return mimetype
    def get_mimetype(self, file):
        (prefix, ext) = os.path.splitext(file)
        ext = ext.lower()
        mimetype = None
        if sys.platform == 'win32':
            # TODO: Use Python's mailcap facility on Linux to find player
            try:
                from Tribler.Video.utils import win32_retrieve_video_play_command

                [mimetype, playcmd] = win32_retrieve_video_play_command(ext, file)
                if DEBUG:
                    print >>sys.stderr, "LibtorrentDownloadImpl: Win32 reg said MIME type is", mimetype
            except:
                if DEBUG:
                    print_exc()
                pass
        else:
            try:
                import mimetypes
                # homedir = os.path.expandvars('${HOME}')
                from Tribler.Core.osutils import get_home_dir
                homedir = get_home_dir()
                homemapfile = os.path.join(homedir, '.mimetypes')
                mapfiles = [homemapfile] + mimetypes.knownfiles
                mimetypes.init(mapfiles)
                (mimetype, encoding) = mimetypes.guess_type(file)
                
                if DEBUG:
                    print >> sys.stderr, "LibtorrentDownloadImpl: /etc/mimetypes+ said MIME type is", mimetype, file
            except:
                print_exc()

        # if auto detect fails
        if mimetype is None:
            if ext == '.avi':
                # Arno, 2010-01-08: Hmmm... video/avi is not official registered at IANA
                mimetype = 'video/avi'
            elif ext == '.mpegts' or ext == '.ts':
                mimetype = 'video/mp2t'
            elif ext == '.mkv':
                mimetype = 'video/x-matroska'
            elif ext in ('.ogg', '.ogv'):
                mimetype = 'video/ogg'
            elif ext in ('.oga'):
                mimetype = 'audio/ogg'
            elif ext == '.webm':
                mimetype = 'video/webm'
            else:
                mimetype = 'video/mpeg'
        return mimetype