Пример #1
0
def viewImage(iURL=''):
    mode = 0
    #    self.setInfoText("Loading...")
    #clear the imageview cache
    #    self.delFiles(imageCacheDir)

    if not os.path.exists(imageCacheDir):
        os.mkdir(imageCacheDir)

    if mode == 0:  #single file show
        localfile = imageCacheDir + '0.'
        if iURL != '':
            URL = iURL
#        else:
#            URL = playlist.list[pos].URL
        ext = getFileExtension(URL)

        if URL[:4] == 'http':
            loader = CFileLoader()
            loader.load(URL, localfile + ext, proxy="DISABLED")
            if loader.state == 0:
                xbmc.executebuiltin('xbmc.slideshow(' + imageCacheDir + ')')
            else:
                dialog = xbmcgui.Dialog()
                dialog.ok("Error", "Unable to open image.")
        else:
            #local file
            shutil.copyfile(URL, localfile + ext)
            xbmc.executebuiltin('xbmc.slideshow(' + imageCacheDir + ')')
Пример #2
0
def viewImage(iURL=''):
    mode = 0
#    self.setInfoText("Loading...")
    #clear the imageview cache
#    self.delFiles(imageCacheDir)

    if not os.path.exists(imageCacheDir): 
        os.mkdir(imageCacheDir) 

    if mode == 0: #single file show
        localfile= imageCacheDir + '0.'
        if iURL != '':
            URL = iURL
#        else:    
#            URL = playlist.list[pos].URL
        ext = getFileExtension(URL)

        if URL[:4] == 'http':
            loader = CFileLoader()
            loader.load(URL, localfile + ext, proxy="DISABLED")
            if loader.state == 0:
                xbmc.executebuiltin('xbmc.slideshow(' + imageCacheDir + ')')
            else:
                dialog = xbmcgui.Dialog()
                dialog.ok("Error", "Unable to open image.")
        else:
            #local file
            shutil.copyfile(URL, localfile + ext)
            xbmc.executebuiltin('xbmc.slideshow(' + imageCacheDir + ')')
Пример #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
    def InstallPlugin(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.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

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

        return result
Пример #5
0
 def InstallPlugin(self, URL='', mediaitem=CMediaItem()):            
     if URL != '':
         self.URL = URL
     else:
         self.URL = mediaitem.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
     
     result = self.unzip_file_into_dir(filename, pluginDir + subdir)    
    
     return result
Пример #6
0
    def UpdateThumb(self):
        #        if self.MainWindow.state_busy != 0:
        #            return

        playlist = self.MainWindow.pl_focus
        index = self.MainWindow.list.getSelectedPosition()
        index2 = -1  #this value never will be reached
        thumb_update = False

        while (self.MainWindow.state_busy == 0) and (index != index2):
            #while (index != index2):
            index = self.MainWindow.list.getSelectedPosition()
            if playlist.size() > 0:
                m = self.MainWindow.pl_focus.list[index].thumb

                if (m == 'default') or (m == ""):  #no thumb image
                    m = self.MainWindow.pl_focus.logo  #use the logo instead
                    if m != self.MainWindow.userthumb:
                        self.MainWindow.user_thumb.setVisible(0)

                if m != self.MainWindow.userthumb:
                    #diffent thumb image
                    if (m == 'default') or (m == ""):  #no image
                        self.MainWindow.thumb_visible = False
                    elif m != 'previous':  #URL to image located elsewhere
                        ext = getFileExtension(m)

                        loader = CFileLoader()  #file loader
                        loader.load(m,
                                    cacheDir + "thumb." + ext,
                                    timeout=2,
                                    proxy="ENABLED",
                                    content_type='image')
                        if loader.state == 0:  #success
                            #next line is fix, makes sure thumb is update.
                            self.MainWindow.thumb_visible = True
                            thumb_update = True
                        else:
                            self.MainWindow.thumb_visible = False
                    self.MainWindow.userthumb = m
            else:
                self.MainWindow.thumb_visible = False

            index2 = self.MainWindow.list.getSelectedPosition()

        if self.MainWindow.thumb_visible == True:
            #            self.MainWindow.user_logo.setVisible(0)
            if thumb_update == True:
                self.MainWindow.user_thumb.setVisible(0)
                self.MainWindow.user_thumb.setImage("")
                self.MainWindow.user_thumb.setImage(loader.localfile)

            self.MainWindow.user_thumb.setVisible(1)
        else:
            self.MainWindow.user_thumb.setVisible(0)
Пример #7
0
    def UpdateThumb(self):  
#        if self.MainWindow.state_busy != 0:
#            return
 
        playlist = self.MainWindow.pl_focus
        index = self.MainWindow.list.getSelectedPosition()
        index2 = -1 #this value never will be reached
        thumb_update = False
                              
        while (self.MainWindow.state_busy == 0) and (index != index2):
            index = self.MainWindow.list.getSelectedPosition()
            if playlist.size() > 0:
                m = self.MainWindow.pl_focus.list[index].thumb
                      
                if (m == 'default') or (m == ""): #no thumb image
                    m = self.MainWindow.pl_focus.logo #use the logo instead
                    if m != self.MainWindow.userthumb:
                        self.MainWindow.user_thumb.setVisible(0)
            
                if m != self.MainWindow.userthumb:
                    #diffent thumb image
                    if (m == 'default') or (m == ""): #no image
                        self.MainWindow.thumb_visible = False
                    elif m != 'previous': #URL to image located elsewhere
                        ext = getFileExtension(m)

                        loader = CFileLoader() #file loader
                        #loader = CFileLoader2() #file loader
                        loader.load(m, cacheDir + "thumb." + ext, timeout=2, proxy="ENABLED", content_type='image')
                        if loader.state == 0: #success
                            #next line is fix, makes sure thumb is update.
                            self.MainWindow.thumb_visible = True
                            thumb_update = True
                        else:
                            self.MainWindow.thumb_visible = False
                    self.MainWindow.userthumb = m
            else:
                self.MainWindow.thumb_visible = False
                
            index2 = self.MainWindow.list.getSelectedPosition()

        if self.MainWindow.thumb_visible == True:
#            self.MainWindow.user_logo.setVisible(0)
            if thumb_update == True:
                self.MainWindow.user_thumb.setVisible(0)
                self.MainWindow.user_thumb.setImage("")
                self.MainWindow.user_thumb.setImage(loader.localfile)

            self.MainWindow.user_thumb.setVisible(1)
        else:
            self.MainWindow.user_thumb.setVisible(0)
Пример #8
0
    def InstallScript(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.URL

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

        result = self.unzip_file_into_dir(filename, scriptDir)

        return result
Пример #9
0
    def InstallScript(self, URL='', mediaitem=CMediaItem()):
        if URL != '':
            self.URL = URL
        else:
            self.URL = mediaitem.URL
        
        #download the file.
        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'script.zip')
        if loader.state != 0:
            return -2
        filename = loader.localfile

        result = self.unzip_file_into_dir(filename, scriptDir)   

        return result
Пример #10
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
Пример #11
0
    def OpenDocument(self, URL="", mediaitem=0):
        if mediaitem == 0:
            mediaitem = CMediaItem()

        # from here we use the mediaitem object
        loader = CFileLoader()
        # first load the background image
        if mediaitem.background != "default":  # default BG image
            ext = getFileExtension(mediaitem.background)
            loader.load(mediaitem.background, cacheDir + "backtextview." + ext, 8, proxy="ENABLED")
            if loader.state == 0:  # if this fails we still continue
                self.bg.setImage(loader.localfile)

        if URL == "":
            URL = mediaitem.URL

        # now load the text file
        loader.load(URL, cacheDir + "document.txt")
        if loader.state == 0:
            # open the local file
            try:
                f = open(loader.localfile, "r")
                data = f.read()
                f.close()
                text = ""
                lines = data.split("\n")
                # we check each line if it exceeds 80 characters and does not contain
                # any space characters (e.g. long URLs). The textbox widget does not
                # split up these strings. In this case we add a space characters ourself.
                for m in lines:
                    if (len(m) > 80) and (m.find(" ") == -1):
                        m = m[:80] + " " + m[80:]
                    text = text + m + "\n"
                self.TextBox.setText(text)
                return 0  # success
            except IOError:
                return -1  # failure
        else:
            return -1  # failure
Пример #12
0
    def OpenDocument(self, URL='', mediaitem=0):
        if mediaitem == 0:
            mediaitem = CMediaItem()

        #from here we use the mediaitem object
        loader = CFileLoader()
        #first load the background image
        if (mediaitem.background != 'default'):  #default BG image
            ext = getFileExtension(mediaitem.background)
            loader.load(mediaitem.background,
                        cacheDir + "backtextview." + ext,
                        8,
                        proxy="ENABLED")
            if loader.state == 0:  #if this fails we still continue
                self.bg.setImage(loader.localfile)

        if URL == '':
            URL = mediaitem.URL

        #now load the text file
        loader.load(URL, cacheDir + 'document.txt')
        if loader.state == 0:
            #open the local file
            try:
                f = open(loader.localfile, 'r')
                data = f.read()
                f.close()
                text = ""
                lines = data.split("\n")
                #we check each line if it exceeds 80 characters and does not contain
                #any space characters (e.g. long URLs). The textbox widget does not
                #split up these strings. In this case we add a space characters ourself.
                for m in lines:
                    if (len(m) > 80) and (m.find(" ") == -1):
                        m = m[:80] + " " + m[80:]
                    text = text + m + "\n"
                self.TextBox.setText(text)
                return 0  #success
            except IOError:
                return -1  #failure
        else:
            return -1  #failure
Пример #13
0
    def load_plx(self, filename='', mediaitem=CMediaItem(), proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL

        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'playlist.plx', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile

        try:
            f = open(filename, 'r')
            data = f.read()
            #            data = data.split('\n')
            data = data.splitlines()
            f.close()
        except IOError:
            return -2

        #defaults
        self.version = '-1'
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = ''
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0

        #parse playlist entries
        counter = 0
        state = 0
        tmp = ''

        for m in data:
            if state == 2:  #parsing description field
                index = m.find('/description')
                if index != -1:
                    self.description = self.description + "\n" + m[:index]
                    state = 0
                else:
                    self.description = self.description + "\n" + m
            elif state == 3:  #parsing description field
                index = m.find('/description')
                if index != -1:
                    tmp.description = tmp.description + "\n" + m[:index]
                    state = 1
                else:
                    tmp.description = tmp.description + "\n" + m
            elif m and m[0] != '#':
                index = m.find('=')
                if index != -1:
                    key = m[:index]
                    value = m[index + 1:]
                    if key == 'version' and state == 0:
                        self.version = value
                        #check the playlist version
                        if int(self.version) > int(plxVersion):
                            return -1
                    elif key == 'background' and state == 0:
                        self.background = value
                    elif key == 'player' and state == 0:
                        self.player = value
                    elif key == 'logo' and state == 0:
                        self.logo = value
                    elif key == 'title' and state == 0:
                        self.title = value
                    elif key == 'description' and state == 0:
                        index = value.find('/description')
                        if index != -1:
                            self.description = value[:index]
                        else:
                            self.description = value
                            state = 2  #description on more lines
                    elif key == 'playmode' and state == 0:
                        self.playmode = value
                    elif key == 'type':
                        if state == 1:
                            self.list.append(tmp)
                        else:  #state=0
                            del self.list[:]
                        tmp = CMediaItem()  #create new item
                        tmp.type = value
                        if tmp.type == 'video' or tmp.type == 'audio':
                            tmp.player = self.player

                        counter = counter + 1
                        state = 1
                    elif key == 'version' and state == 1:
                        tmp.version = value
                    elif key == 'name':
                        tmp.name = value
                    elif key == 'date':
                        tmp.date = value
                    elif key == 'thumb':
                        tmp.thumb = value
                    elif key == 'URL':
                        tmp.URL = value
                    elif key == 'DLloc':
                        tmp.DLloc = value
                    elif key == 'player':
                        tmp.player = value
                    elif key == 'background':
                        tmp.background = value
                    elif key == 'description':
                        #self.description = ' ' #this will make the description field visible
                        index = value.find('/description')
                        if index != -1:
                            tmp.description = value[:index]
                        else:
                            tmp.description = value
                            state = 3  #description on more lines

        if state == 1:
            self.list.append(tmp)

        #if no version ID is found then this is not a valid playlist.
#the next lines to not work because they current playlist is already lost.
#        if self.version == '-1':
#            return -2

        return 0  #successful
Пример #14
0
    def load_xml_applemovie(self, filename='', mediaitem=CMediaItem(), proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL
        
        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'page.xml', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile
        
        try:
            f = open(filename, 'r')
            data = f.read()
            entries = data.split('</movieinfo>')
            f.close()
        except IOError:
            return -2
        
        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = 'Apple Movie Trailers'
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]
        dates = [] #contains the dates
        
        #get the publication date and add it to the title.
        index = data.find('<records date')
        if index != -1:
            index2 = data.find(':', index)
            if index2 != -1:
                value = data[index+15:index2-2]
                self.title = self.title + " (" + value + ")"
        
        #parse playlist entries 
        for m in entries:
            #fill the title
            index = m.find('<title>')
            if index != -1:
                #create a new entry
                tmp = CMediaItem() #create new item
                tmp.type = 'video'
            
                index2 = m.find('</title>')
                if index2 != -1:
                    value = m[index+7:index2]
                    tmp.name = value

                #fill the release date
                date = 0
                index = m.find('<releasedate>')
                if index != -1:
                    index2 = m.find('</releasedate>')
                    if index2 != -1:
                        value = m[index+13:index2]
                        if value != '':
                            date=int(value[2:4]) * 365
                            date = date + int(value[5:7]) * 31
                            date = date + int(value[8:])
                        tmp.name = tmp.name + "  - (Release Date: " + value + ")"
                dates.append(date)
                    
                #fill the thumb
                index = m.find('<location>')
                if index != -1:
                    index2 = m.find('</location>')
                    if index2 != -1:
                        value = m[index+10:index2]
                        tmp.thumb = value

                #fill the URL
                index = m.find('<preview>')
                if index != -1:
                    index2 = m.find('</large>')
                    if index2 != -1:
                        index3 = m.find('http', index, index2)
                        if index3 != -1:
                            value = m[index3:index2]
                            tmp.URL = value

                self.list.append(tmp)

        #sort the list according release date
        for i in range(len(dates)-1):
            oldest = i
            for n in range(i, len(dates)):
                if dates[n] < dates[oldest]:
                    oldest = n
            if oldest != i:
                temp = dates[i]
                dates[i] = dates[oldest]
                dates[oldest] = temp
                
                temp = self.list[i]
                self.list[i] = self.list[oldest]
                self.list[oldest] = temp
        return 0        
Пример #15
0
    def load_plx(self, filename='', mediaitem=CMediaItem(), proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL
        
        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'playlist.plx', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile
        
        try:
            f = open(filename, 'r')
            data = f.read()
#            data = data.split('\n')
            data = data.splitlines()
            f.close()
        except IOError:
            return -2
        
        #defaults
        self.version = '-1'
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = ''
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0

        #parse playlist entries 
        counter = 0
        state = 0
        tmp=''
        
        for m in data:
            if state == 2: #parsing description field
                index = m.find('/description')
                if index != -1:
                    self.description = self.description + "\n" + m[:index]
                    state = 0
                else:
                    self.description = self.description + "\n" + m
            elif state == 3: #parsing description field
                index = m.find('/description')
                if index != -1:
                    tmp.description = tmp.description + "\n" + m[:index]
                    state = 1
                else:
                    tmp.description = tmp.description + "\n" + m
            elif m and m[0] != '#':
                index = m.find('=')
                if index != -1:
                    key = m[:index]
                    value = m[index+1:]
                    if key == 'version' and state == 0:
                        self.version = value
                        #check the playlist version
                        if int(self.version) > int(plxVersion):
                            return -1
                    elif key == 'background' and state == 0:
                        self.background=value
                    elif key == 'player' and state == 0:
                        self.player=value
                    elif key == 'logo' and state == 0:
                        self.logo=value
                    elif key == 'title' and state == 0:
                            self.title=value
                    elif key == 'description' and state == 0:
                            index = value.find('/description')
                            if index != -1:
                                self.description=value[:index]
                            else:
                                self.description=value
                                state = 2 #description on more lines
                    elif key == 'playmode' and state == 0:
                            self.playmode=value
                    elif key == 'type':
                        if state == 1:
                            self.list.append(tmp)
                        else: #state=0
                            del self.list[:]
                        tmp = CMediaItem() #create new item
                        tmp.type = value
                        if tmp.type == 'video' or tmp.type == 'audio':
                            tmp.player = self.player

                        counter = counter+1
                        state = 1
                    elif key == 'version' and state == 1:
                        tmp.version=value
                    elif key == 'name':
                        tmp.name=value
                    elif key == 'date':
                        tmp.date=value    
                    elif key == 'thumb':
                        tmp.thumb=value
                    elif key == 'URL':
                        tmp.URL=value
                    elif key == 'DLloc':
                        tmp.DLloc=value
                    elif key == 'player':
                        tmp.player=value 
                    elif key == 'background':
                        tmp.background=value 
                    elif key == 'description':
                        #self.description = ' ' #this will make the description field visible
                        index = value.find('/description')
                        if index != -1:
                            tmp.description=value[:index]
                        else:
                            tmp.description=value
                            state = 3 #description on more lines
                        
                    
        if state == 1:
            self.list.append(tmp)
        
        #if no version ID is found then this is not a valid playlist.
#the next lines to not work because they current playlist is already lost.
#        if self.version == '-1':
#            return -2
        
        return 0 #successful
Пример #16
0
    def load_rss_flickr_daily(self, filename='', mediaitem=CMediaItem(), proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL

        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'feed.xml', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile
        
        try:
            f = open(filename, 'r')
            data = f.read()
            data = data.split('<item ')
            f.close()
        except IOError:
            return -2
        
        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = ''
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]
        
        counter=0
        #parse playlist entries 
        for m in data:
            if counter == 0:
                #fill the title
                index = m.find('<title>')
                if index != -1:
                    index2 = m.find('</title>')
                    if index != -1:
                        value = m[index+7:index2]
                        self.title = value
                
                counter = counter + 1
            else:
                #get the title.
                index = m.find('<title>')
                if index != -1:
                    index2 = m.find('</title>', index)
                    if index2 != -1:
                        value = m[index+7:index2]
                        name = value

                #get the enclosed content.
                items = 0
                index = m.find('<description>')
                if index != -1:
                    index2 = m.find('</description>', index)
                    if index2 != -1:
                        index3 = m.find('src=', index)
                        while index3 != -1:
                            index4 = m.find('"', index3+5)
                            if index4 != -1:
                                tmp = CMediaItem() #create new item
                                tmp.type = 'image'
                                if items > 0:
                                    tmp.name = name + " " + str(items+1)
                                else:
                                    tmp.name = name
                            
                                value = m[index3+5:index4-4]
                                if value[-6] == '_':
                                    value = value[:-6] + ".jpg"
                                tmp.URL = value
                                tmp.thumb = tmp.URL[:-4] + "_m" + ".jpg"
                                
                                self.list.append(tmp)
                                counter = counter + 1

                                items= items + 1
                                index3 = m.find('src=', index4)
                
        return 0
Пример #17
0
    def load_xml_shoutcast(self, filename='', mediaitem=CMediaItem(), proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL
        
        loader = CFileLoader()
        
        counter = 0
        while counter < 5: #maximum 5 retries
            loader.load(self.URL, cacheDir + 'shoutcast.xml', proxy=proxy)
            if loader.state != 0:
                return -2
            filename = loader.localfile
        
            try:
                f = open(filename, 'r')
                data = f.read()

                f.close()
            except IOError:
                return -2
        
            if data.find('<?xml version="1.0"') != -1:
                break #success
                
            #failed try again
            counter = counter + 1
            
        if counter >= 5:
            return -2 #failed

        
        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
#        self.logo = 'none'
        self.logo = "images\shoutcast.jpg"
        self.title = 'Shoutcast' + ' - ' + mediaitem.name
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]

        if data.find('<stationlist>') != -1:
            #parse playlist entries
            entries = data.split('</station>')            
            for m in entries:
                tmp = CMediaItem() #create new item
                tmp.type = 'audio'
                tmp.player = self.player

                index1 = m.find('station name=')
                if index1 != -1: #valid entry
                    index2= m.find('"', index1+14)
                    tmp.name = m[index1+14:index2]
                
                index1 = m.find('br=')
                if index1 != -1:
                    index2= m.find('"', index1+4)
                    bitrate = m[index1+4:index2]
                    tmp.name = tmp.name + " (" + bitrate + "kbps) "
                    tmp.URL = ''

                index1 = m.find('ct=')
                if index1 != -1:
                    index2= m.find('"', index1+4)
                    np = m[index1+4:index2]
                    tmp.name = tmp.name + "- Now Playing: " + np
                    tmp.URL = ''

                index1 = m.find('br=')
                if index1 != -1:
                    index2= m.find('"', index1+4)
                    bitrate = m[index1+4:index2]
                    tmp.name = tmp.name + " (" + bitrate + "kbps) "
                    tmp.URL = ''
   
                index1 = m.find('genre=')
                if index1 != -1: #valid entry
                    index2= m.find('"', index1+7)
                    genre = m[index1+7:index2]
                    tmp.name = tmp.name + '[' + genre + ']'

                index1 = m.find('id=')
                if index1 != -1:
                    index2= m.find('"', index1+4)
                    id = m[index1+4:index2]
                    tmp.URL = "http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=" + id + "&file=filename.pls"

                    self.list.append(tmp)
                
        else: #<genrelist>
            #parse playlist entries
            entries = data.split('</genre>')
            for m in entries:
                tmp = CMediaItem() #create new item
                tmp.type='xml_shoutcast'
                tmp.player = self.player
                
                index1 = m.find('name=')
                if index1 != -1:
                    index2= m.find('"', index1+6)
                    genre = m[index1+6:index2]
                    tmp.name = genre
                    tmp.URL = "http://www.shoutcast.com/sbin/newxml.phtml?genre=" + genre
                    self.list.append(tmp)
                
        return 0
Пример #18
0
    def load_rss_20(self, filename='', mediaitem=CMediaItem(), proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL

        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'feed.xml', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile
        
        try:
            f = open(filename, 'r')
            data = f.read()
            data = data.split('<item')
            f.close()
        except IOError:
            return -2
        
        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = ''
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]
        
        counter=0
        #parse playlist entries 
        for m in data:
            if counter == 0:
                #fill the title
                index = m.find('<title>')
                if index != -1:
                    index2 = m.find('</title>')
                    if index != -1:
                        value = m[index+7:index2]
                        self.title = value

                index = m.find('<description>')
                if index != -1:
                    index2 = m.find('</description>')
                    if index2 != -1:
                        value = m[index+13:index2]
                        self.description = value
                        index3 = self.description.find('<![CDATA[')
                        if index3 != -1:
                            self.description = self.description[9:-3]
                
                #fill the logo
                index = m.find('<image>')
                if index != -1:
                    index2 = m.find('</image>')
                    if index != -1:
                        index3 = m.find('<url>', index, index2)
                        if index != -1:
                            index4 = m.find('</url>', index, index2)
                            if index != -1:
                                value = m[index3+5:index4]
                                self.logo = value
                else: #try if itunes image
                    index = m.find('<itunes:image href="')
                    if index != -1:
                        index2 = m.find('"', index+20)
                        if index != -1:
                            value = m[index+20:index2]
                            self.logo = value
       
                counter = counter + 1
            else:
                tmp = CMediaItem() #create new item
                tmp.player = self.player

                #get the publication date.
                index = m.find('<pubDate')
                if index != -1:
                    index2 = m.find('>', index)
                    if index2 != -1:
                        index3 = m.find('</pubDate')
                        if index3 != -1:
                            index4 = m.find(':', index2, index3)
                            if index4 != -1:
                                value = m[index2+1:index4-2]
                                tmp.name = value

                #get the title.
                index = m.find('<title')
                if index != -1:
                    index2 = m.find('>', index)
                    if index2 != -1:
                        index3 = m.find('</title>')
                        if index3 != -1:
                            index4 = m.find('![CDATA[', index2, index3)
                            if index4 != -1:
                                value = m[index2+10:index3-3]
                            else:
                                value = m[index2+1:index3]
                            tmp.name = tmp.name + value
                                             
                #get the description.
                index1 = m.find('<content:encoded>')
                index = m.find('<description>')
                if index1 != -1:
                    index2 = m.find('</content:encoded>')
                    if index2 != -1:
                        value = m[index1+17:index2]
                        tmp.description = value
                        index3 = tmp.description.find('<![CDATA[')
                        if index3 != -1:
                            tmp.description = tmp.description[9:-3]
                elif index != -1:
                    index2 = m.find('</description>')
                    if index2 != -1:
                        value = m[index+13:index2]
                        tmp.description = value
                        index3 = tmp.description.find('<![CDATA[')
                        if index3 != -1:
                            tmp.description = tmp.description[9:-3]

                #get the thumb
                index = m.find('<media:thumbnail')
                if index != -1:
                    index2 = m.find('url=', index+16)
                    if index2 != -1:
                        index3 = m.find('"', index2+5)
                        if index3 != -1:
                            value = m[index2+5:index3]
                            tmp.thumb = value

                #get the enclosed content.
                index = m.find('enclosure')
                index1 = m.find ('<media:content')
                if (index != -1) or (index1 != -1):
                    #enclosure is first choice. If no enclosure then use media:content
                    if (index == -1) and (index1 != -1):
                        index = index1
                    index2 = m.find('url="',index)
                    if index2 != -1:
                        index3 = m.find('"', index2+5)
                    else:
                        index2 = m.find("url='",index)
                        if index2 != -1:
                            index3 = m.find("'", index2+5)
                    if (index2 != -1) and (index3 != -1):
                        value = m[index2+5:index3]
                        tmp.URL = value
                            
                    if tmp.URL != '': #valid URL found
                        #validate the type based on file extension
                        ext_pos = tmp.URL.rfind('.') #find last '.' in the string
                        if ext_pos != -1:
                            ext = tmp.URL[ext_pos+1:]
                            ext = ext.lower()
                            if ext == 'jpg' or ext == 'gif' or ext == 'png':
                                tmp.type = 'image'
                            elif ext == 'mp3':
                                tmp.type = 'audio'
                            else:
                                tmp.type = 'video'
                                                        
                else: #no enclosed URL, use the link
                    index = m.find('<link>')
                    if index != -1:
                        index2 = m.find('</link>', index+6)
                        if index2 != -1:
                            value = m[index+6:index2]
                            tmp.URL = value
                        tmp.type = 'html'
                
                if tmp.URL != '':
                    self.list.append(tmp)
                    counter = counter + 1
                    
        return 0
Пример #19
0
    def load_rss_20(self,
                    filename='',
                    mediaitem=CMediaItem(),
                    proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL

        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'feed.xml', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile

        try:
            f = open(filename, 'r')
            data = f.read()
            data = data.split('<item')
            f.close()
        except IOError:
            return -2

        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = ''
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]

        counter = 0
        #parse playlist entries
        for m in data:
            if counter == 0:
                #fill the title
                index = m.find('<title>')
                if index != -1:
                    index2 = m.find('</title>')
                    if index != -1:
                        value = m[index + 7:index2]
                        self.title = value

                index = m.find('<description>')
                if index != -1:
                    index2 = m.find('</description>')
                    if index2 != -1:
                        value = m[index + 13:index2]
                        self.description = value
                        index3 = self.description.find('<![CDATA[')
                        if index3 != -1:
                            self.description = self.description[9:-3]

                #fill the logo
                index = m.find('<image>')
                if index != -1:
                    index2 = m.find('</image>')
                    if index != -1:
                        index3 = m.find('<url>', index, index2)
                        if index != -1:
                            index4 = m.find('</url>', index, index2)
                            if index != -1:
                                value = m[index3 + 5:index4]
                                self.logo = value
                else:  #try if itunes image
                    index = m.find('<itunes:image href="')
                    if index != -1:
                        index2 = m.find('"', index + 20)
                        if index != -1:
                            value = m[index + 20:index2]
                            self.logo = value

                counter = counter + 1
            else:
                tmp = CMediaItem()  #create new item
                tmp.player = self.player

                #get the publication date.
                index = m.find('<pubDate')
                if index != -1:
                    index2 = m.find('>', index)
                    if index2 != -1:
                        index3 = m.find('</pubDate')
                        if index3 != -1:
                            index4 = m.find(':', index2, index3)
                            if index4 != -1:
                                value = m[index2 + 1:index4 - 2]
                                tmp.name = value

                #get the title.
                index = m.find('<title')
                if index != -1:
                    index2 = m.find('>', index)
                    if index2 != -1:
                        index3 = m.find('</title>')
                        if index3 != -1:
                            index4 = m.find('![CDATA[', index2, index3)
                            if index4 != -1:
                                value = m[index2 + 10:index3 - 3]
                            else:
                                value = m[index2 + 1:index3]
                            tmp.name = tmp.name + value

                #get the description.
                index1 = m.find('<content:encoded>')
                index = m.find('<description>')
                if index1 != -1:
                    index2 = m.find('</content:encoded>')
                    if index2 != -1:
                        value = m[index1 + 17:index2]
                        tmp.description = value
                        index3 = tmp.description.find('<![CDATA[')
                        if index3 != -1:
                            tmp.description = tmp.description[9:-3]
                elif index != -1:
                    index2 = m.find('</description>')
                    if index2 != -1:
                        value = m[index + 13:index2]
                        tmp.description = value
                        index3 = tmp.description.find('<![CDATA[')
                        if index3 != -1:
                            tmp.description = tmp.description[9:-3]

                #get the thumb
                index = m.find('<media:thumbnail')
                if index != -1:
                    index2 = m.find('url=', index + 16)
                    if index2 != -1:
                        index3 = m.find('"', index2 + 5)
                        if index3 != -1:
                            value = m[index2 + 5:index3]
                            tmp.thumb = value

                #get the enclosed content.
                index = m.find('enclosure')
                index1 = m.find('<media:content')
                if (index != -1) or (index1 != -1):
                    #enclosure is first choice. If no enclosure then use media:content
                    if (index == -1) and (index1 != -1):
                        index = index1
                    index2 = m.find('url="', index)
                    if index2 != -1:
                        index3 = m.find('"', index2 + 5)
                    else:
                        index2 = m.find("url='", index)
                        if index2 != -1:
                            index3 = m.find("'", index2 + 5)
                    if (index2 != -1) and (index3 != -1):
                        value = m[index2 + 5:index3]
                        tmp.URL = value

                    if tmp.URL != '':  #valid URL found
                        #validate the type based on file extension
                        ext_pos = tmp.URL.rfind(
                            '.')  #find last '.' in the string
                        if ext_pos != -1:
                            ext = tmp.URL[ext_pos + 1:]
                            ext = ext.lower()
                            if ext == 'jpg' or ext == 'gif' or ext == 'png':
                                tmp.type = 'image'
                            elif ext == 'mp3':
                                tmp.type = 'audio'
                            else:
                                tmp.type = 'video'

                else:  #no enclosed URL, use the link
                    index = m.find('<link>')
                    if index != -1:
                        index2 = m.find('</link>', index + 6)
                        if index2 != -1:
                            value = m[index + 6:index2]
                            tmp.URL = value
                        tmp.type = 'html'

                if tmp.URL != '':
                    self.list.append(tmp)
                    counter = counter + 1

        return 0
Пример #20
0
    def load_xml_applemovie(self,
                            filename='',
                            mediaitem=CMediaItem(),
                            proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL

        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'page.xml', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile

        try:
            f = open(filename, 'r')
            data = f.read()
            entries = data.split('</movieinfo>')
            f.close()
        except IOError:
            return -2

        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = 'Apple Movie Trailers'
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]
        dates = []  #contains the dates

        #get the publication date and add it to the title.
        index = data.find('<records date')
        if index != -1:
            index2 = data.find(':', index)
            if index2 != -1:
                value = data[index + 15:index2 - 2]
                self.title = self.title + " (" + value + ")"

        #parse playlist entries
        for m in entries:
            #fill the title
            index = m.find('<title>')
            if index != -1:
                #create a new entry
                tmp = CMediaItem()  #create new item
                tmp.type = 'video'

                index2 = m.find('</title>')
                if index2 != -1:
                    value = m[index + 7:index2]
                    tmp.name = value

                #fill the release date
                date = 0
                index = m.find('<releasedate>')
                if index != -1:
                    index2 = m.find('</releasedate>')
                    if index2 != -1:
                        value = m[index + 13:index2]
                        if value != '':
                            date = int(value[2:4]) * 365
                            date = date + int(value[5:7]) * 31
                            date = date + int(value[8:])
                        tmp.name = tmp.name + "  - (Release Date: " + value + ")"
                dates.append(date)

                #fill the thumb
                index = m.find('<location>')
                if index != -1:
                    index2 = m.find('</location>')
                    if index2 != -1:
                        value = m[index + 10:index2]
                        tmp.thumb = value

                #fill the URL
                index = m.find('<preview>')
                if index != -1:
                    index2 = m.find('</large>')
                    if index2 != -1:
                        index3 = m.find('http', index, index2)
                        if index3 != -1:
                            value = m[index3:index2]
                            tmp.URL = value

                self.list.append(tmp)

        #sort the list according release date
        for i in range(len(dates) - 1):
            oldest = i
            for n in range(i, len(dates)):
                if dates[n] < dates[oldest]:
                    oldest = n
            if oldest != i:
                temp = dates[i]
                dates[i] = dates[oldest]
                dates[oldest] = temp

                temp = self.list[i]
                self.list[i] = self.list[oldest]
                self.list[oldest] = temp
        return 0
Пример #21
0
    def load_xml_shoutcast(self,
                           filename='',
                           mediaitem=CMediaItem(),
                           proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL

        loader = CFileLoader()

        counter = 0
        while counter < 5:  #maximum 5 retries
            loader.load(self.URL, cacheDir + 'shoutcast.xml', proxy=proxy)
            if loader.state != 0:
                return -2
            filename = loader.localfile

            try:
                f = open(filename, 'r')
                data = f.read()

                f.close()
            except IOError:
                return -2

            if data.find('<?xml version="1.0"') != -1:
                break  #success

            #failed try again
            counter = counter + 1

        if counter >= 5:
            return -2  #failed

        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
        #        self.logo = 'none'
        self.logo = "images\shoutcast.jpg"
        self.title = 'Shoutcast' + ' - ' + mediaitem.name
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]

        if data.find('<stationlist>') != -1:
            #parse playlist entries
            entries = data.split('</station>')
            for m in entries:
                tmp = CMediaItem()  #create new item
                tmp.type = 'audio'
                tmp.player = self.player

                index1 = m.find('station name=')
                if index1 != -1:  #valid entry
                    index2 = m.find('"', index1 + 14)
                    tmp.name = m[index1 + 14:index2]

                index1 = m.find('br=')
                if index1 != -1:
                    index2 = m.find('"', index1 + 4)
                    bitrate = m[index1 + 4:index2]
                    tmp.name = tmp.name + " (" + bitrate + "kbps) "
                    tmp.URL = ''

                index1 = m.find('ct=')
                if index1 != -1:
                    index2 = m.find('"', index1 + 4)
                    np = m[index1 + 4:index2]
                    tmp.name = tmp.name + "- Now Playing: " + np
                    tmp.URL = ''

                index1 = m.find('br=')
                if index1 != -1:
                    index2 = m.find('"', index1 + 4)
                    bitrate = m[index1 + 4:index2]
                    tmp.name = tmp.name + " (" + bitrate + "kbps) "
                    tmp.URL = ''

                index1 = m.find('genre=')
                if index1 != -1:  #valid entry
                    index2 = m.find('"', index1 + 7)
                    genre = m[index1 + 7:index2]
                    tmp.name = tmp.name + '[' + genre + ']'

                index1 = m.find('id=')
                if index1 != -1:
                    index2 = m.find('"', index1 + 4)
                    id = m[index1 + 4:index2]
                    tmp.URL = "http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=" + id + "&file=filename.pls"

                    self.list.append(tmp)

        else:  #<genrelist>
            #parse playlist entries
            entries = data.split('</genre>')
            for m in entries:
                tmp = CMediaItem()  #create new item
                tmp.type = 'xml_shoutcast'
                tmp.player = self.player

                index1 = m.find('name=')
                if index1 != -1:
                    index2 = m.find('"', index1 + 6)
                    genre = m[index1 + 6:index2]
                    tmp.name = genre
                    tmp.URL = "http://www.shoutcast.com/sbin/newxml.phtml?genre=" + genre
                    self.list.append(tmp)

        return 0
Пример #22
0
    def load_rss_flickr_daily(self,
                              filename='',
                              mediaitem=CMediaItem(),
                              proxy="CACHING"):
        if filename != '':
            self.URL = filename
        else:
            self.URL = mediaitem.URL

        loader = CFileLoader()
        loader.load(self.URL, cacheDir + 'feed.xml', proxy=proxy)
        if loader.state != 0:
            return -2
        filename = loader.localfile

        try:
            f = open(filename, 'r')
            data = f.read()
            data = data.split('<item ')
            f.close()
        except IOError:
            return -2

        #defaults
        self.version = plxVersion
        self.background = mediaitem.background
        self.logo = 'none'
        self.title = ''
        self.description = ''
        self.player = mediaitem.player
        self.playmode = 'default'
        self.start_index = 0
        #clear the list
        del self.list[:]

        counter = 0
        #parse playlist entries
        for m in data:
            if counter == 0:
                #fill the title
                index = m.find('<title>')
                if index != -1:
                    index2 = m.find('</title>')
                    if index != -1:
                        value = m[index + 7:index2]
                        self.title = value

                counter = counter + 1
            else:
                #get the title.
                index = m.find('<title>')
                if index != -1:
                    index2 = m.find('</title>', index)
                    if index2 != -1:
                        value = m[index + 7:index2]
                        name = value

                #get the enclosed content.
                items = 0
                index = m.find('<description>')
                if index != -1:
                    index2 = m.find('</description>', index)
                    if index2 != -1:
                        index3 = m.find('src=', index)
                        while index3 != -1:
                            index4 = m.find('"', index3 + 5)
                            if index4 != -1:
                                tmp = CMediaItem()  #create new item
                                tmp.type = 'image'
                                if items > 0:
                                    tmp.name = name + " " + str(items + 1)
                                else:
                                    tmp.name = name

                                value = m[index3 + 5:index4 - 4]
                                if value[-6] == '_':
                                    value = value[:-6] + ".jpg"
                                tmp.URL = value
                                tmp.thumb = tmp.URL[:-4] + "_m" + ".jpg"

                                self.list.append(tmp)
                                counter = counter + 1

                                items = items + 1
                                index3 = m.find('src=', index4)

        return 0