コード例 #1
0
    def play(self, playlist, first, last):
        self.pls.clear()

        if first == last:
            URL = playlist.list[first].URL
            xbmc.Player.play(self, URL)
        else:
        
            index = first
            urlopener = CURLLoader()
            self.stopped=False
            while index <= last and self.stopped == False and self.pls.size() < 100:                
                type = playlist.list[index].type
                if type == 'video' or type == 'audio':
                    URL = playlist.list[index].URL

                    result = urlopener.urlopen(URL)
                    if result == 0:
                        loc_url = urlopener.loc_url

                        name = playlist.list[index].name
                        self.pls.add(loc_url, name)
                        
                        if self.pls.size() == 1:
                            #start playing                        
                            xbmc.Player.play(self, self.pls)
                index = index + 1
            
            if self.pls.size() == 0:
                #no valid items found
                return -1
                
        return 0
コード例 #2
0
    def get_real_url(self, entry, header=""):
        self.state = 0  #success

        URL = entry.URL
        localfile = entry.DLloc

        #download of FTP file is handled in a separte function
        if URL[:3] == 'ftp':
            self.download_fileFTP(entry, header)
            return "ftp"

        if URL[:4] != 'http':
            self.state = -1  #URL does not point to internet file.
            return "non http"

        #Continue with HTTP download
        #self.MainWindow.dlinfotekst.setLabel('(' + header + ')' + " Retrieving file info...")
        #entry.processed=self.processed

        # set custom headers if specified
        URL, headers = parse_headers(URL, entry)

        #Get the direct URL to the mediaitem given URL
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, entry)
        if result["code"] != 0:
            self.state = -1  #failed to download the file
            print "urlopener.urlopen failed"
            return "urlopen failed"

        URL = urlopener.loc_url

        return URL
コード例 #3
0
    def InstallScript(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.URL
        
        dialog=xbmcgui.DialogProgress()
        dialog.create("Installer")
        dialog.update(33,"Downloading file...")
        
        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result == 0:
            self.URL = urlopener.loc_url
               
        #download the file.
        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'script.zip')
        if loader.state != 0:
            return -2
        filename = loader.localfile

        dialog.update(66,"Installing...")

        result = self.unzip_file_into_dir(filename, scriptDir)   

        dialog.close()

        return result
コード例 #4
0
ファイル: CInstaller.py プロジェクト: Stevie-Bs/navi-x
    def InstallScript(self, URL="", mediaitem=CMediaItem()):
        if URL != "":
            self.URL = URL
        else:
            self.URL = mediaitem.URL

        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result["code"] == 0:
            self.URL = urlopener.loc_url

        SetInfoText("Downloading... ", setlock=True)

        # download the file.
        loader = CFileLoader2()
        loader.load(self.URL, tempCacheDir + "script.zip")
        if loader.state != 0:
            return -2
        filename = loader.localfile

        SetInfoText("Installing... ", setlock=True)

        result = self.unzip_file_into_dir(filename, scriptDir)

        return result
コード例 #5
0
ファイル: CInstaller.py プロジェクト: lockers90/Isengard
    def InstallScript(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.URL
        
        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result["code"] == 0:
            self.URL = urlopener.loc_url
        
        SetInfoText("Downloading... ", setlock=True)
        
        #download the file.
        loader = CFileLoader2()
        loader.load(self.URL, tempCacheDir + 'script.zip')
        if loader.state != 0:
            return -2
        filename = loader.localfile

        SetInfoText("Installing... ", setlock=True)

        result = self.unzip_file_into_dir(filename, scriptDir)   
        
        return result
コード例 #6
0
ファイル: CPlayer.py プロジェクト: drrlramsey/xbmc-addons
    def play_URL(self, URL, mediaitem=0):
        #URL=mediaitem.URL
        #check if the URL is empty or not
        if URL == '':
            return -1
                                              
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, mediaitem)
        if result != 0:
            return -1    
        URL = urlopener.loc_url
        
        SetInfoText("Loading... ")

        self.pls.clear() #clear the playlist
    
        ext = getFileExtension(URL)
        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2() #file loader
            loader.load(URL, tempCacheDir + "playlist." + ext, retries=2)
            if loader.state == 0: #success
                result = self.pls.load(loader.localfile)
                if result == False:
                    return -1
                xbmc.Player.play(self, self.pls) #play the playlist
        else:
            #self.pls.add(urlopener.loc_url)
            if mediaitem.playpath != '':
                self.play_RTMP(mediaitem.URL, mediaitem.playpath, mediaitem.swfplayer, mediaitem.pageurl);
            else:  
                xbmc.Player.play(self, urlopener.loc_url)
            
        return 0
コード例 #7
0
ファイル: CInstaller.py プロジェクト: Stevie-Bs/navi-x
    def InstallPlugin(self, URL="", mediaitem=CMediaItem()):
        if URL != "":
            self.URL = URL
        else:
            self.URL = mediaitem.URL

        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result["code"] == 0:
            self.URL = urlopener.loc_url

        # retrieve the type of plugin
        index = mediaitem.type.find(":")
        if index != -1:
            subdir = mediaitem.type[index + 1 :] + "\\"
        else:
            subdir = ""

        SetInfoText("Downloading... ", setlock=True)

        # download the file.
        loader = CFileLoader2()
        loader.load(self.URL, tempCacheDir + "plugin.zip", content_type="zip")
        if loader.state != 0:
            if loader.state == -2:
                dialog = xbmcgui.Dialog()
                dialog.ok(" Installer", "Failed. Not a ZIP file.", "Use the standard Download feature.")
            return -2
        filename = loader.localfile

        SetInfoText("Installing... ", setlock=True)

        result = self.unzip_file_into_dir(filename, pluginDir + subdir)

        return result
コード例 #8
0
    def read_file_info(self, entry):
        self.state = 0  #success
        ext = ''  #no extension
        size = 0
        try:
            URL, headers = parse_headers(entry.URL)

            if URL[:3] == 'ftp':
                #FTP
                ext = getFileExtension(URL)
                if ext != '':
                    ext = '.' + ext
            else:
                #HTTP
                urlopener = CURLLoader()
                result = urlopener.urlopen(URL, entry)
                if result["code"] != 0:
                    self.state = -1
                    print('URL does not point to internet file.')
                    return ext, size
                loc_url = urlopener.loc_url  #; print('line223 loc_url= ' +str(loc_url))
                self.processed = urlopener.processed  #; print('self.processed= ' +str(self.processed))

                #Now we try to open the URL. If it does not exist an error is
                #returned.
                try:
                    #headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
                    req = urllib2.Request(loc_url, None, headers)
                    size_string, size_raw = self.file_size(0, req)
                    size = int(size_raw)
                except Exception, e:
                    size = 0
                    print('ERROR line 237' + str(e))
                #loc_url=f.geturl()
                try:
                    #special handing for some URL's
                    pos = URL.find(
                        'http://www.youtube.com')  #find last 'http' in the URL
                    if pos != -1:
                        ext = '.mp4'
                    else:
                        #todo: deprecated
                        pos = URL.find("flyupload.com")
                        if pos != -1:
                            ext = '.avi'
                        else:
                            #extract the file extension
                            url_stripped = re.sub(
                                '\?.*$', '', loc_url)  # strip GET-method args
                            re_ext = re.compile('(\.\w+)$')  # find extension
                            match = re_ext.search(url_stripped)
                            if match is None:
                                #ext = ""
                                ext = getFileExtension(loc_url)
                                if ext != '':
                                    ext = '.' + ext
                            else:
                                ext = match.group(1)
                except Exception, e:
                    print('ERROR line 261', 'e =' + str(e))
コード例 #9
0
    def play_URL(self, URL, mediaitem=0):
        #URL=mediaitem.URL
        #check if the URL is empty or not
        if URL == '':
            return -1

        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, mediaitem)
        if result != 0:
            return -1
        URL = urlopener.loc_url

        SetInfoText("Loading... ")

        self.pls.clear()  #clear the playlist

        ext = getFileExtension(URL)
        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2()  #file loader
            loader.load(URL, tempCacheDir + "playlist." + ext, retries=2)
            if loader.state == 0:  #success
                result = self.pls.load(loader.localfile)
                if result == False:
                    return -1
                xbmc.Player.play(self, self.pls)  #play the playlist
        else:
            #self.pls.add(urlopener.loc_url)
            if mediaitem.playpath != '':
                self.play_RTMP(mediaitem.URL, mediaitem.playpath,
                               mediaitem.swfplayer, mediaitem.pageurl)
            else:
                xbmc.Player.play(self, urlopener.loc_url)

        return 0
コード例 #10
0
ファイル: CDownLoader.py プロジェクト: NavFRi-x/Navi-X-FR
    def get_real_url(self, entry, header=""):
        self.state = 0 #success

        URL = entry.URL
        localfile = entry.DLloc

        #download of FTP file is handled in a separte function
        if URL[:3] == 'ftp':
            self.download_fileFTP(entry, header)
            return "ftp"

        if URL[:4] != 'http':
            self.state = -1 #URL does not point to internet file.
            return "non http"

        #Continue with HTTP download
        #self.MainWindow.dlinfotekst.setLabel('(' + header + ')' + " Retrieving file info...")
        #entry.processed=self.processed

        # set custom headers if specified
        URL, headers=parse_headers(URL, entry)

        #Get the direct URL to the mediaitem given URL 
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, entry)
        if result["code"] != 0:
            self.state = -1 #failed to download the file
            print "urlopener.urlopen failed"
            return "urlopen failed"

        URL = urlopener.loc_url

	return URL
コード例 #11
0
ファイル: CInstaller.py プロジェクト: drrlramsey/xbmc-addons
    def InstallSkin(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.URL
        
        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result == 0:
            self.URL = urlopener.loc_url
        
        SetInfoText("Downloading... ")
        
        #download the file.
        loader = CFileLoader2()
        loader.load(self.URL, tempCacheDir + 'skin.zip')
        if loader.state != 0:
            return -2
        filename = loader.localfile

        SetInfoText("Installing... ")

        result = self.unzip_file_into_dir(filename, skinDir)   

        return result
コード例 #12
0
    def read_file_info(self, entry):
        self.state = 0  #success
        ext = ''  #no extension

        URL = entry.URL

        if URL[:3] == 'ftp':
            #FTP
            ext = getFileExtension(URL)
            if ext != '':
                ext = '.' + ext
        else:
            #HTTP
            urlopener = CURLLoader()
            result = urlopener.urlopen(URL, entry)
            if result != 0:
                self.state = -1  #URL does not point to internet file.
                return
            loc_url = urlopener.loc_url

            #Now we try to open the URL. If it does not exist an error is
            #returned.
            try:
                headers = {
                    'User-Agent':
                    'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'
                }
                req = urllib2.Request(loc_url, None, headers)
                f = urllib2.urlopen(req)
                loc_url = f.geturl()
                size_string = f.headers['Content-Length']
                size = int(size_string)

            except IOError:
                self.state = -1  #failed to open the HTTP URL
                return

            #special handing for some URL's
            pos = URL.find(
                'http://www.youtube.com')  #find last 'http' in the URL
            if pos != -1:
                ext = '.mp4'
            else:
                #todo: deprecated
                pos = URL.find("flyupload.com")
                if pos != -1:
                    ext = '.avi'
                else:
                    #extract the file extension
                    url_stripped = re.sub('\?.*$', '',
                                          loc_url)  # strip GET-method args
                    re_ext = re.compile('(\.\w+)$')  # find extension
                    match = re_ext.search(url_stripped)
                    if match is None:
                        ext = ""
                    else:
                        ext = match.group(1)

        return ext, size
コード例 #13
0
ファイル: CDownLoader.py プロジェクト: tderuvo/Gogo-TV-Plus
    def read_file_info(self, entry):
        self.state = 0  # success
        ext = ""  # no extension
        size = 0

        URL = entry.URL

        if URL[:3] == "ftp":
            # FTP
            ext = getFileExtension(URL)
            if ext != "":
                ext = "." + ext
        else:
            # HTTP
            urlopener = CURLLoader()
            result = urlopener.urlopen(URL, entry)
            if result != 0:
                self.state = -1  # URL does not point to internet file.
                return
            loc_url = urlopener.loc_url

            # Now we try to open the URL. If it does not exist an error is
            # returned.
            try:
                headers = {"User-Agent": "Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)"}
                req = urllib2.Request(loc_url, None, headers)
                f = urllib2.urlopen(req)
                # loc_url=f.geturl()
                size_string = f.headers["Content-Length"]
                size = int(size_string)
                f.close()
            except:
                size = 0

            # special handing for some URL's
            pos = URL.find("http://www.youtube.com")  # find last 'http' in the URL
            if pos != -1:
                ext = ".mp4"
            else:
                # todo: deprecated
                pos = URL.find("flyupload.com")
                if pos != -1:
                    ext = ".avi"
                else:
                    # extract the file extension
                    url_stripped = re.sub("\?.*$", "", loc_url)  # strip GET-method args
                    re_ext = re.compile("(\.\w+)$")  # find extension
                    match = re_ext.search(url_stripped)
                    if match is None:
                        # ext = ""
                        ext = getFileExtension(loc_url)
                        if ext != "":
                            ext = "." + ext
                    else:
                        ext = match.group(1)

        return ext, size
コード例 #14
0
ファイル: CDownLoader.py プロジェクト: drrlramsey/xbmc-addons
    def read_file_info(self, entry):
        self.state = 0 #success    
        ext='' #no extension
    
        URL = entry.URL
    
        if URL[:3] == 'ftp':
            #FTP
            ext = getFileExtension(URL)
            if ext != '':
                ext = '.' + ext
        else:
            #HTTP
            urlopener = CURLLoader()
            result = urlopener.urlopen(URL, entry)
            if result != 0:
                self.state = -1 #URL does not point to internet file.
                return
            loc_url = urlopener.loc_url

            #Now we try to open the URL. If it does not exist an error is
            #returned.
            try:
                headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
                req = urllib2.Request(loc_url, None, headers)
                f = urllib2.urlopen(req)
                loc_url=f.geturl()
                size_string = f.headers['Content-Length']
                size = int(size_string)

            except IOError:
                self.state = -1 #failed to open the HTTP URL
                return
            
            #special handing for some URL's
            pos = URL.find('http://www.youtube.com') #find last 'http' in the URL
            if pos != -1:
                ext='.mp4'
            else:
#todo: deprecated            
                pos = URL.find("flyupload.com")
                if pos != -1:
                    ext='.avi'
                else:
                    #extract the file extension
                    url_stripped = re.sub('\?.*$', '', loc_url) # strip GET-method args
                    re_ext = re.compile('(\.\w+)$') # find extension
                    match = re_ext.search(url_stripped)
                    if match is None:
                        ext = ""
                    else:
                        ext = match.group(1)

        return ext, size
コード例 #15
0
ファイル: CPlayer.py プロジェクト: pmietlicki/kodi-repo
    def play(self, playlist, first, last):
        self.pls.clear()

        if first == last:
            URL = playlist.list[first].URL
            xbmc.Player.play(self, URL)
        else:
        
            index = first
            urlopener = CURLLoader()
            self.stopped=False
            count=0
            while (index <= last) and (self.stopped == False):        
                if (count>0) and not (xbmc.Player().isPlaying()):
                    self.stopped=True
                type = playlist.list[index].type
                if type == 'video' or type == 'audio' or type == 'ps3plus':
                    URL = playlist.list[index].URL

                    result = urlopener.urlopen(URL, playlist.list[index])
                    if result["code"] == 0:
                        loc_url = urlopener.loc_url

                        name = playlist.list[index].name
                        
                        #if (xbmc.getInfoLabel("System.BuildVersion")[:1] == '9') or \
                        #   (xbmc.getInfoLabel("System.BuildVersion")[:2] == '10'):                        
                        listitem = xbmcgui.ListItem(name)
                        listitem.setInfo('video', {'Title': name})
                        self.pls.add(url=loc_url, listitem=listitem)                      
                        #else:
                        #    self.pls.add(loc_url, name)
                        
                        if self.pls.size() == 1:
                            #start playing, continue loading                      
                            xbmc.Player.play(self, self.pls)
                index = index + 1
                count = count + 1
            
            if self.pls.size() == 0:
                #no valid items found
                return {"code":1,"data":"no valid items found"}
        
        if not (xbmc.Player().isPlaying()):
            return {"code":1,"data":"no valid items found"} 

        return {"code":0}
コード例 #16
0
    def play(self, playlist, first, last):
        self.pls.clear()

        if first == last:
            URL = playlist.list[first].URL
            self.Attempt_to_play_URL(URL)
            #xbmc.Player.play(self, URL)
        else:

            index = first
            urlopener = CURLLoader()
            self.stopped = False
            while (index <= last) and (self.stopped
                                       == False) and (self.pls.size() < 10):
                type = playlist.list[index].type
                if type == 'video' or type == 'audio':
                    URL = playlist.list[index].URL

                    result = urlopener.urlopen(URL, playlist.list[index])
                    if result["code"] == 0:
                        loc_url = urlopener.loc_url

                        name = playlist.list[index].name

                        #if (xbmc.getInfoLabel("System.BuildVersion")[:1] == '9') or \
                        #   (xbmc.getInfoLabel("System.BuildVersion")[:2] == '10'):
                        listitem = xbmcgui.ListItem(name)
                        listitem.setInfo('video', {'Title': name})
                        self.pls.add(url=loc_url, listitem=listitem)
                        #else:
                        #    self.pls.add(loc_url, name)

                        if self.pls.size() == 1:
                            #start playing, continue loading
                            self.Attempt_to_play_URL(URL)
                            #xbmc.Player.play(self, self.pls)
                index = index + 1

            if self.pls.size() == 0:
                #no valid items found
                return {"code": 1, "data": "no valid items found"}

        return {"code": 0}
コード例 #17
0
ファイル: CInstaller.py プロジェクト: pmietlicki/kodi-repo
    def InstallApiPortail(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.URL
        
        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result["code"] == 0:
            self.URL = urlopener.loc_url
        
        SetInfoText("Telechargement... ", setlock=True)
        
        #download the file.
        loader = CFileLoader2()
        loader.load(self.URL, tempCacheDir + 'script.zip')
        if loader.state != 0:
            return -2
        filename = loader.localfile

        SetInfoText("Installing... ", setlock=True)

        #determine the install dir based on the current directory (root)
        if RootDir[0] == '/':
            pos =   RootDir.rfind("/",0,-1)
        else:
            pos =   RootDir.rfind("\\",0,-1)
            
        if pos != -1:
            InstallDir = RootDir[0:pos+1]

            print "Installation aPiPortail dans: " + InstallDir

            result = self.unzip_file_into_dir(filename, InstallDir)
            
            if result == 0: #remove pyo files (needed for XBMC Dharma)
                self.delPYOFiles(RootDir+'src')
            
        else:
            result = -1
        
        return result
コード例 #18
0
ファイル: CInstaller.py プロジェクト: lockers90/Isengard
    def InstallNaviX(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.URL
        
        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result["code"] == 0:
            self.URL = urlopener.loc_url
        
        SetInfoText("Downloading... ", setlock=True)
        
        #download the file.
        loader = CFileLoader2()
        loader.load(self.URL, tempCacheDir + 'script.zip')
        if loader.state != 0:
            return -2
        filename = loader.localfile

        SetInfoText("Installing... ", setlock=True)

        #determine the install dir based on the current Navi-X directory (root)
        if RootDir[0] == '/':
            pos =   RootDir.rfind("/",0,-1)
        else:
            pos =   RootDir.rfind("\\",0,-1)
            
        if pos != -1:
            InstallDir = RootDir[0:pos+1]

            print "Installing Navi-X in: " + InstallDir

            result = self.unzip_file_into_dir(filename, InstallDir)
            
            if result == 0: #remove pyo files (needed for XBMC Dharma)
                self.delPYOFiles(RootDir+'src')
            
        else:
            result = -1
        
        return result
コード例 #19
0
ファイル: CInstaller.py プロジェクト: Stevie-Bs/navi-x
    def InstallNaviX(self, URL="", mediaitem=CMediaItem()):
        if URL != "":
            self.URL = URL
        else:
            self.URL = mediaitem.URL

        urlopener = CURLLoader()
        result = urlopener.urlopen(self.URL, mediaitem)
        if result["code"] == 0:
            self.URL = urlopener.loc_url

        SetInfoText("Downloading... ", setlock=True)

        # download the file.
        loader = CFileLoader2()
        loader.load(self.URL, tempCacheDir + "script.zip")
        if loader.state != 0:
            return -2
        filename = loader.localfile

        SetInfoText("Installing... ", setlock=True)

        # determine the install dir based on the current Navi-X directory (root)
        if RootDir[0] == "/":
            pos = RootDir.rfind("/", 0, -1)
        else:
            pos = RootDir.rfind("\\", 0, -1)

        if pos != -1:
            InstallDir = RootDir[0 : pos + 1]

            print "Installing Navi-X in: " + InstallDir

            result = self.unzip_file_into_dir(filename, InstallDir)

            if result == 0:  # remove pyo files (needed for XBMC Dharma)
                self.delPYOFiles(RootDir + "src")

        else:
            result = -1

        return result
コード例 #20
0
ファイル: CPlayer.py プロジェクト: bialagary/mw
    def play(self, playlist, first, last):
        self.pls.clear()

        if first == last:
            URL = playlist.list[first].URL
            self.Attempt_to_play_URL(URL)
            # xbmc.Player.play(self, URL)
        else:

            index = first
            urlopener = CURLLoader()
            self.stopped = False
            while (index <= last) and (self.stopped == False) and (self.pls.size() < 10):
                type = playlist.list[index].type
                if type == "video" or type == "audio":
                    URL = playlist.list[index].URL

                    result = urlopener.urlopen(URL, playlist.list[index])
                    if result["code"] == 0:
                        loc_url = urlopener.loc_url

                        name = playlist.list[index].name

                        # if (xbmc.getInfoLabel("System.BuildVersion")[:1] == '9') or \
                        #   (xbmc.getInfoLabel("System.BuildVersion")[:2] == '10'):
                        listitem = xbmcgui.ListItem(name)
                        listitem.setInfo("video", {"Title": name})
                        self.pls.add(url=loc_url, listitem=listitem)
                        # else:
                        #    self.pls.add(loc_url, name)

                        if self.pls.size() == 1:
                            # start playing, continue loading
                            self.Attempt_to_play_URL(URL)
                            # xbmc.Player.play(self, self.pls)
                index = index + 1

            if self.pls.size() == 0:
                # no valid items found
                return {"code": 1, "data": "no valid items found"}

        return {"code": 0}
コード例 #21
0
    def play_URL(self, URL, mediaitem=0):
        #URL=mediaitem.URL
        #check if the URL is empty or not
        if URL == '':
            return {"code": 1, "data": "URL is empty"}

        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, mediaitem)
        if result["code"] != 0:
            return result
        URL = urlopener.loc_url

        SetInfoText("Loading...... ", setlock=True)

        self.pls.clear()  #clear the playlist

        ext = getFileExtension(URL)
        #todo ashx
        if ext == 'ashx':
            ext = 'm3u'

        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2()  #file loader
            loader.load(URL, tempCacheDir + "playlist." + ext, retries=2)
            if loader.state == 0:  #success
                result = self.pls.load(loader.localfile)
                if result == False:
                    return {"code": 1}

                #xbmc.Player.play(self, self.pls) #play the playlist
                self.play_media(loader.localfile)
        else:
            #self.pls.add(urlopener.loc_url)
            if mediaitem.playpath != '':
                self.play_RTMP(mediaitem.URL, mediaitem.playpath,
                               mediaitem.swfplayer, mediaitem.pageurl)
            else:
                self.play_media(URL)

        return {"code": 0}
コード例 #22
0
 def InstallPlugin(self, URL='', mediaitem=CMediaItem()):            
     if URL != '':
         self.URL = URL
     else:
         self.URL = mediaitem.URL
     
     dialog=xbmcgui.DialogProgress()
     dialog.create("Installer")
     dialog.update(33,"Downloading file...")        
     
     urlopener = CURLLoader()
     result = urlopener.urlopen(self.URL, mediaitem)
     if result == 0:
         self.URL = urlopener.loc_url
     
     
     #retrieve the type of plugin
     index=mediaitem.type.find(":")
     if index != -1:
         subdir = mediaitem.type[index+1:] + '\\'
     else:
         subdir = ''
            
     #download the file.
     loader = CFileLoader()
     loader.load(self.URL, cacheDir + 'plugin.zip', content_type='zip')
     if loader.state != 0:
         if loader.state == -2:
             dialog = xbmcgui.Dialog()
             dialog.ok(" Installer", "Failed. Not a ZIP file.", "Use the standard Download feature.")
         return -2
     filename = loader.localfile
     
     dialog.update(66,"Installing...")
     
     result = self.unzip_file_into_dir(filename, pluginDir + subdir)    
    
     dialog.close()
    
     return result
コード例 #23
0
    def play(self, playlist, first, last):
        self.pls.clear()

        if first == last:
            URL = playlist.list[first].URL
            xbmc.Player.play(self, URL)
        else:

            index = first
            urlopener = CURLLoader()
            self.stopped = False
            while index <= last and self.stopped == False and self.pls.size(
            ) < 100:
                type = playlist.list[index].type
                if type == 'video' or type == 'audio':
                    URL = playlist.list[index].URL

                    result = urlopener.urlopen(URL, playlist.list[index])
                    if result == 0:
                        loc_url = urlopener.loc_url

                        name = playlist.list[index].name

                        if version == '9':
                            listitem = xbmcgui.ListItem(name)
                            listitem.setInfo('video', {'Title': name})
                            self.pls.add(url=loc_url, listitem=listitem)
                        else:
                            self.pls.add(loc_url, name)

                        if self.pls.size() == 1:
                            #start playing
                            xbmc.Player.play(self, self.pls)
                index = index + 1

            if self.pls.size() == 0:
                #no valid items found
                return -1

        return 0
コード例 #24
0
ファイル: CPlayer.py プロジェクト: drrlramsey/xbmc-addons
    def play(self, playlist, first, last):
        self.pls.clear()

        if first == last:
            URL = playlist.list[first].URL
            xbmc.Player.play(self, URL)
        else:
        
            index = first
            urlopener = CURLLoader()
            self.stopped=False
            while index <= last and self.stopped == False and self.pls.size() < 100:               
                type = playlist.list[index].type
                if type == 'video' or type == 'audio':
                    URL = playlist.list[index].URL

                    result = urlopener.urlopen(URL, playlist.list[index])
                    if result == 0:
                        loc_url = urlopener.loc_url

                        name = playlist.list[index].name
                        
                        if version == '9':  
                            listitem = xbmcgui.ListItem(name)
                            listitem.setInfo('video', {'Title': name})
                            self.pls.add(url=loc_url, listitem=listitem)                      
                        else:
                            self.pls.add(loc_url, name)
                        
                        if self.pls.size() == 1:
                            #start playing                        
                            xbmc.Player.play(self, self.pls)
                index = index + 1
            
            if self.pls.size() == 0:
                #no valid items found
                return -1
                
        return 0
コード例 #25
0
ファイル: CPlayer.py プロジェクト: Gemini88/addons
    def play_URL(self, URL, mediaitem=0):
        #URL=mediaitem.URL
        #check if the URL is empty or not
        if URL == '':
            return {"code":1, "data":"URL is empty"}
                                              
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, mediaitem)
        if result["code"] != 0:
            return result   
        URL = urlopener.loc_url
        
        SetInfoText("Loading...... ", setlock=True)

        self.pls.clear() #clear the playlist
                
        ext = getFileExtension(URL)
#todo ashx  
        if ext == 'ashx':
            ext = 'm3u'
               
        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2() #file loader
            loader.load(URL, tempCacheDir + "playlist." + ext, retries=2)
            if loader.state == 0: #success
                result = self.pls.load(loader.localfile)
                if result == False:
                    return {"code":1}
                    
                #xbmc.Player.play(self, self.pls) #play the playlist
                self.play_media(loader.localfile)
        else:
            #self.pls.add(urlopener.loc_url)
            if mediaitem.playpath != '':
                self.play_RTMP(mediaitem.URL, mediaitem.playpath, mediaitem.swfplayer, mediaitem.pageurl);
            else: 
                self.play_media(URL)
            
        return {"code":0}
コード例 #26
0
ファイル: CInstaller.py プロジェクト: lockers90/Isengard
 def InstallPlugin(self,URL='',mediaitem=CMediaItem()):            
     if URL != '':
         self.URL=URL
     else:
         self.URL=mediaitem.URL
     
     urlopener=CURLLoader()
     result=urlopener.urlopen(self.URL,mediaitem)
     if result["code"] == 0:
         self.URL=urlopener.loc_url
     
     
     #retrieve the type of plugin
     index=mediaitem.type.find(":")
     if index != -1:
         subdir=mediaitem.type[index+1:]+'\\'
     else:
         subdir=''
     
     SetInfoText("Downloading... ",setlock=True)
     
     #download the file.
     loader=CFileLoader2()
     loader.load(self.URL,tempCacheDir+'plugin.zip',content_type='zip')
     if loader.state != 0:
         if loader.state == -2:
             dialog=xbmcgui.Dialog()
             dialog.ok(" Installer","Failed. Not a ZIP file.","Use the standard Download feature.")
         return -2
     filename=loader.localfile
     
     SetInfoText("Installing... ", setlock=True)
     
     result=self.unzip_file_into_dir(filename,pluginDir+subdir)
     
     xbmc.executebuiltin("XBMC.UpdateLocalAddons()"); 
     
     return result
コード例 #27
0
ファイル: CInstaller.py プロジェクト: pmietlicki/kodi-repo
 def InstallPlugin(self, URL='', mediaitem=CMediaItem()):            
     if URL != '':
         self.URL = URL
     else:
         self.URL = mediaitem.URL
     
     urlopener = CURLLoader()
     result = urlopener.urlopen(self.URL, mediaitem)
     if result["code"] == 0:
         self.URL = urlopener.loc_url
     
     
     #retrieve the type of plugin
     index=mediaitem.type.find(":")
     if index != -1:
         subdir = mediaitem.type[index+1:] + '\\'
     else:
         subdir = ''
     
     SetInfoText("Downloading... ", setlock=True)
     
     #download the file.
     loader = CFileLoader2()
     loader.load(self.URL, tempCacheDir + 'plugin.zip', content_type='zip')
     if loader.state != 0:
         if loader.state == -2:
             dialog = xbmcgui.Dialog()
             dialog.ok(" Installeur", "Echec. Pas un fichier ZIP.", "Use the standard Download feature.")
         return -2
     filename = loader.localfile
     
     SetInfoText("Installation... ", setlock=True)
     
     result = self.unzip_file_into_dir(filename, pluginDir + subdir)    
                  
     return result
コード例 #28
0
    def play_URL(self, URL):
        #check if the URL is empty or not
        if URL == '':
            return -1
    
        self.pls.clear() #clear the playlist
    
        ext = getFileExtension(URL)
        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2() #file loader
            loader.load(URL, cacheDir + "playlist." + ext)
            if loader.state == 0: #success
                result = self.pls.load(loader.localfile)
                if result == False:
                    return -1
        else:
            urlopener = CURLLoader()
            result = urlopener.urlopen(URL)
            if result != 0:
                return -1
            self.pls.add(urlopener.loc_url)

        xbmc.Player.play(self, self.pls)
        return 0
コード例 #29
0
            cookies = ''
            if URL.find(nxserver_URL) != -1:
                cookies = 'platform=' + platform + '; version=' + Version + '.' + SubVersion
                cookies = cookies + '; nxid=' + nxserver.user_id
                headers = {
                    'User-Agent':
                    'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4',
                    'Cookie': cookies
                }
                #headers={'User-Agent':'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)','Cookie':cookies}
        except Exception, e:
            print('ERROR line 397 cookies ' + str(e))
            #print 'headers =    ' + str(headers)

        #Get the direct URL to the mediaitem given URL
        urlopener = CURLLoader()
        self.processed = urlopener.processed  #### needed or will fault the next line at times
        entry.processed = self.processed
        try:
            result = urlopener.urlopen(URL, entry)
            if result["code"] != 0:
                self.state = -1  #failed to open the file
                print("urlopener.urlopen failed line 408  " + str(result))
                line2 = '%s  %s' % ('failed to open', str(entry.name))
                self.MainWindow.dlinfotekst.setLabel(line2)
                return
        except Exception, e:
            self.state = -1  #failed to open the file
            print("urlopener.urlopen failed line 414  " + str(e))
            line2 = '%s  %s' % ('failed to open', str(entry.name))
            self.MainWindow.dlinfotekst.setLabel(line2)
コード例 #30
0
ファイル: CDownLoader.py プロジェクト: drrlramsey/xbmc-addons
    def download_file(self, entry, header=""):
        self.state = 0 #success
        
        URL = entry.URL
        localfile = entry.DLloc     
        
        #download of FTP file is handled in a separte function
        if URL[:3] == 'ftp':
            self.download_fileFTP(entry, header)
            return
        
        if URL[:4] != 'http':
            self.state = -1 #URL does not point to internet file.
            return

        #Continue with HTTP download
        self.MainWindow.dlinfotekst.setLabel('(' + header + ')' + " Retrieving file info...") 

        #Get the direct URL to the mediaitem given URL      
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, entry)
        if result != 0:
            self.state = -1 #failed to download the file
            return        

        URL = urlopener.loc_url
              
        try:
#            oldtimeout=socket_getdefaulttimeout()
#            socket_setdefaulttimeout(url_open_timeout)

            existSize=0 #existing size = 0 Bytes

            if os.path.exists(localfile):
                #Append to the existing file. Because opening a file for append no longer works,
                #we need to copy the existing file in a new file.
                self.MainWindow.dlinfotekst.setLabel("Preparing append to file...")            
                existSize = os.path.getsize(localfile)
                
                #Message("Exist size: " + str(existSize))
                
                backupfile = localfile[0:-1] + '~'
                os.rename(localfile, backupfile)
                
                file2 = open(backupfile, "rb")
                file = open(localfile, "wb")
                bytes= 0
                while (bytes < existSize):
                    chunk = 100 * 1024
                    if (bytes + chunk) > existSize:
                        chunk = existSize-bytes #remainder
                    file.write(file2.read(chunk))
                    bytes = bytes + chunk

                    percent = 100 * bytes / existSize
                    line2 = '(%s) - %d ' % (header, percent) + '%' + ' Append...' 
                    self.MainWindow.dlinfotekst.setLabel(line2)
            
                file2.close()                
                os.remove(backupfile)
               
                #If the file exists, then only download the remainder 
                headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)',
                            'Range' : 'bytes=%s-' % existSize}                          

            else: 
                #file does not exist 
                file = open(localfile, "wb")           
                headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
            
            #destination is already open            

            self.MainWindow.dlinfotekst.setLabel('(' + header + ')' + " Downloading file...")  
            
            req = urllib2.Request(URL, None, headers)
            f = urllib2.urlopen(req)            
                        
            #If the file exists, but we already have the whole thing, don't download again
            size_string = f.headers['Content-Length']
            size = int(size_string) #The remaining bytes
            
            #Message("Remaining: " + str(size))
                        
#todo: size may be existsize if file is downloaded exactly 50%            
            if (size > 0) and (size != existSize):
                bytes = existSize #bytes downloaded already
                size = size + existSize #total size
                #Message("Total: " + str(size))
                
                size_MB = float(size) / (1024 * 1024) #total size MB

                #DL-speed calculation
                starttime = time.time()
                startsize = bytes
                deltatime = 0
                deltasize = 0
                dlspeed = 0

                #download in chunks of 100kBytes                
                while (bytes < size) and (self.killed == False) and (self.running == True):
                    chunk = 100 * 1024 #100kBytes chunks
                    if (bytes + chunk) > size:
                        chunk = size-bytes #remainder
                    #data = f.read(chunk)
                    file.write(f.read(chunk))
                    bytes = bytes + chunk
                            
                    percent = 100 * bytes / size
                    done = float(bytes) / (1024 * 1024)
                    
                    deltatime = time.time() - starttime
                    if deltatime >=5: #update every 5 seconds
                        #calculate the download speed                        
                        deltasize = bytes - startsize
                        dlspeed = (deltasize / 1024) / deltatime                        
                        starttime = time.time()
                        startsize = bytes
                    
                    line2 = '(%s) %.1f MB - %d%% - %dkB/s' % (header, size_MB, percent, dlspeed)
                    self.MainWindow.dlinfotekst.setLabel(line2)
                
                f.close() #close the URL
                file.close() #close the destination file                 

                if (self.killed == True) or (self.running == False):
                    self.state = -2 #failed to download the file
                        
        except IOError:        
            self.state = -1 #failed to download the file
            return

        file.close() #close the destination file  
#        socket_setdefaulttimeout(oldtimeout)
  
        #add the downloaded file to the download list
        if self.state == 0:
            tmp = CMediaItem() #create new item
            tmp.type = entry.type
            tmp.name = entry.name
            tmp.thumb = entry.thumb
            tmp.URL = entry.DLloc
            tmp.player = entry.player
            self.playlist_dst.add(tmp)
            self.playlist_dst.save(RootDir + downloads_complete)
コード例 #31
0
ファイル: CDownLoader.py プロジェクト: whf839/xbmc-addons
    def browse(self, entry, dir=myDownloadsDir):
        self.state = 0 #success
        self.dir = ''
       
        URL=entry.URL

        if URL[:4] != 'http':
            self.state = -1 #URL does not point to internet file.
            return

        urlopener = CURLLoader()
        result = urlopener.urlopen(URL)
        if result != 0:
            self.state = -1 #URL does not point to internet file.
            return
        loc_url = urlopener.loc_url

        #Now we try to open the URL. If it does not exist an error is
        #returned.
#        try:
#            oldtimeout=socket.getdefaulttimeout()
#            socket.setdefaulttimeout(url_open_timeout)

#            values = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
#            req = urllib2.Request(loc_url, None, values)
#            f = urllib2.urlopen(req)
#            loc_url=f.geturl()
#            socket.setdefaulttimeout(oldtimeout)

#        except IOError:
#            socket.setdefaulttimeout(oldtimeout)
#            self.state = -1 #failed to open URL
#            return
            
        #special handing for some URL's
        pos = URL.find('http://youtube.com/v') #find last 'http' in the URL
        if pos != -1:
            ext='.mp4'
        else:
            pos = URL.find("flyupload.com")
            if pos != -1:
                ext='.avi'
            else:
                #strip the file extension
                pos = loc_url.rfind('.') #find last '.' in the string
                if pos != -1:
                    ext = loc_url[pos:] #the file extension
                else:
                    ext = ""
               
        #For the local file name we use the playlist item 'name' field.
        #But this string may contain invalid characters. Therefore
        #we strip these invalid characters. We also limit the file
        #name length to 42 which is the XBMC limit.
        localfile = entry.name.replace('<',"")
        localfile = localfile.replace('>',"")
        localfile = localfile.replace('=',"")
        localfile = localfile.replace('?',"")
        localfile = localfile.replace(':',"")
        localfile = localfile.replace(';',"")
        localfile = localfile.replace('"',"")
        localfile = localfile.replace('*',"")
        localfile = localfile.replace('+',"")
        localfile = localfile.replace(',',"")
        localfile = localfile.replace('/',"")
        localfile = localfile.replace('|',"")
        localfile = localfile[:(42-len(ext))] #limit to 42 characters.
        localfile = localfile + ext
                
        browsewnd = CDialogBrowse()
        browsewnd.SetFile(dir, localfile, 3)
        browsewnd.doModal()

        if browsewnd.state != 0:
            self.state = -2 #cancel download
            return
        
        self.localfile = browsewnd.dir + browsewnd.filename
        self.dir = browsewnd.dir
        
        #Check if the file already exists
        if os.path.exists(self.localfile):
            dialog = xbmcgui.Dialog()
            if dialog.yesno("Message", "The destination file already exists, continue?") == False:
                self.state = -2 #cancel download
コード例 #32
0
ファイル: CDownLoader.py プロジェクト: cyberwarrior/dmind
    def read_file_info(self, entry):
        self.state = 0 #success    
        ext='' #no extension
        size = 0
        try:
            URL, headers = parse_headers(entry.URL)
        
            if URL[:3] == 'ftp':
                #FTP
                ext = getFileExtension(URL)
                if ext != '':
                    ext = '.' + ext
            else:
                #HTTP
                urlopener = CURLLoader()
                result = urlopener.urlopen(URL, entry);
                if result["code"] != 0:
                    self.state = -1; print('URL does not point to internet file.')
                    return ext, size
                loc_url = urlopener.loc_url#; print('line223 loc_url= ' +str(loc_url))
                self.processed=urlopener.processed#; print('self.processed= ' +str(self.processed))

                #Now we try to open the URL. If it does not exist an error is
                #returned.
                try:
                    #headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
                    req = urllib2.Request(loc_url, None, headers)
                    size_string,size_raw = self.file_size(0,req)
                    size = int(size_raw)
                except Exception, e: size = 0; print('ERROR line 237' +str(e))
                #loc_url=f.geturl()
                try:
                    #special handing for some URL's
                    pos = URL.find('http://www.youtube.com') #find last 'http' in the URL
                    if pos != -1:
                        ext='.mp4'
                    else:
          #todo: deprecated            
                        pos = URL.find("flyupload.com")
                        if pos != -1:
                            ext='.avi'
                        else:                             
                            #extract the file extension
                            url_stripped = re.sub('\?.*$', '', loc_url) # strip GET-method args
                            re_ext = re.compile('(\.\w+)$') # find extension
                            match = re_ext.search(url_stripped)
                            if match is None:
                                #ext = ""
                                ext = getFileExtension(loc_url)
                                if ext != '':
                                    ext = '.' + ext
                            else:
                                ext = match.group(1)
                except Exception, e: print('ERROR line 261','e =' +str(e))
            # processed youtube URL
    #the code below is failing. Do we still need it?
    #            match=re.search('youtube\.com/.*?&itag=(\d+)', loc_url)
    #            if match:
    #               fmt=int(match.group(1))
    #                if [5,6,34,35].index(fmt) >= 0:
    #                    ext='.flv'
    #                elif [43,44,45,46,100,101,46,102].index(fmt) >= 0:
    #                    ext='.webm'
    #                else:
    #                    ext='.mp4' # [18,22,37,38,83,82,85,84] - default to instead of testing for

            # safety net
            if len(ext)>6:
                ext='.avi'
        except Exception,e:
            print '\t\t\t Error CDL 278 ' + str(e)
コード例 #33
0
    def play_URL(self, URL, mediaitem=0):
        #URL=mediaitem.URL
        #check if the URL is empty or not
        if URL == '':
            return {"code":1, "data":"URL is empty"}
                                              
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, mediaitem)
        addon = xbmcaddon.Addon(id='script.navi-x')
        if (result["code"] != 0) and (addon.getSetting("pyload_enabled")=="true"):
            try:
				downloader = PYLoader()
				session = downloader.login()
				downloadable = downloader.send(session, "checkURLs", urls=[URL])
				#print downloadable
				if not "BasePlugin" in downloadable:
				    result = downloader.send(session, "addPackage", name=mediaitem.name.strip(), links=[URL])
				    #print result
				    fileid = downloader.send(session, "getPackageData", pid=result)
				    fileid = downloader.parse_json(fileid)
				    folder = fileid["folder"]
				    #fileinfo = downloader.send(session, "getFileData", fid=fileid["links"][0]["fid"])
				    #fileinfo = downloader.parse_json(fileinfo)
				    #print fileinfo
				    #downloader.setallcaptcha(session)
				    download_folder = downloader.send(session, "getConfigValue", category="general", option="download_folder")
				    download_folder = download_folder.replace('"','')
				    time.sleep(10)
				    captcha = downloader.send(session, "isCaptchaWaiting")
				    if captcha == "true":
				        dialog = xbmcgui.Dialog()
				        dialog.ok('Captcha en attente', "Veuillez vous connecter sur http://"+iptools.get_lan_ip()+":"+addon.getSetting("ip_port")+" pour le rentrer.")
				    #print download_folder
				    time.sleep(10)
				    fileinfo = downloader.send(session, "getFileData", fid=fileid["links"][0]["fid"])
				    fileinfo = downloader.parse_json(fileinfo)
					#print "fileinfo", fileinfo
				    dialog = xbmcgui.Dialog()
				    dialog.ok('Telechargement en cours', "Veuillez vous connecter sur http://"+iptools.get_lan_ip()+":"+addon.getSetting("ip_port")+" pour plus d\'informations.")
				    #status = downloader.send(session, "statusDownloads")
					#status = downloader.parse_json(status)
				    #print status
				    try:
				        self.play_media(xbmc.translatePath("file:///"+download_folder+"/"+folder+"/"+fileinfo["name"]+".chunk0"))
				    except IOError:
				        #print 'Fichier inexistant.'
                                        return result
            except:
                 return result

        URL = urlopener.loc_url
        
        SetInfoText("Loading...... ", setlock=True)

        self.pls.clear() #clear the playlist
                
        ext = getFileExtension(URL)
        #todo ashx  
        if ext == 'ashx':
            ext = 'm3u'
               
        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2() #file loader
            loader.load(URL, tempCacheDir + "playlist." + ext, retries=2)
            if loader.state == 0: #success
                result = self.pls.load(loader.localfile)
                if result == False:
                    return {"code":1}
                    
                #xbmc.Player.play(self, self.pls) #play the playlist
                self.play_media(loader.localfile)
        else:
            #self.pls.add(urlopener.loc_url)
            if mediaitem.playpath != '':
                self.play_RTMP(mediaitem.URL, mediaitem.playpath, mediaitem.swfplayer, mediaitem.pageurl);
            else: 
                self.play_media(URL)
            
        return {"code":0}
コード例 #34
0
    def download_file(self, entry, header=""):
        self.state = 0  #success

        URL = entry.URL
        localfile = entry.DLloc

        #download of FTP file is handled in a separte function
        if URL[:3] == 'ftp':
            self.download_fileFTP(entry, header)
            return

        if URL[:4] != 'http':
            self.state = -1  #URL does not point to internet file.
            return

        #Continue with HTTP download
        self.MainWindow.dlinfotekst.setLabel('(' + header + ')' +
                                             " Retrieving file info...")

        #Get the direct URL to the mediaitem given URL
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, entry)
        if result != 0:
            self.state = -1  #failed to download the file
            return

        URL = urlopener.loc_url

        try:
            #            oldtimeout=socket_getdefaulttimeout()
            #            socket_setdefaulttimeout(url_open_timeout)

            existSize = 0  #existing size = 0 Bytes

            if os.path.exists(localfile):
                #Append to the existing file. Because opening a file for append no longer works,
                #we need to copy the existing file in a new file.
                self.MainWindow.dlinfotekst.setLabel(
                    "Preparing append to file...")
                existSize = os.path.getsize(localfile)

                #Message("Exist size: " + str(existSize))

                backupfile = localfile[0:-1] + '~'
                os.rename(localfile, backupfile)

                file2 = open(backupfile, "rb")
                file = open(localfile, "wb")
                bytes = 0
                while (bytes < existSize):
                    chunk = 100 * 1024
                    if (bytes + chunk) > existSize:
                        chunk = existSize - bytes  #remainder
                    file.write(file2.read(chunk))
                    bytes = bytes + chunk

                    percent = 100 * bytes / existSize
                    line2 = '(%s) - %d ' % (header,
                                            percent) + '%' + ' Append...'
                    self.MainWindow.dlinfotekst.setLabel(line2)

                file2.close()
                os.remove(backupfile)

                #If the file exists, then only download the remainder
                headers = {
                    'User-Agent':
                    'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)',
                    'Range': 'bytes=%s-' % existSize
                }

            else:
                #file does not exist
                file = open(localfile, "wb")
                headers = {
                    'User-Agent':
                    'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'
                }

            #destination is already open

            self.MainWindow.dlinfotekst.setLabel('(' + header + ')' +
                                                 " Downloading file...")

            req = urllib2.Request(URL, None, headers)
            f = urllib2.urlopen(req)

            #If the file exists, but we already have the whole thing, don't download again
            size_string = f.headers['Content-Length']
            size = int(size_string)  #The remaining bytes

            #Message("Remaining: " + str(size))

            #todo: size may be existsize if file is downloaded exactly 50%
            if (size > 0) and (size != existSize):
                bytes = existSize  #bytes downloaded already
                size = size + existSize  #total size
                #Message("Total: " + str(size))

                size_MB = float(size) / (1024 * 1024)  #total size MB

                #DL-speed calculation
                starttime = time.time()
                startsize = bytes
                deltatime = 0
                deltasize = 0
                dlspeed = 0

                #download in chunks of 100kBytes
                while (bytes < size) and (self.killed
                                          == False) and (self.running == True):
                    chunk = 100 * 1024  #100kBytes chunks
                    if (bytes + chunk) > size:
                        chunk = size - bytes  #remainder
                    #data = f.read(chunk)
                    file.write(f.read(chunk))
                    bytes = bytes + chunk

                    percent = 100 * bytes / size
                    done = float(bytes) / (1024 * 1024)

                    deltatime = time.time() - starttime
                    if deltatime >= 5:  #update every 5 seconds
                        #calculate the download speed
                        deltasize = bytes - startsize
                        dlspeed = (deltasize / 1024) / deltatime
                        starttime = time.time()
                        startsize = bytes

                    line2 = '(%s) %.1f MB - %d%% - %dkB/s' % (header, size_MB,
                                                              percent, dlspeed)
                    self.MainWindow.dlinfotekst.setLabel(line2)

                f.close()  #close the URL
                file.close()  #close the destination file

                if (self.killed == True) or (self.running == False):
                    self.state = -2  #failed to download the file

        except IOError:
            self.state = -1  #failed to download the file
            return

        file.close()  #close the destination file
        #        socket_setdefaulttimeout(oldtimeout)

        #add the downloaded file to the download list
        if self.state == 0:
            tmp = CMediaItem()  #create new item
            tmp.type = entry.type
            tmp.name = entry.name
            tmp.thumb = entry.thumb
            tmp.URL = entry.DLloc
            tmp.player = entry.player
            self.playlist_dst.add(tmp)
            self.playlist_dst.save(RootDir + downloads_complete)
コード例 #35
0
ファイル: CDownLoader.py プロジェクト: bialagary/mw
    def browse(self, entry, dir=myDownloadsDir):
        self.state = 0 #success
        self.dir = ''
        self.processed=False
       
        URL=entry.URL

        if (URL[:4] != 'http') and (URL[:3] != 'ftp'):
            self.state = -1 #URL does not point to internet file.
            return

        if re.search('^http://(\w+\.)?(icefilms|mega(upload|video))\.', URL):
            size_check_skip=True
        else:
            size_check_skip=False
            
        if size_check_skip:
            print("Mega URL; skipping size check")
            size=0
            urlopener = CURLLoader()
            result = urlopener.geturl_processor(entry)
            URL=entry.URL
            loc_url=URL
            self.processed=entry.processed          
            self.loc_url=URL
            url_stripped = re.sub('\?.*$', '', loc_url) # strip GET-method args
            url_stripped = re.sub('\|.*$', '', url_stripped) # strip header info if any
            # find extension
            match = re.search('(\.\w+)$',url_stripped)
            if match is None:
                #ext = ""
                ext = getFileExtension(loc_url)
                if ext != '':
                    ext = '.' + ext
            else:
                ext = match.group(1)
        else:
            ext, size = self.read_file_info(entry)
            url_stripped = re.sub('\?.*$', '', entry.URL) # strip GET-method args
            url_stripped = re.sub('\&.*$', '', entry.URL) # strip odd GET-method args
            url_stripped = re.sub('\|.*$', '', url_stripped) # strip header info if any

        if self.state != 0:
            return
               
        # For the local file name we use the playlist item 'name' field.
        # But this string may contain invalid characters. Therefore
        # we strip these invalid characters. We also limit the file
        # name length to 42 which is the XBMC XBOX limit.

        if re.search('^Source #', entry.name):
            localfile=url_stripped[url_stripped.rindex("/")+1:]
        else:
            localfile = re.sub('[^\w\s-]', '', entry.name) # remove characters which are not a letter, digit, white-space, underscore, or dash
            localfile = re.sub('\s+', ' ', localfile) # convert all instances of multiple spaces to single spaces
            localfile = localfile[:(42-len(ext))] # limit to 42 characters.
            localfile = localfile + ext
        
        if size_check_skip:
            heading="Download File"
        else:
            size_string, raw_size = self.file_size(size,'')
            heading = "Download File: (Size = %s)" % size_string
            
        if (entry.type=='playlist') and (localfile.lower().endswith('.plx')==False):
            localfile+='.plx'
        
        #browsewnd = CDialogBrowse("CBrowseskin.xml", os.getcwd())
        curdir = addon.getAddonInfo('path')
        browsewnd = CDialogBrowse("CBrowseskin2.xml", curdir)
        browsewnd.SetFile(dir, localfile, 3, heading)
        browsewnd.doModal()

        if browsewnd.state != 0:
            self.state = -2 #cancel download
            return
        
        self.localfile = browsewnd.dir + browsewnd.filename
        self.dir = browsewnd.dir
        
        #Check if the file already exists
        if os.path.exists(self.localfile):
            dialog = xbmcgui.Dialog()
            if dialog.yesno("Message", "The destination file already exists, continue?") == False:
                self.state = -2 #cancel download
コード例 #36
0
ファイル: CDownLoader.py プロジェクト: bialagary/mw
    def read_file_info(self, entry):
        self.state = 0 #success    
        ext='' #no extension
        size = 0
        try:
            URL, headers = parse_headers(entry.URL)
        
            if URL[:3] == 'ftp':
                #FTP
                ext = getFileExtension(URL)
                if ext != '':
                    ext = '.' + ext
            else:
                #HTTP
                urlopener = CURLLoader()
                result = urlopener.urlopen(URL, entry);
                if result["code"] != 0:
                    self.state = -1; print('URL does not point to internet file.')
                    return ext, size
                loc_url = urlopener.loc_url#; print('line223 loc_url= ' +str(loc_url))
                self.processed=urlopener.processed#; print('self.processed= ' +str(self.processed))

                #Now we try to open the URL. If it does not exist an error is
                #returned.
                try:
                    #headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
                    req = urllib2.Request(loc_url, None, headers)
                    size_string,size_raw = self.file_size(0,req)
                    size = int(size_raw)
                except Exception, e: size = 0; print('ERROR line 237' +str(e))
                #loc_url=f.geturl()
                try:
                    #special handing for some URL's
                    pos = URL.find('http://www.youtube.com') #find last 'http' in the URL
                    if pos != -1:
                        ext='.mp4'
                    else:
          #todo: deprecated            
                        pos = URL.find("flyupload.com")
                        if pos != -1:
                            ext='.avi'
                        else:                             
                            #extract the file extension
                            url_stripped = re.sub('\?.*$', '', loc_url) # strip GET-method args
                            re_ext = re.compile('(\.\w+)$') # find extension
                            match = re_ext.search(url_stripped)
                            if match is None:
                                #ext = ""
                                ext = getFileExtension(loc_url)
                                if ext != '':
                                    ext = '.' + ext
                            else:
                                ext = match.group(1)
                except Exception, e: print('ERROR line 261','e =' +str(e))
            # processed youtube URL
    #the code below is failing. Do we still need it?
    #            match=re.search('youtube\.com/.*?&itag=(\d+)', loc_url)
    #            if match:
    #               fmt=int(match.group(1))
    #                if [5,6,34,35].index(fmt) >= 0:
    #                    ext='.flv'
    #                elif [43,44,45,46,100,101,46,102].index(fmt) >= 0:
    #                    ext='.webm'
    #                else:
    #                    ext='.mp4' # [18,22,37,38,83,82,85,84] - default to instead of testing for

            # safety net
            if len(ext)>6:
                ext='.avi'
        except Exception,e:
            print '\t\t\t Error CDL 278 ' + str(e)
コード例 #37
0
ファイル: CPlayer.py プロジェクト: pmietlicki/kodi-repo
    def play_URL(self, URL, mediaitem=0):
        #URL=mediaitem.URL
        #check if the URL is empty or not
        if URL == '':
            return {"code":1, "data":"URL is empty"}
                                              
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, mediaitem)
        addon = xbmcaddon.Addon(id='script.apiportal')
        #Pb de latences sur ce code voir si indispensable
#        if (result["code"] != 0) and (addon.getSetting("pyload_enabled")=="true"):
#            try:
#                downloader = PYLoader()
#                session = downloader.login()
#                downloadable = downloader.send(session, "checkURLs", urls=[URL])
#                if not "BasePlugin" in downloadable:
#                    result = downloader.send(session, "addPackage", name=mediaitem.name.strip(), links=[URL])
#                    fileid = downloader.send(session, "getPackageData", pid=result)
#                    fileid = downloader.parse_json(fileid)
#                    folder = fileid["folder"]
#                    download_folder = downloader.send(session, "getConfigValue", category="general", option="download_folder")
#                    download_folder = download_folder.replace('"','')
#                    time.sleep(10)
#                    captcha = downloader.send(session, "isCaptchaWaiting")
#                    if captcha == "true":
#                        dialog = xbmcgui.Dialog()
#                        dialog.ok('Captcha en attente', "Veuillez vous connecter sur http://"+iptools.get_lan_ip()+":"+addon.getSetting("ip_port")+" pour le rentrer.")
#                    time.sleep(10)
#                    fileinfo = downloader.send(session, "getFileData", fid=fileid["links"][0]["fid"])
#                    fileinfo = downloader.parse_json(fileinfo)
#                    dialog = xbmcgui.Dialog()
#                    dialog.ok('Telechargement en cours', "Veuillez vous connecter sur http://"+iptools.get_lan_ip()+":"+addon.getSetting("ip_port")+" pour plus d\'informations.")
#                    try:
#                        self.play_media(xbmc.translatePath("file:///"+download_folder+"/"+folder+"/"+fileinfo["name"]+".chunk0"))
#                    except IOError:
#                        return result
#            except:
#                return result

        try:
            URL = urlopener.loc_url
        except AttributeError:
            URL = URL
        
        SetInfoText("Loading...... ", setlock=True)

        self.pls.clear() #clear the playlist
                
        ext = getFileExtension(URL)
        #todo ashx  
        if ext == 'ashx':
            ext = 'm3u'
               
        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2() #file loader
            loader.load(URL, tempCacheDir + "playlist." + ext, retries=2)
            if loader.state == 0: #success
                result = self.pls.load(loader.localfile)
                if result == False:
                    return {"code":1}
                    
                #xbmc.Player.play(self, self.pls) #play the playlist
                self.play_media(loader.localfile)
        else:
            #self.pls.add(urlopener.loc_url)
            if mediaitem.playpath != '':
                self.play_RTMP(mediaitem.URL, mediaitem.playpath, mediaitem.swfplayer, mediaitem.pageurl);
            else: 
                self.play_media(URL)
        
        if not (xbmc.Player().isPlaying()):
            return {"code":1,"error":"unable to play this item"} 
            
        return {"code":0}
コード例 #38
0
    def DownLoadSpeedTest(self, entry):
        #Get the direct URL to the mediaitem given URL
        urlopener = CURLLoader()
        result = urlopener.urlopen(entry.URL, entry)
        if result != 0:
            return -1

        URL = urlopener.loc_url

        dialog = xbmcgui.DialogProgress()
        dialog.create("Download Speed Test", entry.name)
        dialog.update(0, entry.name)

        try:
            bytes = 0
            chunk = 100 * 1024

            headers = {
                'User-Agent':
                'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'
            }
            req = urllib2.Request(URL, None, headers)
            f = urllib2.urlopen(req)

            size_string = f.headers['Content-Length']
            size = int(size_string)

            file = open(tempCacheDir + "dltest", "wb")
            starttime = time.time()
            deltatime = 0
            updatetime = 0

            while deltatime < 10:  #10 seconds
                if (dialog.iscanceled()):
                    break

                if (bytes >= size):  # got the complete file
                    break

                file.write(f.read(chunk))
                bytes = bytes + chunk

                deltatime = time.time() - starttime
                if (deltatime - updatetime) >= 1.0:
                    dialog.update(deltatime * 10, entry.name)
                    #dialog.update(deltatime*10, str(deltatime-updatetime))
                    updatetime = deltatime

            f.close()
            file.close()
            os.remove(tempCacheDir + "dltest")

        except IOError:
            pass

        dialog.close()

        if deltatime < 3:
            return -1  # failed because we need at least 3 seconds to have an accurate measurement

        if (deltatime < 10) and (bytes < size):
            return 0  #abort

        #calculate the download speed
        dlspeed = (bytes / 1024) / deltatime

        dialog = xbmcgui.Dialog()
        dialog.ok("Message", "Download speed: %d kBytes/s." % dlspeed)

        return 0
コード例 #39
0
ファイル: CDownLoader.py プロジェクト: bialagary/mw
    def DownLoadSpeedTest(self, entry):
        #Get the direct URL to the mediaitem given URL      
        urlopener = CURLLoader()
        result = urlopener.urlopen(entry.URL, entry)
        if result["code"] != 0:
            return -1       

        URL = urlopener.loc_url

        if URL[:3] == 'ftp':
            dialog = xbmcgui.Dialog()
            dialog.ok("Message", "FTP download speed test not supported.")
            return 0

        dialog = xbmcgui.DialogProgress()
        dialog.create("Download Speed Test", entry.name)        
        dialog.update(0, entry.name)
    
        #try:
        bytes= 0
        chunk = 100 * 1024
        
        #rembember the user agent set the processor
        index = URL.find('|User-Agent=')
        if index != -1:
            useragent = URL[index+12:]
            URL = URL[:index]
        else:
            useragent = 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'
        
        #headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
        headers = { 'User-Agent' : useragent}
        req = urllib2.Request(URL, None, headers)
        f = urllib2.urlopen(req)
        
        size_rb,size_raw = self.file_size(0,req)             ####
        #size_raw = f.headers['Content-Length']          ####
        size = int(size_raw)     
        
        file = open(tempCacheDir + "dltest", "wb")
        starttime = time.time()
        deltatime = 0
        updatetime = 0
    
        while deltatime < 10: #10 seconds
            if(dialog.iscanceled()):
                break
        
            if (bytes >= size): # got the complete file
                break;
        
            file.write(f.read(chunk))
            bytes = bytes + chunk
        
            deltatime = time.time() - starttime
            if (deltatime - updatetime) >= 1.0:
                dialog.update(int(deltatime*10), entry.name)            ####
                #dialog.update(deltatime*10, str(deltatime-updatetime))
                updatetime = deltatime

        f.close()
        file.close()                
        os.remove(tempCacheDir + "dltest")
                
        #except IOError:
            #pass
  
        dialog.close()        
        
        if deltatime < 3:
            return -1 # failed because we need at least 3 seconds to have an accurate measurement
        
        if (deltatime < 10) and (bytes < size):
            return 0 #abort
        
        #calculate the download speed
        dlspeed = (bytes / 1024) / deltatime
        
        dialog = xbmcgui.Dialog()
        dialog.ok("Message", "Download speed: %d kBytes/s." % dlspeed)
        
        return 0
コード例 #40
0
    def browse(self, entry, dir=myDownloadsDir):
        self.state = 0  #success
        self.dir = ''
        self.processed = False

        URL = entry.URL

        if (URL[:4] != 'http') and (URL[:3] != 'ftp'):
            self.state = -1  #URL does not point to internet file.
            return

        if re.search('^http://(\w+\.)?(icefilms|mega(upload|video))\.', URL):
            size_check_skip = True
        else:
            size_check_skip = False

        if size_check_skip:
            print("Mega URL; skipping size check")
            size = 0
            urlopener = CURLLoader()
            result = urlopener.geturl_processor(entry)
            URL = entry.URL
            loc_url = URL
            self.processed = entry.processed
            self.loc_url = URL
            url_stripped = re.sub('\?.*$', '',
                                  loc_url)  # strip GET-method args
            url_stripped = re.sub('\|.*$', '',
                                  url_stripped)  # strip header info if any
            # find extension
            match = re.search('(\.\w+)$', url_stripped)
            if match is None:
                #ext = ""
                ext = getFileExtension(loc_url)
                if ext != '':
                    ext = '.' + ext
            else:
                ext = match.group(1)
        else:
            ext, size = self.read_file_info(entry)
            url_stripped = re.sub('\?.*$', '',
                                  entry.URL)  # strip GET-method args
            url_stripped = re.sub('\&.*$', '',
                                  entry.URL)  # strip odd GET-method args
            url_stripped = re.sub('\|.*$', '',
                                  url_stripped)  # strip header info if any

        if self.state != 0:
            return

        # For the local file name we use the playlist item 'name' field.
        # But this string may contain invalid characters. Therefore
        # we strip these invalid characters. We also limit the file
        # name length to 42 which is the XBMC XBOX limit.

        if re.search('^Source #', entry.name):
            localfile = url_stripped[url_stripped.rindex("/") + 1:]
        else:
            localfile = re.sub(
                '[^\w\s-]', '', entry.name
            )  # remove characters which are not a letter, digit, white-space, underscore, or dash
            localfile = re.sub(
                '\s+', ' ', localfile
            )  # convert all instances of multiple spaces to single spaces
            localfile = localfile[:(42 - len(ext))]  # limit to 42 characters.
            localfile = localfile + ext

        if size_check_skip:
            heading = "Download File"
        else:
            size_string, raw_size = self.file_size(size, '')
            heading = "Download File: (Size = %s)" % size_string

        if (entry.type == 'playlist') and (localfile.lower().endswith('.plx')
                                           == False):
            localfile += '.plx'

        #browsewnd = CDialogBrowse("CBrowseskin.xml", os.getcwd())
        curdir = addon.getAddonInfo('path')
        browsewnd = CDialogBrowse("CBrowseskin2.xml", curdir)
        browsewnd.SetFile(dir, localfile, 3, heading)
        browsewnd.doModal()

        if browsewnd.state != 0:
            self.state = -2  #cancel download
            return

        self.localfile = browsewnd.dir + browsewnd.filename
        self.dir = browsewnd.dir

        #Check if the file already exists
        if os.path.exists(self.localfile):
            dialog = xbmcgui.Dialog()
            if dialog.yesno(
                    "Message",
                    "The destination file already exists, continue?") == False:
                self.state = -2  #cancel download
コード例 #41
0
ファイル: CDownLoader.py プロジェクト: whf839/xbmc-addons
    def download_file(self, entry, shutdown = False, header=""):
        self.state = 0 #success
        
        URL = entry.URL
        localfile = entry.DLloc
        
        if URL[:4] != 'http':
            self.state = -1 #URL does not point to internet file.
            return

        #Get the direct URL to the mediaitem given URL
        urlopener = CURLLoader()
        result = urlopener.urlopen(URL)
        if result != 0:
            self.state = -1 #failed to download the file
            return        
    
        URL = urlopener.loc_url

        self.MainWindow.dlinfotekst.setLabel("Getting file from server.")

        try:
            oldtimeout=socket_getdefaulttimeout()
            socket_setdefaulttimeout(url_open_timeout)

            existSize=0
            myUrlclass = myURLOpener()
            if os.path.exists(localfile):
                file = open(localfile,"ab")
                existSize = os.path.getsize(localfile)
                               
                #If the file exists, then only download the remainder
                myUrlclass.addheader("User-Agent","Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)")                            
                myUrlclass.addheader("Range","bytes=%s-" % existSize)                             

            else:
                #open the destination file
                file = open(localfile, "wb")

            f = myUrlclass.open(URL)
            #If the file exists, but we already have the whole thing, don't download again
            size_string = f.headers['Content-Length']
            size = int(size_string) #The remaining bytes
            
#todo: size may be existsize if file is downloaded exactly 50%            
            if (size > 0) and (size != existSize):
                if shutdown == True:
                    string = "Downloading + Shutdown " + header
                else:
                    string = "Downloading " + header

#                dialog = xbmcgui.DialogProgress()
#                dialog.create(string, entry.name)
                
                bytes = existSize #bytes downloaded already
                size = size + existSize
                size_MB = float(size) / (1024 * 1024)

                #download in chunks of 100kBytes
                while (bytes < size) and (self.killed == False) and (self.running == True):
                    chunk = 100 * 1024
                    if (bytes + chunk) > size:
                        chunk = size-bytes #remainder
                    file.write(f.read(chunk))
                    bytes = bytes + chunk
            
#                    if(dialog.iscanceled()):
#                        self.state = -2 #cancel download
#                        break
                
                    percent = 100 * bytes / size
                    done = float(bytes) / (1024 * 1024)
                    #line2 = '%.1f MB of %.1f MB copied.' % (done, size_MB)
                    line2 = '%.1f MB - %d ' % (size_MB, percent) + '%'
#                    dialog.update(percent, entry.name, line2)
                
                    self.MainWindow.dlinfotekst.setLabel(line2)
                
#                dialog.close()
                f.close()

                if (self.killed == True) or (self.running == False):
                    self.state = -1 #failed to download the file
                
            
        except IOError:
#            dialog.close()
            f.close()            
            self.state = -1 #failed to download the file

        file.close()      
        socket_setdefaulttimeout(oldtimeout)
  
        #add the downloaded file to the download list
        if self.state == 0:
            tmp = CMediaItem() #create new item
            tmp.type = entry.type
            tmp.name = entry.name
            tmp.thumb = entry.thumb
            tmp.URL = entry.DLloc
            tmp.player = entry.player
            self.playlist_dst.add(tmp)
            self.playlist_dst.save(RootDir + downloads_complete)
コード例 #42
0
    def DownLoadSpeedTest(self, entry):
        #Get the direct URL to the mediaitem given URL
        urlopener = CURLLoader()
        result = urlopener.urlopen(entry.URL, entry)
        if result["code"] != 0:
            return -1

        URL = urlopener.loc_url

        if URL[:3] == 'ftp':
            dialog = xbmcgui.Dialog()
            dialog.ok("Message", "FTP download speed test not supported.")
            return 0

        dialog = xbmcgui.DialogProgress()
        dialog.create("Download Speed Test", entry.name)
        dialog.update(0, entry.name)

        #try:
        bytes = 0
        chunk = 100 * 1024

        #rembember the user agent set the processor
        index = URL.find('|User-Agent=')
        if index != -1:
            useragent = URL[index + 12:]
            URL = URL[:index]
        else:
            useragent = 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'

        #headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
        headers = {'User-Agent': useragent}
        req = urllib2.Request(URL, None, headers)
        f = urllib2.urlopen(req)

        size_rb, size_raw = self.file_size(0, req)  ####
        #size_raw = f.headers['Content-Length']          ####
        size = int(size_raw)

        file = open(tempCacheDir + "dltest", "wb")
        starttime = time.time()
        deltatime = 0
        updatetime = 0

        while deltatime < 10:  #10 seconds
            if (dialog.iscanceled()):
                break

            if (bytes >= size):  # got the complete file
                break

            file.write(f.read(chunk))
            bytes = bytes + chunk

            deltatime = time.time() - starttime
            if (deltatime - updatetime) >= 1.0:
                dialog.update(int(deltatime * 10), entry.name)  ####
                #dialog.update(deltatime*10, str(deltatime-updatetime))
                updatetime = deltatime

        f.close()
        file.close()
        os.remove(tempCacheDir + "dltest")

        #except IOError:
        #pass

        dialog.close()

        if deltatime < 3:
            return -1  # failed because we need at least 3 seconds to have an accurate measurement

        if (deltatime < 10) and (bytes < size):
            return 0  #abort

        #calculate the download speed
        dlspeed = (bytes / 1024) / deltatime

        dialog = xbmcgui.Dialog()
        dialog.ok("Message", "Download speed: %d kBytes/s." % dlspeed)

        return 0
コード例 #43
0
    def play_URL(self, URL, mediaitem=0):

        ##mc.ShowDialogOk("play_URL", str(URL))
        #URL=mediaitem.URL
        #check if the URL is empty or not
        if URL == '':
            return {"code":1, "data":"URL is empty"}
        
        orig_processor = mediaitem.processor   #remember to decide if we show a webpage or play the result of html processing      
        ##mc.ShowDialogOk("Debug in play_URL start", "type = " + mediaitem.type + '\n' + "processor = " + mediaitem.processor) 

        urlopener = CURLLoader()
        result = urlopener.urlopen(URL, mediaitem)
        ##mc.ShowDialogOk("result from urlopen", str(result))
        if result["code"] != 0:
            return result   
        URL = urlopener.loc_url
        ##mc.ShowDialogOk("loc_url", str(URL))
        
#        SetInfoText("Loading... ")

#        self.pls.clear() #clear the playlist
#################################  
        ext = getFileExtension(URL)
        
        #todo ashx  
        if ext == 'ashx':
            ext = 'm3u'
        
        if ext == 'pls' or ext == 'm3u':
            loader = CFileLoader2() #file loader
            loader.load(URL, tempCacheDir + "playlist." + ext, retries=2)
            if loader.state == 0: #success
                URL = loader.localfile
################################# 
        ##mc.ShowDialogOk("Debug in play_URL before play", "type = " + mediaitem.type + '\n' + "processor = " + orig_processor)

        if mediaitem.type == 'html':   #assume html processing returns video?
            if orig_processor == '':  #no actual html processing, just display the webpage using boxee browser
                listitemObj = CreateHTMLListItem(URL)
                if listitemObj["code"]==0:
                    listitem=listitemObj["data"]
                    mc.Player().Play(listitem)
                    return {"code":0}
                else:
                    return listitemObj
            else:  
                listitem = mc.ListItem(mc.ListItem.MEDIA_VIDEO_CLIP)

        elif mediaitem.type == 'video': 
            listitem = mc.ListItem(mc.ListItem.MEDIA_VIDEO_CLIP)
        elif mediaitem.type == 'audio':
            listitem = mc.ListItem(mc.ListItem.MEDIA_AUDIO_MUSIC)
        else:                      #Player can only play audio or video or html
            return {"code":1,"data":"Item type not supported"}

        listitem.SetLabel(mediaitem.name)
        listitem.SetPath(URL)
        listitem.SetContentType("url")

        if mediaitem.playpath != '':
            self.play_RTMP(mediaitem.URL, mediaitem.playpath, mediaitem.swfplayer, mediaitem.pageurl);
        else:  
#            xbmc.Player.play(self, urlopener.loc_url)
             mc.Player().Play(listitem)
            
        return {"code":0}
コード例 #44
0
ファイル: CDownLoader.py プロジェクト: drrlramsey/xbmc-addons
    def DownLoadSpeedTest(self, entry):
        #Get the direct URL to the mediaitem given URL      
        urlopener = CURLLoader()
        result = urlopener.urlopen(entry.URL, entry)
        if result != 0:
            return -1       

        URL = urlopener.loc_url

        dialog = xbmcgui.DialogProgress()
        dialog.create("Download Speed Test", entry.name)        
        dialog.update(0, entry.name)
    
        try:
            bytes= 0
            chunk = 100 * 1024
            
            headers = { 'User-Agent' : 'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)'}
            req = urllib2.Request(URL, None, headers)
            f = urllib2.urlopen(req)      
            
            size_string = f.headers['Content-Length']
            size = int(size_string)     
            
            file = open(tempCacheDir + "dltest", "wb")
            starttime = time.time()
            deltatime = 0
            updatetime = 0
        
            while deltatime < 10: #10 seconds
                if(dialog.iscanceled()):
                    break
            
                if (bytes >= size): # got the complete file
                    break;
            
                file.write(f.read(chunk))
                bytes = bytes + chunk
            
                deltatime = time.time() - starttime
                if (deltatime - updatetime) >= 1.0:
                    dialog.update(deltatime*10, entry.name)
                    #dialog.update(deltatime*10, str(deltatime-updatetime))
                    updatetime = deltatime

            f.close()
            file.close()                
            os.remove(tempCacheDir + "dltest")
                
        except IOError:
            pass
  
        dialog.close()        
        
        if deltatime < 3:
            return -1 # failed because we need at least 3 seconds to have an accurate measurement
        
        if (deltatime < 10) and (bytes < size):
            return 0 #abort
        
        #calculate the download speed
        dlspeed = (bytes / 1024) / deltatime
        
        dialog = xbmcgui.Dialog()
        dialog.ok("Message", "Download speed: %d kBytes/s." % dlspeed)
        
        return 0

                
コード例 #45
0
ファイル: CDownLoader.py プロジェクト: bialagary/mw
            
        # set custom headers if specified
        URL, headers=parse_headers(URL, entry)
        try:
            cookies = ''
            if URL.find(nxserver_URL) != -1:
                cookies='platform='+platform+'; version='+Version+'.'+SubVersion
                cookies=cookies+'; nxid='+nxserver.user_id
                headers={'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4','Cookie':cookies}
                #headers={'User-Agent':'Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)','Cookie':cookies}
        except Exception,e: 
            print('ERROR line 397 cookies ' +str(e))
            #print 'headers =    ' + str(headers)

        #Get the direct URL to the mediaitem given URL      
        urlopener = CURLLoader()
        self.processed=urlopener.processed            #### needed or will fault the next line at times
        entry.processed=self.processed
        try:
            result = urlopener.urlopen(URL, entry)
            if result["code"] != 0:
                self.state = -1 #failed to open the file
                print("urlopener.urlopen failed line 408  " + str(result))
                line2 = '%s  %s' % ('failed to open', str(entry.name))
                self.MainWindow.dlinfotekst.setLabel(line2)
                return
        except Exception,e:
            self.state = -1 #failed to open the file
            print("urlopener.urlopen failed line 414  " + str(e))
            line2 = '%s  %s' % ('failed to open', str(entry.name))
            self.MainWindow.dlinfotekst.setLabel(line2)