Example #1
0
    def poll(self, menuw=None, arg=None):
        """
        poll to check for devices
        """
        changes = False

        current_devices = util.list_usb_devices()
        for d in current_devices:
            try:
                self.devices.remove(d)
            except ValueError:
                logger.debug('new device %s', d)
                for device, message, action in config.USB_HOTPLUG:
                    if d == device:
                        pop = dialog.show_working_indicator(message)
                        os.system(action)
                        pop.hide()
                        break
                else:
                    changes = True

        for d in self.devices:
            changes = True
            logger.debug('removed device %s', d)

        if changes:
            rc.post_event(plugin.event('USB'))

        self.devices = current_devices
Example #2
0
    def save_changes(self, arg=None, menuw=None):
        """
        Save favorite
        """
        logger.log( 9, 'save_changes(arg=%r, menuw=%r)', arg, menuw)
        # this can take some time, as it means although to update the schedule
        msgtext = _('Saving the changes to this favorite.')+'\n'+_('This may take some time.')
        pop = dialog.show_working_indicator(msgtext)

        if self.fav_action == 'edit':
            # first we remove the old favorite
            (result, msg) = self.recordclient.removeFavoriteNow(self.origname)
        elif self.fav_action =='add':
            result = True

        if result:
            # create a new edited favorite
            (result, msg) = self.recordclient.addEditedFavoriteNow(self.fav.name,
                self.fav.title, self.fav.channel, self.fav.dow, self.fav.mod,
                self.fav.priority, self.fav.allowDuplicates, self.fav.onlyNew)
            if result:
                if menuw:
                    menuw.delete_submenu()
                    if self.fav_action == 'add':
                        menuw.refresh(reload=1)
                self.fav_action = 'edit'
                pop.hide()
            else:
                pop.hide()
                # it is important to show the user this error,
                # because that means the favorite is removed,
                # and must be created again
                msgtext=_('Save failed, favorite was lost')+(':\n%s' % msg)
                dialog.show_alert(msgtext)
Example #3
0
    def poll(self, menuw=None, arg=None):
        """
        poll to check for devices
        """
        changes = False

        current_devices = util.list_usb_devices()
        for d in current_devices:
            try:
                self.devices.remove(d)
            except ValueError:
                logger.debug('new device %s', d)
                for device, message, action in config.USB_HOTPLUG:
                    if d == device:
                        pop = dialog.show_working_indicator(message)
                        os.system(action)
                        pop.hide()
                        break
                else:
                    changes = True

        for d in self.devices:
            changes = True
            logger.debug('removed device %s', d)

        if changes:
            rc.post_event(plugin.event('USB'))

        self.devices = current_devices
Example #4
0
def search_for_more(arg=None, menuw=None):
    parent, title = arg
    # this might take some time, thus we open a popup messages
    logger.log( 9, String('searching for: %s', title))
    pop = dialog.show_working_indicator(_('Searching, please wait...'))

    # do the search
    (status, matches) = RecordClient().findMatchesNow(title)
    pop.hide()
    if status:
        items = []
        logger.log( 9, 'search found %s matches', len(matches))
        # sort by start times
        f = lambda a, b: cmp(a.start, b.start)
        matches.sort(f)
        for prog in matches:
            items.append(ProgramItem(parent, prog, context='search'))
    elif matches == 'no matches':
        # there have been no matches
        msgtext = _('No matches found for %s') % self.title
        dialog.show_alert(msgtext)
        return
    else:
        # something else went wrong
        msgtext = _('Search failed') +(':\n%s' % matches)
        dialog.show_alert(msgtext)
        return

    # create a menu from the search result
    search_menu = Menu(_('Search Results'), items, item_types='tv program menu')
    # do not return from the search list to the submenu
    # where the search was initiated
    menuw.delete_submenu(refresh = False)
    menuw.pushmenu(search_menu)
    menuw.refresh()
Example #5
0
 def copyHere(self, arg=None, menuw=None):
     popup = dialog.show_working_indicator(_('Copying files...'))
     
     try:
         for cartfile in self.cart:
             cartfile.files.copy(self.item.dir)
     except OSError, e:
         print 'Copy failed: %s' % e
Example #6
0
    def copyHere(self, arg=None, menuw=None):
        popup = dialog.show_working_indicator(_('Copying files...'))

        try:
            for cartfile in self.cart:
                cartfile.files.copy(self.item.dir)
        except OSError, e:
            print 'Copy failed: %s' % e
Example #7
0
    def fetchheadlinesfromurl(self):
        """
        this fetches the headlines (title, link and description) from the url.
        Here the parsing of the xml is done
        """
        headlines = []
        # create Reader object
        reader = Sax2.Reader()

        popup = dialog.show_working_indicator(_('Fetching headlines...'))
        

        # parse the document
        try:
            myfile=urllib.urlopen(self.url)
            doc = reader.fromStream(myfile)
            items = doc.getElementsByTagName('item')
            for item in items:
                title = ''
                link  = ''
                description = ''

                if item.hasChildNodes():
                    for c in item.childNodes:
                        if c.localName == 'title':
                            title = c.firstChild.data
                        if c.localName == 'description':
                            description = c.firstChild.data
                        #################################
                        # Ajout pour identifier le lien de la video
                        if self.mode == 'youtube':
                            if c.localName == 'link':
                                link='youtube:'+c.firstChild.data
                        else:
                            if c.localName == 'enclosure':
                                attrs = c.attributes
                                for attrName in attrs.keys():
                                    attrNode = attrs.get(attrName)
                                    attrValue = attrNode.nodeValue
                                    if 'url' in attrName:
                                        link = attrValue

                if title:
                    headlines.append((title, link, description))

        except:
            #unreachable or url error
            logger.error('could not open %s', self.url)
            pass

        #write the file
        if len(headlines) > 0:
            pfile = os.path.join(self.cachedir, 'itv-%i' % self.location_index)
            util.save_pickle(headlines, pfile)

        popup.hide()
        return headlines
Example #8
0
    def imdb_search(self, arg=None, menuw=None):
        """
        search imdb for this item
        """

        items = []
        dlg = dialog.show_working_indicator(_('Searching IMDB...'))

        if self.disc_set:
            self.searchstring = self.item.media.label
        else:
            self.searchstring = self.item['title']

        try:
            #guess the title from the filename
            lock = kaa.ThreadCallable(self.fxd.guessImdb, self.searchstring,
                                      self.disc_set)()
            lock.wait()
            results = lock.result

            # loop through the results and create menu
            # should not use imdbpy objects here as imdbpy should be encapsulated by FxdImdb
            # but for now it's to much work to do this the right way.
            # It works so let's deal with it later.
            for movie in results:
                try:
                    # OK, we have a regular movie here, no nested episodes
                    items.append(menu.MenuItem('%s (%s) (%s)' % \
                                (movie['long imdb title'], movie['kind'], movie.movieID),
                                 self.imdb_create_fxd, (movie.movieID, movie['kind'])))
                except Unicode, e:
                    print e

        except (FxdImdb_Error) as error:
            logger.warning('%s', error)
            dlg.hide()
            dialog.show_message(_('Connection to IMDB failed'))
            return

        dlg.hide()

        if config.IMDB_AUTOACCEPT_SINGLE_HIT and len(items) == 1:
            self.imdb_create_fxd(arg=items[0].arg, menuw=menuw)
            return

        if items:
            moviemenu = menu.Menu(_('IMDB Query'),
                                  items,
                                  self.item.skin_fxd,
                                  item_types='%s default' % self.item.type)
            # we see if the item has individual skin and load it if so
            menuw.pushmenu(moviemenu)
            return

        dialog.show_message(_('No information available from IMDB'))
        return
Example #9
0
    def imdb_search(self, arg=None, menuw=None):
        """
        search imdb for this item
        """

        items = []
        dlg = dialog.show_working_indicator(_('Searching IMDB...'))

        if self.disc_set:
            self.searchstring = self.item.media.label
        else:
            self.searchstring = self.item['title']
    
        try:
            #guess the title from the filename
            lock = kaa.ThreadCallable(self.fxd.guessImdb, 
                                      self.searchstring, 
                                      self.disc_set)()
            lock.wait()
            results = lock.result            

            # loop through the results and create menu
            # should not use imdbpy objects here as imdbpy should be encapsulated by FxdImdb
            # but for now it's to much work to do this the right way. 
            # It works so let's deal with it later.
            for movie in results:
                try:
                    # OK, we have a regular movie here, no nested episodes
                    items.append(menu.MenuItem('%s (%s) (%s)' % \
                                (movie['long imdb title'], movie['kind'], movie.movieID), 
                                 self.imdb_create_fxd, (movie.movieID, movie['kind'])))
                except Unicode, e:
                    print e

        except (FxdImdb_Error) as error:
            logger.warning('%s', error)
            dlg.hide()
            dialog.show_message(_('Connection to IMDB failed'))
            return

        dlg.hide()

        if config.IMDB_AUTOACCEPT_SINGLE_HIT and len(items) == 1:
            self.imdb_create_fxd(arg=items[0].arg, menuw=menuw)
            return

        if items:
            moviemenu = menu.Menu(_('IMDB Query'), items, 
                self.item.skin_fxd, item_types = '%s default' % self.item.type)
            # we see if the item has individual skin and load it if so 
            menuw.pushmenu(moviemenu)
            return

        dialog.show_message(_('No information available from IMDB'))
        return
Example #10
0
    def subs_search(self, arg=None, menuw=None):
        """
        Search subtitle website for subtitles for this item
        """
        self.subs = {}
        items     = []
        dlg       = None
    
        try:
            #get the subtitles from each active handler
            for handler in self.get_handlers().values():
                dlg = dialog.show_working_indicator(_('Searching %s...' % (handler['name'])))

                if self.item.subitems:
                    for i in range(len(self.item.subitems)):
                        lock = kaa.ThreadCallable(handler.get_subs, 
                                                  self.item.subitems[i].filename, 
                                                  config.SUBS_LANGS.keys())()
                        lock.wait()
                        self.subs.update(lock.result)
                else:
                    lock = kaa.ThreadCallable(handler.get_subs, 
                                              self.item.filename, 
                                              config.SUBS_LANGS.keys())()
                    lock.wait()
                    self.subs.update(lock.result)

                dlg.hide()

            for subs in sorted(self.subs.values(), key=attrgetter('handler.id', 'lang', 'vfile')):
                try:
                    lang = config.SUBS_LANGS[subs.lang]
                    if self.item.subitems:
                        items.append(menu.MenuItem(_('%s subtitles for "%s" (%s from %s)' % \
                                     (lang, trunc(os.path.basename(subs.vfile), 20), subs.fmt, subs.handler['name'])),
                                     self.subs_create_subs, (subs['id'])))
                    else:
                        items.append(menu.MenuItem(_('%s subtitles (%s from %s)' % \
                                     (lang, subs.fmt, subs.handler['name'])),
                                     self.subs_create_subs, (subs['id'])))
                    
                except (Unicode) as err:
                    logger.warning(err)

            # if we have more then 1 set of subs, we give user an option to save all
            if len(self.subs) > 1:
                items.insert(0, menu.MenuItem(_('Get all available subtitles listed below'),
                             self.subs_create_subs, ('all')))

        except (Exception), err:
            logger.error('%s' % (err))
            dialog.show_message(_('Connection to subtitle service failed'))
            return
Example #11
0
    def imdb_create_fxd(self, arg=None, menuw=None):
        """
        create fxd file for the item
        """
        dlg = dialog.show_working_indicator(_('Getting data...'))

        try:
            lock = kaa.ThreadCallable(self.fxd.retrieveImdbData, arg[0],
                                      self.fxd.ctitle[1], self.fxd.ctitle[2])()
            lock.wait()

        except FxdImdb_Error, error:
            logger.warning('%s', error)
            dlg.hide()
            return
Example #12
0
    def imdb_create_fxd(self, arg=None, menuw=None):
        """
        create fxd file for the item
        """
        dlg = dialog.show_working_indicator(_('Getting data...'))

        try:
            lock = kaa.ThreadCallable(self.fxd.retrieveImdbData, 
                arg[0], 
                self.fxd.ctitle[1], 
                self.fxd.ctitle[2])()
            lock.wait() 

        except FxdImdb_Error, error:
            logger.warning('%s', error)
            dlg.hide()
            return
Example #13
0
    def subs_delete_subs(self, arg=None, menuw=None):
        """
        delete subtitle file(s) for the item
        """
        dlg = dialog.show_working_indicator(_('Deleting subtitles...'))

        try:
            if arg == None or arg == 'all':
                # we delete all available subtitle files
                for subs in self.subfiles:
                    os.remove(subs)

            else:
                # we delete only chosen subtitle file
                logger.debug('Deleting subtitle file %s', arg)
                os.remove(arg)

        except (Exception), error:
            logger.error('%s' % (err))
            dialog.show_message(_('Error while deleting subtitles'))
Example #14
0
    def subs_create_subs(self, arg=None, menuw=None):
        """
        create subs for the item
        """
        dlg = dialog.show_working_indicator(_('Saving subtitles...'))
 
        try:
            if arg == None or arg == 'all':
                # we write all available subs
                for subs in self.subs.values():
                    subs.save()

            else:
                # we write only chosen subs
                subs = self.subs[arg]
                logger.debug('Writing subs from %s for lang %s', subs.handler['name'], subs.lang)
                subs.save()
                        
        except (Exception), err:
            logger.error('%s' % (err))
            dialog.show_message(_('Error while saving subtitles'))
Example #15
0
    def save_changes(self, arg=None, menuw=None):
        """
        Save favorite
        """
        logger.log(9, 'save_changes(arg=%r, menuw=%r)', arg, menuw)
        # this can take some time, as it means although to update the schedule
        msgtext = _('Saving the changes to this favorite.') + '\n' + _(
            'This may take some time.')
        pop = dialog.show_working_indicator(msgtext)

        if self.fav_action == 'edit':
            # first we remove the old favorite
            (result, msg) = self.recordclient.removeFavoriteNow(self.origname)
        elif self.fav_action == 'add':
            result = True

        if result:
            # create a new edited favorite
            (result, msg) = self.recordclient.addEditedFavoriteNow(
                self.fav.name, self.fav.title, self.fav.channel, self.fav.dow,
                self.fav.mod, self.fav.priority, self.fav.allowDuplicates,
                self.fav.onlyNew)
            if result:
                if menuw:
                    menuw.delete_submenu()
                    if self.fav_action == 'add':
                        menuw.refresh(reload=1)
                self.fav_action = 'edit'
                pop.hide()
            else:
                pop.hide()
                # it is important to show the user this error,
                # because that means the favorite is removed,
                # and must be created again
                msgtext = _('Save failed, favorite was lost') + (':\n%s' % msg)
                dialog.show_alert(msgtext)