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: _debug_('new device %s' % (d)) for device, message, action in config.USB_HOTPLUG: if d == device: pop = PopupBox(text=message) pop.show() os.system(action) pop.destroy() break else: changes = True for d in self.devices: changes = True _debug_('removed device %s' % (d)) if changes: rc.post_event(plugin.event('USB')) self.devices = current_devices
def play(self, arg=None, menuw=None): """ Play this Podcast """ download_failed = False self.download_url = self.item_url if not os.path.exists(self.filename) or os.path.getsize(self.filename) < 1024: try: background = BGDownload(self.download_url, self.filename, self.results) background.start() popup = PopupBox(text=_('Fetching "%s"...' % self.name)) popup.show() try: size = 0 for i in range(int(config.VPODCAST_BUFFERING_TIME)): if os.path.exists(self.filename): size = os.stat(self.filename)[stat.ST_SIZE] if size > config.VPODCAST_BUFFERING_SIZE: break time.sleep(1.0) else: if size < config.VPODCAST_BUFFERING_SIZE: download_failed = True finally: popup.destroy() if download_failed: AlertBox(text=_('Fetching "%s" failed\nNo data') % self.filename).show() return except youtube.DownloadError, why: AlertBox(text=_('Fetching "%(filename)s" failed:\n%(why)s') % ({ 'filename': self.filename, 'why': why})).show() return
def move_tray(self, direction='toggle'): """ Move the tray. direction can be toggle/open/close """ global im_thread if direction == 'toggle': if self.is_tray_open(): direction = 'close' else: direction = 'open' if direction == 'open' and self.can_eject: pop = PopupBox(text=_('Ejecting disc in drive %s') % self.drivename) pop.show() if util.is_mounted(self.mountdir): self.umount() self.mount_ref_count = 0 self.open_tray() pop.destroy() elif direction == 'close' and self.can_close: pop = PopupBox(text=_('Reading disc in drive %s') % self.drivename) pop.show() self.close_tray() if im_thread: im_thread.check_all() pop.destroy()
def create_podcast_menu(self, arg=None, menuw=None): """ Create the main menu item for the video podcasts """ popup = PopupBox(text=_('Fetching podcasts...')) popup.show() podcast_menu_items = [] for location in config.VPODCAST_LOCATIONS: url = location[1] image_path = config.VPODCAST_DIR + '/' + location[ 0] + '/' + 'cover.jpg' if self.check_logo(image_path): p = podcast() p.open_rss(url) p.rss_title() name = p.rss_title try: image_url = p.rss_image self.download(image_url, image_path) except: print 'No image in RSS' if (len(config.VPODCAST_DIR) == 0): podcast_items += [ menu.MenuItem(_('Set VPODCAST_DIR in local_conf.py'), menwu.goto_prev_page, 0) ] podcast_menu_items += [menu.MenuItem(_(location[0]), action=self.create_podcast_submenu, \ arg=location, image=image_path)] popup.destroy() podcast_main_menu = menu.Menu(_('Video Podcasts'), podcast_menu_items) rc.app(None) menuw.pushmenu(podcast_main_menu) menuw.refresh()
def play(self, arg=None, menuw=None): """ Play this Podcast""" # play the item. isYT = self.vp_url.find('youtube.com') #YouTube podcast isMC = self.vp_url.find('metacafe.com') #Metacafe podcast if isYT != -1: self.download_url = self.youtube(self.vp_url) elif isMC != -1: self.download_url = self.metacafe(self.vp_url) else: self.download_url = self.vp_url if not os.path.exists(self.filename): background = BGDownload(self.download_url, self.filename) background.start() popup = PopupBox(text=_('Buffering podcast...')) popup.show() time.sleep(20) # 20s. buffering time popup.destroy() # call the play funuction of VideoItem VideoItem.play(self, menuw=menuw, arg=arg)
def copy_fxd(self, arg=None, menuw=None): """ Find all fxd files inside a given folder, and copy them to the configured destination folder """ self.item.media.mount() box = PopupBox(text=_('Finding and copying FXD files...')) box.show() time.sleep(1) fxds = util.fileops.match_files_recursively(self.item.dir, ['fxd']) msg = '' for i in fxds: logger.debug('file: %r', i) self.cwd = os.path.dirname(i) parser = util.fxdparser.FXD(i) parser.set_handler('movie', self.fxdparser) parser.set_handler('movie', self.fxdparsew, mode='w') parser.parse() if self.ismovie: parser.tree.filename = '%s/%s' % ( self.archives, os.path.basename(parser.filename)) try: parser.save() self.nfiles += 1 except: print "Error while trying to write ", parser.tree.filename msg = _( "There was a error while trying to write the fxd file") if self.coverimg: coverfrom = os.path.join(self.cwd, self.coverimg) coverto = os.path.join(self.archives, self.coverimg) try: shutil.copy(coverfrom, coverto) # is there a better way to do this? os.chmod(coverto, 0644) except: print "Error while trying to copy %s to %s" % ( coverfrom, coverto) msg = _("But I couldn't copy a cover image file.") self.ismovie = False box.destroy() box = PopupBox(text=_('%(nfiles)d fxd files archived. %(msg)s') % ({ 'nfiles': self.nfiles, 'msg': msg })) box.show() time.sleep(3) box.destroy() self.item.media.umount() #reset a few variables self.nfiles = 0 msg = ''
def create_thumbnail(self, arg=None, menuw=None): """ Create a thumbnail as image icon """ import util.videothumb pop = PopupBox(text=_('Please wait....')) pop.show() util.videothumb.snapshot(self.filename) pop.destroy() menuw.delete_submenu()
def create_thumbnail(self, arg=None, menuw=None): """ create a thumbnail as image icon """ import util.videothumb pop = PopupBox(text=_('Please wait....')) pop.show() util.videothumb.snapshot(self.filename) pop.destroy() if menuw.menustack[-1].selected != self: menuw.back_one_menu()
def copy_fxd(self, arg=None, menuw=None): """ Find all fxd files inside a given folder, and copy them to the configured destination folder """ self.item.media.mount() box = PopupBox(text=_('Finding and copying FXD files...')) box.show() time.sleep(1) fxds = util.fileops.match_files_recursively( self.item.dir , [ 'fxd' ]) msg='' for i in fxds: logger.debug('file: %r', i) self.cwd = os.path.dirname(i) parser = util.fxdparser.FXD(i) parser.set_handler('movie', self.fxdparser) parser.set_handler('movie', self.fxdparsew, mode='w') parser.parse() if self.ismovie: parser.tree.filename= '%s/%s' % (self.archives, os.path.basename(parser.filename) ) try: parser.save() self.nfiles += 1 except: print "Error while trying to write ", parser.tree.filename msg = _("There was a error while trying to write the fxd file") if self.coverimg: coverfrom = os.path.join(self.cwd, self.coverimg) coverto = os.path.join(self.archives, self.coverimg) try: shutil.copy(coverfrom, coverto) # is there a better way to do this? os.chmod(coverto, 0644) except: print "Error while trying to copy %s to %s" % (coverfrom, coverto) msg = _("But I couldn't copy a cover image file.") self.ismovie = False box.destroy() box = PopupBox(text=_('%(nfiles)d fxd files archived. %(msg)s') % ({'nfiles': self.nfiles, 'msg': msg})) box.show() time.sleep(3) box.destroy() self.item.media.umount() #reset a few variables self.nfiles = 0 msg = ''
def create_podcast_submenu(self, arg=None, menuw=None, image=None): """ create the sub-menu for the podcast """ popup = PopupBox(text=_('Fetching podcast...')) popup.show() url = arg[1] p = podcast() p.open_rss(url) p.rss_title() p.rss_count() podcast_items = [] for pc_location in range(p.rss.count): p.rss_item(pc_location) if p.image != None: image = config.VPODCAST_DIR + '/' + arg[ 0] + '/' + p.title + '.jpg' self.download(p.image, image) else: image = None url = p.link name = p.title if url != 'ERROR': isYT = url.find('youtube.com') isMC = url.find('metacafe.com') if isYT == -1 and isMC == -1: file_ext = '.avi' else: file_ext = '.flv' filename = config.VPODCAST_DIR + '/' + arg[ 0] + '/' + name + file_ext podcast_items += [menu.MenuItem(_(p.title), \ action=VPVideoItem(filename, url, self), arg=None, image=image)] popup.destroy() if (len(podcast_items) == 0): podcast_items += [ menu.MenuItem(_('No Podcast locations found'), menwu.goto_prev_page, 0) ] podcast_sub_menu = menu.Menu(_('Video Podcasts'), podcast_items) rc.app(None) menuw.pushmenu(podcast_sub_menu) menuw.refresh()
def play(self, arg=None, menuw=None): """ Play this Podcast """ download_failed = False self.download_url = self.item_url if not os.path.exists( self.filename) or os.path.getsize(self.filename) < 1024: try: background = BGDownload(self.download_url, self.filename, self.results) background.start() popup = PopupBox(text=_('Fetching "%s"...' % self.name)) popup.show() try: size = 0 for i in range(int(config.VPODCAST_BUFFERING_TIME)): if os.path.exists(self.filename): size = os.stat(self.filename)[stat.ST_SIZE] if size > config.VPODCAST_BUFFERING_SIZE: break time.sleep(1.0) else: if size < config.VPODCAST_BUFFERING_SIZE: download_failed = True finally: popup.destroy() if download_failed: AlertBox(text=_('Fetching "%s" failed\nNo data') % self.filename).show() return except youtube.DownloadError, why: AlertBox(text=_('Fetching "%(filename)s" failed:\n%(why)s') % ({ 'filename': self.filename, 'why': why })).show() return
def searchProg(self, find): if DEBUG: print String('SEARCHING FOR: %s' % find) pop = PopupBox(parent=self, text=_('Searching, please wait...')) pop.show() (result, matches) = record_client.findMatches(find) if result: if DEBUG: print 'FOUND: %s' % len(matches) i = 0 self.results.items = [] if len(matches) > self.num_shown_items: self.results.show_v_scrollbar = 1 else: self.results.show_v_scrollbar = 0 f = lambda a, b: cmp(a.start, b.start) matches.sort(f) for prog in matches: i += 1 self.results.add_item(text='%s %s: %s' % \ (time.strftime('%b %d %I:%M %p', time.localtime(prog.start)), tv_util.get_chan_displayname(prog.channel_id), prog.title), value=prog) space_left = self.num_shown_items - i if space_left > 0: for i in range(space_left): self.results.add_item(text=' ', value=0) pop.destroy()
def move_tray(self, dir='toggle', notify=1): """ Move the tray. dir can be toggle/open/close """ if dir == 'toggle': if self.is_tray_open(): dir = 'close' else: dir = 'open' if dir == 'open': _debug_('Ejecting disc in drive %s' % self.drivename, 2) if notify: pop = PopupBox(text=_('Ejecting disc in drive %s') % self.drivename) pop.show() try: fd = os.open(self.devicename, os.O_RDONLY | os.O_NONBLOCK) if os.uname()[0] == 'FreeBSD': s = ioctl(fd, CDIOCEJECT, 0) else: s = ioctl(fd, CDROMEJECT) os.close(fd) except: try: traceback.print_exc() except IOError: # believe it or not, this sometimes causes an IOError if # you've got a music track playing in the background (detached) pass # maybe we need to close the fd if ioctl fails, maybe # open fails and there is no fd try: os.close(fd) except: pass self.tray_open = 1 if notify: pop.destroy() elif dir == 'close': _debug_('Inserting %s' % self.drivename, 2) if notify: pop = PopupBox(text=_('Reading disc in drive %s') % self.drivename) pop.show() # close the tray, identifymedia does the rest, # including refresh screen try: fd = os.open(self.devicename, os.O_RDONLY | os.O_NONBLOCK) if os.uname()[0] == 'FreeBSD': s = ioctl(fd, CDIOCCLOSE, 0) else: s = ioctl(fd, CDROMCLOSETRAY) os.close(fd) except: traceback.print_exc() # maybe we need to close the fd if ioctl fails, maybe # open fails and there is no fd try: os.close(fd) except: pass self.tray_open = 0 global im_thread if im_thread: im_thread.check_all() if notify: pop.destroy()
def create_podcast_submenu(self, arg=None, menuw=None, image=None): """ create the sub-menu for the podcast """ name, rss_url, feed_type = arg podcastdir = _name_to_filename(name) popup = PopupBox(text=_('Fetching podcast items...')) popup.show() try: p = Podcast(rss_url, feed_type) feed = p.feed() rss_title = p.rss_title() rss_stitle = _name_to_filename(rss_title) rss_description = p.rss_description() rss_imageurl = p.rss_image() if rss_imageurl: image_path = os.path.join(config.VPODCAST_DIR, podcastdir, 'cover.jpg') if not os.path.exists(image_path): self.download(rss_imageurl, image_path) else: image_path = None podcast_items = [] for item in feed.entries: try: item_link = p.rss_item_link(item) if item_link is None: raise PodcastException item_title = p.rss_item_title(item) item_stitle = _name_to_filename(item_title) item_image_url = p.rss_item_image(item) if item_image_url is None: item_image_url = rss_imageurl item_mimetype = p.rss_item_mimetype(item) item_updated = p.rss_item_updated(item) isYT = item_link.find('youtube.com') isMC = item_link.find('metacafe.com') item_ext = isYT >= 0 and config.YOUTUBE_FORMAT == '18' and 'mp4' \ or isYT >= 0 and config.YOUTUBE_FORMAT == '17' and '3gp' \ or isMC >= 0 and 'flv' \ or item_mimetype == 'video/mpeg' and 'mpeg' \ or item_mimetype == 'video/quicktime' and 'mov' \ or item_mimetype == 'video/x-la-asf' and 'asf' \ or item_mimetype == 'video/x-ms-asf' and 'asf' \ or item_mimetype == 'video/x-msvideo' and 'avi' \ or item_mimetype == 'video/x-m4v' and 'mp4' \ or item_mimetype == 'video/x-flv' and 'flv' \ or item_mimetype == 'application/x-shockwave-flash' and 'flv' \ or '' if not item_ext: item_ext = 'avi' results = [{ 'id': time.strftime('%s').decode('utf-8'), 'url': item_link.decode('utf-8'), 'uploader': u'', 'title': item_title.decode('utf-8'), 'stitle': item_stitle.decode('utf-8'), 'ext': item_ext.decode('utf-8'), }] item_path = os.path.join(config.VPODCAST_DIR, podcastdir, item_stitle+'.'+item_ext) if item_image_url is not None: image_path = os.path.join(config.VPODCAST_DIR, podcastdir, item_stitle+'.jpg') if not os.path.exists(image_path): self.download(item_image_url, image_path) podcast_items += [ menu.MenuItem(item_title, action=VPVideoItem(item_path, self, item_link, results), arg=None, image=image_path) ] if os.path.exists(item_path): if item_updated > os.stat(item_path)[stat.ST_MTIME]: os.remove(item_path) logger.info('%r removed updated %r > %r', item_path, item_updated, os.stat(item_path)[stat.ST_MTIME]) except PodcastException: pass if not podcast_items: podcast_items += [menu.MenuItem(_('No Podcast locations found'), menuw.back_one_menu, 0)] finally: popup.destroy() podcast_sub_menu = menu.Menu(_('Video Podcasts'), podcast_items) menuw.pushmenu(podcast_sub_menu) menuw.refresh()
def create_podcast_submenu(self, arg=None, menuw=None, image=None): """ create the sub-menu for the podcast """ name, rss_url, feed_type = arg podcastdir = _name_to_filename(name) popup = PopupBox(text=_('Fetching podcast items...')) popup.show() try: p = Podcast(rss_url, feed_type) feed = p.feed() rss_title = p.rss_title() rss_stitle = _name_to_filename(rss_title) rss_description = p.rss_description() rss_imageurl = p.rss_image() if rss_imageurl: image_path = os.path.join(config.VPODCAST_DIR, podcastdir, 'cover.jpg') if not os.path.exists(image_path): self.download(rss_imageurl, image_path) else: image_path = None podcast_items = [] for item in feed.entries: try: item_link = p.rss_item_link(item) if item_link is None: raise PodcastException item_title = p.rss_item_title(item) item_stitle = _name_to_filename(item_title) item_image_url = p.rss_item_image(item) if item_image_url is None: item_image_url = rss_imageurl item_mimetype = p.rss_item_mimetype(item) item_updated = p.rss_item_updated(item) isYT = item_link.find('youtube.com') isMC = item_link.find('metacafe.com') item_ext = isYT >= 0 and config.YOUTUBE_FORMAT == '18' and 'mp4' \ or isYT >= 0 and config.YOUTUBE_FORMAT == '17' and '3gp' \ or isMC >= 0 and 'flv' \ or item_mimetype == 'video/mpeg' and 'mpeg' \ or item_mimetype == 'video/quicktime' and 'mov' \ or item_mimetype == 'video/x-la-asf' and 'asf' \ or item_mimetype == 'video/x-ms-asf' and 'asf' \ or item_mimetype == 'video/x-msvideo' and 'avi' \ or item_mimetype == 'video/x-m4v' and 'mp4' \ or item_mimetype == 'video/x-flv' and 'flv' \ or item_mimetype == 'application/x-shockwave-flash' and 'flv' \ or '' if not item_ext: item_ext = 'avi' results = [{ 'id': time.strftime('%s').decode('utf-8'), 'url': item_link.decode('utf-8'), 'uploader': u'', 'title': item_title.decode('utf-8'), 'stitle': item_stitle.decode('utf-8'), 'ext': item_ext.decode('utf-8'), }] item_path = os.path.join(config.VPODCAST_DIR, podcastdir, item_stitle + '.' + item_ext) if item_image_url is not None: image_path = os.path.join(config.VPODCAST_DIR, podcastdir, item_stitle + '.jpg') if not os.path.exists(image_path): self.download(item_image_url, image_path) podcast_items += [ menu.MenuItem(item_title, action=VPVideoItem( item_path, self, item_link, results), arg=None, image=image_path) ] if os.path.exists(item_path): if item_updated > os.stat(item_path)[stat.ST_MTIME]: os.remove(item_path) logger.info('%r removed updated %r > %r', item_path, item_updated, os.stat(item_path)[stat.ST_MTIME]) except PodcastException: pass if not podcast_items: podcast_items += [ menu.MenuItem(_('No Podcast locations found'), menuw.back_one_menu, 0) ] finally: popup.destroy() podcast_sub_menu = menu.Menu(_('Video Podcasts'), podcast_items) menuw.pushmenu(podcast_sub_menu) menuw.refresh()