def search_for_programs(self, menuw, text): pop = PopupBox(text=_('Searching, please wait...')) pop.show() (result, matches) = self.findMatches(text) pop.destroy() items = [] if result: _debug_('search found %s matches' % len(matches)) f = lambda a, b: cmp(a.start, b.start) matches.sort(f) for prog in matches: items.append(ProgramItem(self, prog, context='search')) else: if matches == 'no matches': msgtext = _('No matches found for %s') % text AlertBox(text=msgtext).show() return AlertBox(text=_('Cannot find program: %s') % matches).show() return search_menu = Menu(_('Search Results'), items, item_types='tv program menu') menuw.pushmenu(search_menu) menuw.refresh()
def SetVideoGroup(self, channel): _debug_("TunerControl: Play channel = '%s'" % channel) vg = self.fc.getVideoGroup(channel, True) _debug_("TunerControl: Play group = '%s'" % vg.desc) if (vg.group_type != "ivtv"): _debug_("TunerControl: Video group '%s' is not supported" % vg.group_type) pop = AlertBox(text=_( "This plugin only supports the ivtv video group in tv mode!")) pop.show() return if self.ivtv_init == False: ivtv_dev = ivtv.IVTV(vg.vdev) ivtv_dev.init_settings() ivtv_dev.setinput(vg.input_num) ivtv_dev.print_settings() # disable embedded vbi data self.embed = ivtv_dev.getvbiembed() ivtv_dev.setvbiembed(0) self.ivtv_init = True self.fc.chanSet(channel, True) self.curr_channel = channel
def fetchCurrentPicture(self, arg=None, menuw=None): url = 'http://antwrp.gsfc.nasa.gov/apod/%s' apodpichref = '' try: myfile = urllib.urlopen(url % 'index.html') apodpage = myfile.read() result = re.search("a href=\"(image.*)\"", apodpage) apodpichref = result.group(1) except: #unreachable or url error realurl = url % 'index.html' print 'APOD ERROR: could not open %s' % realurl AlertBox(text=_('Unable to open URL')).show() return apodfile = os.path.join(self.apoddir, os.path.basename(apodpichref)) try: urllib.urlretrieve(url % apodpichref, apodfile) imgitem = ImageItem(apodfile, self) imgitem.view(menuw=menuw) except: #unreachable or url error realurl = url % apodpichref print 'APOD ERROR: could not open %s' % realurl AlertBox(text=_('Unable to open URL')).show() return
def check_prog(self): _debug_('check_prog(self)', 2) isgood = True curtime_epoch = time.time() curtime = time.localtime(curtime_epoch) startyear = curtime[0] stopyear = curtime[0] currentmonth = curtime[1] # handle the year wraparound if int(self.stop_month) < currentmonth: stopyear = str(int(stopyear) + 1) if int(self.start_month) < currentmonth: startyear = str(int(startyear) + 1) # create utc second start time starttime = time.mktime( strptime.strptime( str(self.start_month) + " " + str(self.start_day) + " " + str(startyear) + " " + str(self.start_time) + ":00", '%m %d %Y ' + config.TV_TIMEFORMAT + ':%S')) # create utc stop time stoptime = time.mktime( strptime.strptime( str(self.stop_month) + " " + str(self.stop_day) + " " + str(stopyear) + " " + str(self.stop_time) + ":00", '%m %d %Y ' + config.TV_TIMEFORMAT + ':%S')) # so we don't record for more then maxdays (maxdays day * 24hr/day * 60 min/hr * 60 sec/min) if not abs(stoptime - starttime) < (self.MAXDAYS * 86400): if self.MAXDAYS > 1: isgood = False msg = _("Program would record for more than %d days!" ) % self.MAXDAYS AlertBox(text=_('Save Failed, recording was lost') + (': %s' % msg)).show() else: isgood = False msg = _( "Program would record for more than 1 day!") % self.MAXDAYS AlertBox(text=_('Save Failed, recording was lost') + (': %s' % msg)).show() elif not starttime < stoptime: isgood = False msg = _("start time is not before stop time.") AlertBox(text=_('Save Failed, recording was lost') + (': %s' % msg)).show() elif stoptime < curtime_epoch + self.MINPICKUP: isgood = False msg = _( "Sorry, the stop time does not give enough time for scheduler to pickup the change. Please set it to record for a few minutes longer." ) AlertBox(text=_('Save Failed, recording was lost') + (': %s' % msg)).show() else: self.prog.start = starttime self.prog.stop = stoptime return isgood
def SetVideoGroup(self, channel): """ select a channel's video group and tune to that channel """ try: channel_num = int(channel) except ValueError: channel_num = 0 logger.debug('TunerControl: Channel: %r', channel) new_vg = self.fc.getVideoGroup(channel, True) logger.debug('TunerControl: Group: type=%r, desc=%r', new_vg.group_type, new_vg.desc) logger.debug('TunerControl: Input: type=%r, num=%r', new_vg.input_type, new_vg.input_num) if new_vg.group_type != 'ivtv': logger.error('TunerControl: VideoGroup %s is not supported', new_vg) pop = AlertBox( text=_('This plugin only supports the ivtv video group!')) pop.show() return # check if videogroup switch is needed switch_vg = not self.ivtv_init or self.curr_channel is None or \ new_vg != self.fc.getVideoGroup(self.curr_channel, True) if switch_vg: # switch to a different video group logger.info('TunerControl: Set VideoGroup: %s', new_vg) ivtv_dev = ivtv.IVTV(new_vg.vdev) ivtv_dev.init_settings() self.xine.SetInput(new_vg.input_num) # disable embedded vbi data self.embed = ivtv_dev.getvbiembed() ivtv_dev.setvbiembed(0) if not self.ivtv_init: # set channel directly on v4l device, if channel is not negative if channel_num >= 0: self.fc.chanSet(channel, True) self.curr_channel = channel self.ivtv_init = True else: # set channel through xine process freq = self.fc.chanSet(channel, True, 'ivtv_xine_tv', None) if freq != 0: # channel has frequency logger.debug('TunerControl: Set frequency: %s', freq) self.xine.SetFrequency(freq) else: # channel has no frequency logger.debug('TunerControl: Channel has no frequency') self.curr_channel = channel self.xine.SeekEnd() self.ShowInfo() self.SetAudioByChannel(channel)
def getNations(self): try: req = urllib2.Request(url_nations, txdata, txheaders) response = urllib2.urlopen(req) except: print "errore url\n" popup.destroy() box = AlertBox(text=_('Failed to download channel list')) box.show() return all = '' for line in response.read().split('\n'): all += line + ' ' myDict = [] all = all.replace('\r', '').replace('\t', '').replace('\n', '') m = re.compile( r'''<a class="rb" href="([^"]*)" target="r">([^<]*)\s+(\d+)\s+</a>''', re.IGNORECASE).findall(all) if m: for url, title, channels in m: myDict = [title.strip(), url_base + url, channels] self.nation_list.append(myDict) self.mainArray['nation_list'] = self.nation_list for i in self.nation_list: print "Scarico gli stream di: " + i[0] try: req = urllib2.Request(i[1], txdata, txheaders) response = urllib2.urlopen(req) except: print "errore url\n" all = '' for line in response.read().split('\n'): all += line myChannel = [] all = all.replace('\r', '').replace('\t', '').replace('\n', '') # uncomment for qtl playlist (quicktime) #m = re.compile(r'''target="TV">([^<]*)</a></td><td class="(?:qm|qt|qr|wa)"><a class="(r|m|qu|w)" href="javascript:listen([^>]*)">([^<]*)</a> </td><td class="q"><center>(?:.*?)<font class="hd2">([^>]*)</td></tr>''', re.IGNORECASE).findall(all) # without qtl playlists m = re.compile( r'''target="TV">([^<]*)</a></td><td class="(?:qm|qr|wa)"><a class="(r|m|w)" href="javascript:listen([^>]*)">([^<]*)</a> </td><td class="q"><center>(?:.*?)<font class="hd2">([^>]*)</td></tr>''', re.IGNORECASE).findall(all) if m: nation_channels = [] for tv, gen, url, stream, desc in m: #print tv + " " + gen + " " + url + " " + stream + " " + desc myChannel = eval(url) myDict = [ util.htmlenties2txt(tv), myChannel[1], stream, util.htmlenties2txt(desc) ] # myDict = [myChannel[1], stream] nation_channels.append(myDict) self.nation_tv[i[0]] = nation_channels else: print "non trovo corrispondenze!" self.mainArray['nation_tv'] = self.nation_tv
def show_status(self, arg=None, menuw=None): t = self.rip_thread if t.current_track != -1: pop = AlertBox( text=_('Ripping in progress\nTrack %(current)d of %(total)d') % ({ 'current': t.current_track, 'total': t.max_track })) pop.show()
def SetVideoGroup(self, channel): """ select a channel's video group and tune to that channel """ try: channel_num = int(channel) except ValueError: channel_num = 0 logger.debug('TunerControl: Channel: %r', channel) new_vg = self.fc.getVideoGroup(channel, True) logger.debug('TunerControl: Group: type=%r, desc=%r', new_vg.group_type, new_vg.desc) logger.debug('TunerControl: Input: type=%r, num=%r', new_vg.input_type, new_vg.input_num) if new_vg.group_type != 'ivtv': logger.error('TunerControl: VideoGroup %s is not supported', new_vg) pop = AlertBox(text=_('This plugin only supports the ivtv video group!')) pop.show() return # check if videogroup switch is needed switch_vg = not self.ivtv_init or self.curr_channel is None or \ new_vg != self.fc.getVideoGroup(self.curr_channel, True) if switch_vg: # switch to a different video group logger.info('TunerControl: Set VideoGroup: %s', new_vg) ivtv_dev = ivtv.IVTV(new_vg.vdev) ivtv_dev.init_settings() self.xine.SetInput(new_vg.input_num) # disable embedded vbi data self.embed = ivtv_dev.getvbiembed() ivtv_dev.setvbiembed(0) if not self.ivtv_init: # set channel directly on v4l device, if channel is not negative if channel_num >= 0: self.fc.chanSet(channel, True) self.curr_channel = channel self.ivtv_init = True else: # set channel through xine process freq = self.fc.chanSet(channel, True, 'ivtv_xine_tv', None) if freq != 0: # channel has frequency logger.debug('TunerControl: Set frequency: %s', freq) self.xine.SetFrequency(freq) else: # channel has no frequency logger.debug('TunerControl: Channel has no frequency') self.curr_channel = channel self.xine.SeekEnd() self.ShowInfo() self.SetAudioByChannel(channel)
def getNations(self): try: req = urllib2.Request(url_nations, txdata, txheaders) response = urllib2.urlopen(req) except: print "errore url\n" popup.destroy() box = AlertBox(text=_("Failed to download channel list")) box.show() return all = "" for line in response.read().split("\n"): all += line + " " myDict = [] all = all.replace("\r", "").replace("\t", "").replace("\n", "") m = re.compile(r"""<a class="rb" href="([^"]*)" target="r">([^<]*)\s+(\d+)\s+</a>""", re.IGNORECASE).findall( all ) if m: for url, title, channels in m: myDict = [title.strip(), url_base + url, channels] self.nation_list.append(myDict) self.mainArray["nation_list"] = self.nation_list for i in self.nation_list: print "Scarico gli stream di: " + i[0] try: req = urllib2.Request(i[1], txdata, txheaders) response = urllib2.urlopen(req) except: print "errore url\n" all = "" for line in response.read().split("\n"): all += line myChannel = [] all = all.replace("\r", "").replace("\t", "").replace("\n", "") # uncomment for qtl playlist (quicktime) # m = re.compile(r'''target="TV">([^<]*)</a></td><td class="(?:qm|qt|qr|wa)"><a class="(r|m|qu|w)" href="javascript:listen([^>]*)">([^<]*)</a> </td><td class="q"><center>(?:.*?)<font class="hd2">([^>]*)</td></tr>''', re.IGNORECASE).findall(all) # without qtl playlists m = re.compile( r"""target="TV">([^<]*)</a></td><td class="(?:qm|qr|wa)"><a class="(r|m|w)" href="javascript:listen([^>]*)">([^<]*)</a> </td><td class="q"><center>(?:.*?)<font class="hd2">([^>]*)</td></tr>""", re.IGNORECASE, ).findall(all) if m: nation_channels = [] for tv, gen, url, stream, desc in m: # print tv + " " + gen + " " + url + " " + stream + " " + desc myChannel = eval(url) myDict = [util.htmlenties2txt(tv), myChannel[1], stream, util.htmlenties2txt(desc)] # myDict = [myChannel[1], stream] nation_channels.append(myDict) self.nation_tv[i[0]] = nation_channels else: print "non trovo corrispondenze!" self.mainArray["nation_tv"] = self.nation_tv
def remove_program(self, arg=None, menuw=None): """ remove a program from schedule """ (result, msg) = record_client.removeScheduledRecording(self.prog) if result: if menuw: menuw.back_one_menu(arg='reload') msgtext = _( '"%s" has been removed from schedule') % self.prog.title AlertBox(text=msgtext).show() else: AlertBox(text=_('Remove Failed') + (': %s' % msg)).show()
def rename(self, menuw, newname=''): """ renames the item """ logger.log(9, 'rename %s to %s', self.item.name, newname) oldname = self.item.name if self.item.rename(newname): AlertBox(text=_('Rename %s to %s.') % (oldname, newname)).show() else: AlertBox(text=_('Rename %s to %s, failed.') % (oldname, newname)).show() menuw.delete_menu() menuw.refresh()
def find_more(self, arg=None, menuw=None): """ Find more of this program """ _debug_(String('searching for: %s' % self.prog.title)) pop = AlertBox(text=_('Searching, please wait...')) pop.show() items = [] (result, matches) = record_client.findMatches(self.prog.title) pop.destroy() if result: _debug_('search found %s matches' % len(matches)) f = lambda a, b: cmp(a.start, b.start) matches.sort(f) for prog in matches: items.append(ProgramItem(self, prog, context='search')) else: if matches == 'no matches': msgtext = _('No matches found for %s') % self.prog.title AlertBox(text=msgtext).show() return AlertBox(text=_('findMatches failed: %s') % matches).show() return search_menu = menu.Menu(_('Search Results'), items, item_types='tv program menu') menuw.pushmenu(search_menu) menuw.refresh()
def get_friendly_channel(channel_id): channel_name = tv_util.get_chan_displayname(channel_id) if not channel_name: AlertBox(text=_('Could not find TV channel %s') % channel_id).show() return channel_name
def start_tv(mode=None, channel_id=None): tuner_id = get_tunerid(channel_id) p = plugin.getbyname(plugin.TV) if p is None: AlertBox(text=_('Cannot get TV plug-in')).show() return p.Play(mode, tuner_id)
def display_schedule(self, arg=None, menuw=None): if not self.recordclient.pingNow(): AlertBox(self.recordclient.recordserverdown).show() return items = self.get_items() if not len(items): AlertBox(_('Nothing scheduled.')).show() return schedule_menu = menu.Menu(_('Scheduled Recordings'), items, reload_func=self.reload, item_types='tv program menu') self.menuw = menuw rc.app(None) menuw.pushmenu(schedule_menu) menuw.refresh()
def clean_up_burndir(self): _debug_('clean_up_burndir (self)') """ Tries to cleanup /tmp/burndir, if it not exists it try's to create it the final result of this function must a be a existing and empty /tmp/burnlist """ try: _debug_('in Try 2') if not os.stat("/tmp/burnlist"): _debug_('in if 2') os.makedirs("/tmp/burnlist", 0777) else: _debug_('in else 2') if os.listdir("/tmp/burnlist"): os.system('rm -rf /tmp/burnlist/*') except: _debug_('in except 2') os.makedirs("/tmp/burnlist", 0777) os.system('rm -rf /tmp/burnlist/*') try: _debug_('in Try 1') if os.stat("/tmp/burnlist"): _debug_('in if 1') for a in os.listdir("/tmp/burnlist"): os.unlink("/tmp/burnlist/" + a) except: _debug_('in except 1') AlertBox(text='"Aborted, could not empty /tmp/burnlist"') _debug_('clean_up_burndir end1') return 0 _debug_('clean_up_burndir end') return 1
def display_recitem(self, arg=None, menuw=None): _debug_('display_recitem(self, arg=None, menuw=None)', 2) if not self.recordclient.pingNow(): AlertBox(self.recordclient.recordserverdown).show() return self.make_newprog() items = [] items.append(menu.MenuItem(_('Modify name'), action=self.mod_name)) items.append( menu.MenuItem(_('Modify channel'), action=self.mod_channel)) items.append( menu.MenuItem(_('Modify start month'), action=self.mod_start_month)) items.append( menu.MenuItem(_('Modify start day'), action=self.mod_start_day)) items.append( menu.MenuItem(_('Modify start time'), action=self.mod_start_time)) items.append( menu.MenuItem(_('Modify stop month'), action=self.mod_stop_month)) items.append( menu.MenuItem(_('Modify stop day'), action=self.mod_stop_day)) items.append( menu.MenuItem(_('Modify stop time'), action=self.mod_stop_time)) items.append(menu.MenuItem(_('Save'), action=self.save_changes)) manualrecord_menu = menu.Menu(_('Record Item Menu'), items, item_types='tv manual record menu') manualrecord_menu.infoitem = self menuw.pushmenu(manualrecord_menu) menuw.refresh()
def view_favorites(self, arg=None, menuw=None): _debug_('view_favorites(arg=%r, menuw=%r)' % (arg, menuw), 2) if not self.recordclient.pingNow(): AlertBox(self.recordclient.recordserverdown).show() return items = self.get_items() if not len(items): AlertBox(_('No favorites.')).show() return favorite_menu = menu.Menu(_( 'View Favorites'), items, reload_func=self.reload, item_types='tv favorite menu') self.menuw = menuw rc.app(None) menuw.pushmenu(favorite_menu) menuw.refresh()
def schedule_program(self, arg=None, menuw=None): """ add a program to schedule """ (result, msg) = record_client.scheduleRecording(self.prog) if result: if menuw: if self.context == 'search': menuw.delete_menu() menuw.delete_menu() menuw.back_one_menu(arg='reload') msgtext = _( '"%s" has been scheduled for recording') % self.prog.title AlertBox(text=msgtext).show() else: AlertBox(text=_('Scheduling Failed') + (': %s' % msg)).show()
def clean_up_burndir(self): """ Tries to clean-up /tmp/burndir, if it not exists then try to create it the final result of this function must a be a existing and empty /tmp/burnlist """ logger.debug('clean_up_burndir()') try: logger.debug('in Try 2') if not os.stat(self.burn_list): logger.debug('in if 2') os.makedirs(self.burn_list, 0777) else: logger.debug('in else 2') if os.listdir(self.burn_list): os.system('rm -rf %s' % os.path.join(self.burn_list, '*')) except: logger.debug('in except 2') os.makedirs(self.burn_list, 0777) os.system('rm -rf %s' % os.path.join(self.burn_list, '*')) try: logger.debug('in Try 1') if os.stat(self.burn_list): logger.debug('in if 1') for a in os.listdir(self.burn_list): os.unlink(os.path.join(self.burn_list, a)) except: logger.debug('in except 1') AlertBox(text='Aborted, could not empty %s' % self.burn_list) logger.debug('clean_up_burndir end1') return 0 logger.debug('clean_up_burndir end') return 1
def save_changes(self, arg=None, menuw=None): """ Save favorite """ _debug_('save_changes(arg=%r, menuw=%r)' % (arg, menuw), 2) # 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 = PopupBox(text=msgtext) pop.show() 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.destroy() else: pop.destroy() # 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) AlertBox(text=msgtext).show()
def rem_favorite(self, arg=None, menuw=None): """ Remove favorite """ name = self.origname (result, msg) = record_client.removeFavorite(name) if result: # if this is successfull if menuw: # reload the menu that we return to menuw.back_one_menu(arg='reload') # and show a short message of success msgtext = text = _('"%s" has been removed from favorites') % name AlertBox(text=msgtext).show() else: # if all fails then we should show an error AlertBox(text=_('Remove Failed') + (': %s' % msg)).show()
def add_job(self, type, source, title=None): global drive_jobs drive_jobs[source] = DVDCopyJob(type, source, title) AlertBox(width=400, height=200, text=_("Copy started"), handler=self.mopup).show()
def get_formatted_cd_info(self, device): cd_info = mmpython.parse(device) if cd_info is None: logger.error(_('No CD medadata available')) popup_string = _('CD info not found!') AlertBox(text=popup_string).show() return [ 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown' ] current_time = time.strftime('%d-%b-%y-%I:%M%P') artist = _('Unknown Artist') + ' ' + current_time + ' - ' + _('RENAME') album = _('Unknown CD Album') + ' ' + current_time + ' - ' + _( 'RENAME') genre = _('Other') year = time.strftime('%Y') # Check if getting CDDB data failed -is there a better way to do this? # Give some defaults with a timestamp to uniqueify artist and album names. # So that subsequent CDs with no CDDB data found don't overwrite each other. if cd_info.title is None and cd_info.artist is None: logger.warning(_('No CDDB data available to mmpython')) popup_string = _( 'CD info not found!\nMust manually rename files\nwhen finished ripping' ) AlertBox(text=popup_string).show() else: # If valid data was returned from mmpython/CDDB album = self.fix_case(self.replace_special_char( cd_info.title, '-')) artist = self.fix_case( self.replace_special_char(cd_info.artist, '-')) genre = self.replace_special_char(cd_info.tracks[0].genre, '-') year = cd_info.year song_names = [] for track in cd_info.tracks: song_names.append( self.fix_case(self.replace_special_char(track.title, '-'))) if hasattr(cd_info, 'mixed') and cd_info.mixed: # remove last tracks if it's a mixed cd song_names = song_names[:-1] return [cd_info.id, artist, album, genre, year, song_names]
def get_tunerid(channel_id): tuner_id = None for vals in config.TV_CHANNELS: tv_channel_id, tv_display_name, tv_tuner_id = vals[:3] if tv_channel_id == channel_id: return tv_tuner_id AlertBox(text=_('Could not find TV channel %s') % channel_id).show() return None
def create_job(self, menuw=None, arg=None): _debug_('create_job(self, arg=%r, menuw=%r)' % (arg, menuw), 1) profile = arg #we are going to create a job and send it to the encoding server, this can take some time while analyzing box = PopupBox(text=_('Please wait, analyzing video...')) box.show() (status, resp) = initEncodeJob(self.source, self.output, self.title) _debug_('initEncodeJob:status:%s resp:%s' % (status, resp)) box.destroy() if not status: self.error(resp) return idnr = resp (status, resp) = setContainer(idnr, profile['container']) _debug_('setContainer:status:%s resp:%s' % (status, resp)) if not status: self.error(resp) return multipass = profile['numpasses'] > 1 (status, resp) = setVideoCodec(idnr, profile['videocodec'], 0, multipass, profile['videobitrate']) _debug_('setVideoCodec:status:%s resp:%s' % (status, resp)) if not status: self.error(resp) return (status, resp) = setAudioCodec(idnr, profile['audiocodec'], profile['audiobitrate']) _debug_('setAudioCodec:status:%s resp:%s' % (status, resp)) if not status: self.error(resp) return #(status, resp) = setVideoFilters(idnr, vfilters) #_debug_('setVideoFilters:status:%s resp:%s' % (status, resp)) #And finally, qeue and start the job (status, resp) = queueIt(idnr, True) _debug_('queueIt:status:%s resp:%s' % (status, resp)) if not status: self.error(resp) return self.menuw = menuw AlertBox(width=400, height=200, text=_('Encoding started'), handler=self.mopup).show() _debug_('boe')
def play(self, arg=None, menuw=None, alternateplayer=False): """ Check url before playing """ # Check to see if there's some intermediate file... try: trailerdata = urllib2.urlopen(self.trailer['url']).read(1024) except HTTPError, e: AlertBox("%s %s: %s" % (_("Could not retrieve URL"), self.trailer['url'], e)).show() return
def rem_favorite(self, arg=None, menuw=None): """ Remove favorite """ _debug_('rem_favorite(arg=%r, menuw=%r)' % (arg, menuw), 2) name = self.origname (result, msg) = self.recordclient.removeFavoriteNow(name) if result: # if this is successfull if menuw: menuw.delete_submenu() menuw.refresh(reload=1) # and show a short message of success msgtext = text=_('"%s" has been removed from favorites') % name AlertBox(text=msgtext).show() else: # if all fails then we should show an error msgtext = _('Remove failed')+(':\n%s' % msg) AlertBox(text=msgtext).show()
def check_program(self, program=None, program_name=None): _debug_('check_program (self, program=None, program_name=None) ') if not (os.path.exists(program) and os.path.isfile(program) and os.access(program, os.X_OK)): _debug_("Progam Error") AlertBox(text=_('Cannot find %s (%s). '+\ 'Please configure the right path in your config file and make sure it has the right permissions.' \ % (program_name,program)), handler=self.menu_back).show() return 0 else: return 1
def burn(self, arg=None, menuw=None): _debug_('burn (self, arg=None, menuw=None)') if self.burn_mode == "data_cd": self.burn_data_cd() elif self.burn_mode == "dvd_video": self.burn_dvd_video() elif self.burn_mode == "audio_cd": self.burn_audio_cd() else: AlertBox(text=_('Not Yet implemented :)')).show() return
def get_items(self): items = [] if not self.recordclient.pingNow(): AlertBox(self.recordclient.recordserverdown).show() return [] (status, progs) = self.recordclient.getScheduledRecordingsNow() if status: f = lambda a, b: cmp(a.start, b.start) progs.sort(f) for prog in progs: items.append(ProgramItem(self, prog, context='schedule')) else: AlertBox( _('Get scheduled recordings failed') + (':\n%s' % schedule)).show() return [] return items
def save_changes(self, arg=None, menuw=None): _debug_('save_changes(self, arg=None, menuw=None)', 2) result = self.check_prog() if result: (result, msg) = record_client.scheduleRecording(self.prog) if not result: AlertBox(text=_('Save Failed, recording was lost') + (': %s' % msg)).show() else: if menuw: menuw.back_one_menu(arg='reload')
def getCategories(self): for i in categories: try: print "download " + i[1] + " url: " + url_ + i[0] req = urllib2.Request(url_ + i[0], txdata, txheaders) response = urllib2.urlopen(req) except: print "errore url\n" # popup.destroy() box = AlertBox(text=_("Failed to download categories list")) box.show() return all = "" myDict = [] for line in response.read().split("\n"): all += line myChannel = [] all = all.replace("\r", "").replace("\t", "").replace("\n", "") # uncomment for qtl playlist (quicktime) # m = re.compile(r'''<tr><td class="q"><font class="hd2">([^<]*)</font></td><td class="name" width="120"><font class="new">(?:(?:[^<]*)|(?:\d\d\d\d-\d\d-\d\d<BR>))</font><a class="travel" href="(?:[^"]*)" target="TV">([^<]*)</a></td><td class="(?:qm|qt|qr|wa)"><a class="(r|m|qu|w)" href="javascript:listen([^>]*)">([^<]*)</a> </td><td class="q"><center>(?:.*?)></td><td class="qe"><font class="hd2">([^>]*)</td></tr>''', re.IGNORECASE).findall(all) # without qtl playlists m = re.compile( r"""<tr><td class="q"><font class="hd2">([^<]*)</font></td><td class="name" width="120"><font class="new">(?:(?:[^<]*)|(?:\d\d\d\d-\d\d-\d\d<BR>))</font><a class="travel" href="(?:[^"]*)" target="TV">([^<]*)</a></td><td class="(?:qm|qr|wa)"><a class="(r|m|w)" href="javascript:listen([^>]*)">([^<]*)</a> </td><td class="q"><center>(?:.*?)></td><td class="qe"><font class="hd2">([^>]*)</td></tr>""", re.IGNORECASE, ).findall(all) # m = re.compile(r'''<font class="hd2">([^<]*)</font>(?:.*?)target="TV">([^<]*)</a></td><td class="qm"><a class="(r|m|qu)" href="javascript:listen([^>]*)">([^<]*)</a> </td><td class="q"><center>(?:.*?)<font class="hd2">([^>]*)</td></tr>''', re.IGNORECASE).findall(all) if m: categories_channels = [] for state, tv, gen, url, stream, desc in m: # print state + " " + tv + " " + gen + " " + url + " " + stream + " " + desc myChannel = eval(url) mydesc = util.htmlenties2txt(desc) + "\n" + util.htmlenties2txt(state) myDict = [util.htmlenties2txt(tv), myChannel[1], stream, mydesc] categories_channels.append(myDict) self.categories_tv[i[1]] = categories_channels else: print "non trovo corrispondenze!" self.mainArray["categories_tv"] = self.categories_tv
def cwd(self, arg=None, menuw=None): """ Download the url and create a menu with more links """ txdata = None txheaders = { 'User-Agent': 'freevo %s (%s)' % (config.VERSION, sys.platform), 'Accept-Language': 'en-us', } popup = PopupBox(text=_('Downloading link list...')) popup.show() try: req = urllib2.Request(self.url, txdata, txheaders) response = urllib2.urlopen(req) except: popup.destroy() box = AlertBox(text=_('Failed to download %s') % self.url) box.show() return # base for this url self.base = response.geturl()[:response.geturl().rfind('/')+1] # normalize the text so that it can be searched all = '' for line in response.read().split('\n'): all += line + ' ' all = all.replace('\r', '').replace('\t', ' ') # find names for links (text between <a>) name_map = {} m = re.compile('href="([^"]*)">([^<]*)</a>', re.I).findall(all) if m: for url, title in m: while title.find(' ') > 0: title = title.replace(' ', ' ') title = util.htmlenties2txt(title.lstrip().rstrip()) name_map[url] = title # now search for links, normal links and movie links together all_urls = [] movie_regexp = re.compile('.*(mov|avi|mpg|asf)$', re.I) for m in (re.compile('href="(.*?)"', re.I).findall(all), re.compile('"(http.[^"]*.(mov|avi|mpg|asf))"', re.I).findall(all)): if m: for url in m: if isinstance(url, tuple): url = url[0] all_urls.append(url) # now split all_urls into link_urls (more links) and # movie_urls (video) link_urls = [] movie_urls = [] if all_urls: for url in all_urls: long_url = self.make_complete_url(response.geturl(), url) # bad url? if not long_url: continue # find a title title = url if name_map.has_key(url): title = name_map[url] else: title = title.replace('.html', '').replace('.php', '') # remove blacklisted urls for b in self.blacklist_regexp: if b(long_url): break else: # movie or link? if movie_regexp.match(long_url): movie_urls.append((long_url, url, title)) else: link_urls.append((long_url, url, title)) items = [] # add all link urls if link_urls: for long, short, title in link_urls: # should all links be displayed? if (not self.all_links) and long.find(self.base) != 0: continue # don't display self if long == self.url: continue # search for duplicate links for l in items: if l.url == long: # increase counter, this link seems to be # important l.counter += 1 break else: # add link as new new l = Link(title, long, self.blacklist_regexp, self.autoplay, self.all_links, self) l.url_name = short l.image = None items.append(l) # sort all items items.sort(lambda l, o: cmp(l.sort().upper(), o.sort().upper())) # add part of the url to the name in case a title is used for # more than one item for l in items: for o in items: if l.name == o.name and l.name.find('(') == -1 and not l == o: # duplicate found, get last part of the url url = l.url[l.url.rfind('/')+1:] if not url: url = l.url[l.url[:-1].rfind('/')+1:] if url: l.name = '%s (%s)' % (l.name, url) # same for the other url = o.url[o.url.rfind('/')+1:] if not url: url = o.url[o.url[:-1].rfind('/')+1:] if url: o.name = '%s (%s)' % (o.name, url) # now search for movies movies = [] if movie_urls: for long, short, title in movie_urls: # search for duplicate links for l in movies: if l.filename == long: break else: movies.append(VideoItem(long, self, parse=False)) if title.find('/') != -1: title = 'Video: ' + long[long.rfind('/')+1:] movies[-1].name = title # all done popup.destroy() if len(movies) == 1 and arg=='autoplay': movies[0].play(menuw=menuw) elif len(movies) == 1 and arg=='autoplay_max': movies[0].play_max_cache(menuw=menuw) elif items or movies: menuw.pushmenu(menu.Menu(self.name, movies + items))
def show_status(self, arg=None, menuw=None): t = self.rip_thread if t.current_track != -1: pop = AlertBox(text=_('Ripping in progress\nTrack %(current)d of %(total)d') % ({ 'current': t.current_track, 'total': t.max_track})) pop.show()