예제 #1
0
 def createSubFolders(self):
     progress = DialogProgress()
     try:
         progress.create(SF_SUBFOLDERS_PROGRESS_HEADER, SF_SUBFOLDERS_PROGRESS_MSG)
         row = "id_channel" if getSFFoldersPattern() == AddonConst.SF_XMLTV_ID_PATTERN else 'display_name' 
         request = "SELECT %s FROM channels" % row
         
         if self.database is None or self.cursor is None:
             notify(SF_CHANNELS_INFOS_ERROR)
             progress.close()
             return
         
         self.cursor.execute(request)
         channels = self.cursor.fetchall()
         
         i = 1
         for channel in channels:
             
             if not isfile(join(getSFFolder(translate=True), channel[0])):
                 try:
                     mkdir(join(getSFFolder(translate=True), channel[0]))
                 except OSError:
                     pass
                 
             progress.update(int( ( i / float(len(channels)) ) * 100), "", 
                             SF_DIR_STRING + ' %i/%i' % (i, len(channels)))
             i += 1
             
     except SqliteError:
         progress.close()
         if DEBUG:
             notify(SF_CHANNELS_INFOS_ERROR)
     progress.close()   
예제 #2
0
    def getSubFolderLinks(self, id_channel):
        try:
            # Getting pattern
            channel_data = []
            row = "id_channel" if getSFFoldersPattern(
            ) == AddonConst.SF_XMLTV_ID_PATTERN else "display_name"
            request = 'SELECT %s FROM channels WHERE id=%i' % (row, id_channel)
            self.cursor.execute(request)
            pattern = self.cursor.fetchone()[0]

            sf_folder = join(xbmc.translatePath(getSFFolder()), pattern)

            if exists(sf_folder):
                xml_file = join(sf_folder, "favourites.xml")
                if exists(xml_file):
                    xml = minidom.parse(xml_file)
                    links = xml.getElementsByTagName("favourite")

                    for link in links:
                        link_name = link.getAttribute("name")
                        link_action = link.firstChild.nodeValue
                        channel_data.append({
                            "name": link_name,
                            "action": link_action
                        })
                    return channel_data
                else:
                    return []
            else:
                return []
        except SqliteError:
            return []
        return []
예제 #3
0
 def getSubFolderLinks(self, id_channel):
     try:
         # Getting pattern
         channel_data = []
         row = "id_channel" if getSFFoldersPattern() == AddonConst.SF_XMLTV_ID_PATTERN else "display_name"
         request = 'SELECT %s FROM channels WHERE id=%i' % (row, id_channel)
         self.cursor.execute(request)
         pattern = self.cursor.fetchone()[0]
         
         sf_folder = join(xbmc.translatePath(getSFFolder()), pattern)
         
         if exists(sf_folder):
             # linked stored inside SF/channel/faourites.xml ( containing all channels links )
             xml_file = join(sf_folder, "favourites.xml")
             if exists(xml_file):
                 xml = minidom.parse(xml_file)
                 links = xml.getElementsByTagName("favourite")
                 
                 for link in links:
                     link_name   = link.getAttribute("name")
                     link_action = link.firstChild.nodeValue
                     channel_data.append({"name":link_name, "action":link_action})
                 return channel_data
             else:
                 channel_data
         else:
             # The referenced folder points to an addon folder, so getting SF command
             xml_file = join(xbmc.translatePath(getSFFolder()), "favourites.xml")
             xml = minidom.parse(xml_file)
             sf_commands = xml.getElementsByTagName("favourite")
             
             for action in sf_commands:
                 if action.getAttribute("name") == pattern:
                     link_action = action.firstChild.nodeValue
                     channel_data.append({"name":"Open SF folder", "action":link_action})
                 return channel_data 
             
     except SqliteError:
         return []
     return []
예제 #4
0
    def onClick(self, controlId):
        self.titleLabel.setLabel(ACTIONS_EDIT_CHANNEL + "[CR]" +
                                 self.display_name)
        refreshSkin = True

        # Close
        if controlId == EditControls.QUIT:
            self.close()

        # Channel actions
        elif controlId in [
                EditControls.CHANNEL_HIDE, EditControls.CHANNEL_RENAME,
                EditControls.CHANNEL_LOGO_UPDATE
        ]:
            database, cursor = connectEpgDB()
            epgDb = EpgDb(database, cursor)

            # Hide channel from EPG
            if controlId == EditControls.CHANNEL_HIDE:
                if epgDb.isChannelHidden(self.id_channel):
                    epgDb.updateChannel(self.id_channel, visible=False)
                    self.getControl(EditControls.CHANNEL_HIDE).setLabel(
                        ACTIONS_UNHIDE_CHANNEL)
                else:
                    epgDb.updateChannel(self.id_channel, visible=True)
                    self.getControl(EditControls.CHANNEL_HIDE).setLabel(
                        ACTIONS_HIDE_CHANNEL)

            # Rename the current channel.
            elif controlId == EditControls.CHANNEL_RENAME:
                new_name = xbmcgui.Dialog().input("ACTIONS_RENAME_TITLE",
                                                  self.display_name)
                if not new_name is None or new_name == "":
                    epgDb.updateChannel(self.id_channel, display_name=new_name)
                    # renaming sf directory if 'display names' are used.
                    if not settings.getSFFoldersPattern(
                    ) == settings.AddonConst.SF_XMLTV_ID_PATTERN:
                        joined = join(settings.getSFFolder(translate=True),
                                      self.display_name)
                        if exists(joined):
                            rename(
                                joined,
                                join(settings.getSFFolder(translate=True),
                                     new_name))
                        else:
                            mkdir(
                                join(settings.getSFFolder(translate=True),
                                     new_name))

                        self.display_name = new_name
                        self.titleLabel.setLabel(ACTIONS_EDIT_CHANNEL +
                                                 "[CR]" + self.display_name)

            # Update channel logo
            elif controlId == EditControls.CHANNEL_LOGO_UPDATE:
                source = xbmcgui.Dialog().select(
                    EDIT_LOGO_HEADER,
                    [EDIT_LOGO_FROM_LOCAL, EDIT_LOGO_THE_LOGODB])

                # Start local source dialog browser
                if source == 0:
                    n_logo = xbmcgui.Dialog().browse(2, EDIT_LOGO_HEADER,
                                                     'files')
                    if not n_logo is None:
                        name = str(uuid4()) + n_logo[n_logo.rfind(r"."):]
                        dest = join(settings.getChannelsLogoPath(), name)
                        try:
                            copy(n_logo, dest)
                            epgDb.updateChannel(self.id_channel, logo=name)
                        except:
                            if settings.DEBUG:
                                notify(EDIT_LOGO_ERROR)
                            del database
                            del cursor
                            epgDb.close()
                            del epgDb
                            return

                # Start TheLogoDb search
                elif source == 1:
                    thelogodb = TheLogoDbChannel(self.display_name)
                    if thelogodb.search():
                        progress = xbmcgui.DialogProgress()
                        progress.create(DIALOG_TITLE, SFX_ICONS_DOWNLOAD)

                        # Display found logos.
                        logos = thelogodb.getLogos()
                        logos_local = []

                        import ssl
                        from urllib2 import urlopen, HTTPError
                        from os.path import isdir
                        from shutil import rmtree

                        ssl._create_default_https_context = ssl._create_unverified_context
                        dest_dir = join(
                            xbmc.translatePath("special://home/temp"),
                            "logos_tmp")

                        if not isdir(dest_dir):
                            mkdir(dest_dir)
                        i = 1
                        for logo in logos:
                            progress.update(int((i / float(len(logos))) * 100),
                                            "", EDIT_LOGOS_SEARCH)
                            try:
                                if not logo is None:
                                    dest_file = join(
                                        dest_dir, logo[logo.rfind(r"/") + 1:])
                                    download = urlopen(logo, timeout=30)

                                    tsf = open(dest_file, "w")
                                    tsf.write(download.read())
                                    tsf.close()
                                    del tsf
                                    logos_local.append(dest_file)
                                    i += 1
                            except HTTPError as e:
                                if e.code in [
                                        304, 301, 400, 401, 403, 404, 500, 502,
                                        503, 504
                                ]:
                                    notify(EDIT_LOGO_ERROR)
                                progress.close()

                        progress.close()

                        self.win_logo.addToList(logos_local)
                        self.win_logo.id_channel = self.id_channel
                        self.win_logo.doModal()
                        refreshSkin = self.win_logo.refresh

                        rmtree(dest_dir)

                    else:
                        xbmcgui.Dialog().ok(EDIT_LOGO_HEADER,
                                            EDIT_NO_LOGO_FOUND)

            del database
            del cursor
            epgDb.close()
            del epgDb
            if not self.parent is None and refreshSkin:
                self.parent.refresh()

        # Program actions.
        elif controlId in [
                EditControls.PROGRAM_REMINDER, EditControls.PROGRAM_START
        ]:

            if controlId == EditControls.PROGRAM_REMINDER:
                database, cursor = connectEpgDB()
                epgDb = EpgDb(database, cursor)
                if epgDb.hasReminder(self.program_id):
                    self.getControl(EditControls.PROGRAM_REMINDER).setLabel(
                        ACTIONS_PROGRAM_REMIND)
                    epgDb.removeReminder(self.program_id)
                else:
                    self.getControl(EditControls.PROGRAM_REMINDER).setLabel(
                        ACTIONS_PROGRAM_FORGET_REMIND)
                    epgDb.addReminder(self.program_id)

                if not self.parent is None and refreshSkin:
                    self.parent.refresh()

                del database
                del cursor
                epgDb.close()
                del epgDb

            elif controlId == EditControls.PROGRAM_START:
                database, cursor = connectEpgDB()
                request = "SELECT logo FROM channels WHERE id=%i" % self.id_channel
                cursor.execute(request)
                logo = cursor.fetchone()[0]

                del cursor
                del database

                logo_channel = ""
                if not logo is None:
                    logo_channel = join(getChannelsLogoPath(), logo)

                self.win_sf.setChannel(self.id_channel, logo_channel)
                self.win_sf.doModal()
                del self.win_sf
                self.close()