def getheadlines(self, arg=None, menuw=None): """ this returns a menu with VideoItems for each headline """ headlines = [] rawheadlines = [] rawheadlines = self.getsiteheadlines() for title, link, description in rawheadlines: # create a VideoItem for each headline mi = VideoItem(link, self.parent) mi.name = title description = description.replace('\n\n', '&#xxx;').replace('\n', ' ').\ replace('&#xxx;', '\n') description = description.replace('<p>', '\n').replace('<br>', '\n') description = description.replace('<p>', '\n').replace('<br/>', '\n') description = description + '\n \n \nLink: ' + link description = util.htmlenties2txt(description) mi.plot = re.sub('<.*?>', '', description) headlines.append(mi) # create the menu if (len(headlines) == 0): headlines += [menu.MenuItem(_('No Headlines found'), menuw.back_one_menu, 0)] headlines_menu = menu.Menu(_('Headlines'), headlines) menuw.pushmenu(headlines_menu) menuw.refresh()
class Identify_Thread(threading.Thread): """ Thread to watch the rom drives for changes """ def identify(self, media, force_rebuild=False): """ Try to find out as much as possible about the disc in the rom drive: title, image, play options, ... """ cds = media.get_drive_status() #media.log_drive_status(cds) # Same as last time? If so we're done if media.drive_status == cds: #_debug_('status not changed for drive %r' % (media.devicename)) return logger.debug('drive_status changed %s -> %s', media.drive_status, cds) media.drive_status = cds media.id = '' media.label = '' media.type = 'empty_cdrom' media.item = None media.videoitem = None media.cached = False # Is there a disc information? if media.drive_status == CDS_NO_INFO: logger.debug('cannot get the drive status for drive %r', media.devicename) return # Is there a disc present? if media.drive_status != CDS_DISC_OK: logger.debug('disc not ready for drive %r', media.devicename) return # try to set the speed try: fd = os.open(media.devicename, os.O_RDONLY | os.O_NONBLOCK) try: if media.can_select_speed and config.ROM_SPEED: try: ioctl(fd, CDROM_SELECT_SPEED, config.ROM_SPEED) except Exception, e: logger.debug('setting rom speed for %r failed: %s', media.devicename, e) finally: #_debug_('closing %r drive %r' % (fd, media.devicename)) try: os.close(fd) except Exception, e: logger.debug('closing %r failed: %s', media.devicename, e) except Exception, e: logger.debug('opening %r failed: %s', media.devicename, e) return # if there is a disc, the tray can't be open media.tray_open = False disc_info = util.mediainfo.disc_info(media, force_rebuild) if not disc_info: logger.debug('no disc information for drive %r', media.devicename) return info = disc_info.discinfo if not info: logger.debug('no info for drive %r', media.devicename) return if info['mime'] == 'audio/cd': media.id = disc_id = info['id'] media.item = AudioDiskItem(disc_id, parent=None, devicename=media.devicename, display_type='audio') media.type = 'audio' media.item.media = media if info['title']: media.item.name = info['title'] media.item.info = disc_info logger.debug('playing audio in drive %r', media.devicename) return image = title = movie_info = more_info = fxd_file = None media.id = info['id'] media.label = info['label'] media.type = 'cdrom' label = info['label'] # is the id in the database? if media.id in video.fxd_database['id']: movie_info = video.fxd_database['id'][media.id] if movie_info: title = movie_info.name else: # no? Maybe we can find a label regexp match for (re_label, movie_info_t) in video.fxd_database['label']: if re_label.match(media.label): movie_info = movie_info_t if movie_info_t.name: title = movie_info.name m = re_label.match(media.label).groups() re_count = 1 # found, now change the title with the regexp. E.g.: # label is "bla_2", the label regexp "bla_[0-9]" and the title # is "Something \1", the \1 will be replaced with the first item # in the regexp group, here 2. The title is now "Something 2" for g in m: title = string.replace(title, '\\%s' % re_count, g) re_count += 1 break if movie_info: image = movie_info.image # DVD/VCD/SVCD: if info['mime'] in ('video/vcd', 'video/dvd'): if not title: title = media.label.replace('_', ' ').lstrip().rstrip() title = '%s [%s]' % (info['mime'][6:].upper(), title) if movie_info: media.item = copy.copy(movie_info) else: media.item = VideoItem('', None) media.item.image = util.getimage( os.path.join(config.OVERLAY_DIR, 'disc-set', media.id)) variables = media.item.info.variables media.item.info = disc_info media.item.info.set_variables(variables) media.item.name = title media.item.url = info['mime'][6:] + '://' media.item.media = media media.type = info['mime'][6:] media.item.info.mmdata = info logger.debug('playing video in drive %r', media.devicename) return # Disc is data of some sort. Mount it to get the file info util.mount(media.mountdir, force=True) try: if os.path.isdir(os.path.join(media.mountdir, 'VIDEO_TS')) or \ os.path.isdir(os.path.join(media.mountdir, 'video_ts')): if force_rebuild: logger.debug('Double check without success') else: logger.debug('Undetected DVD, checking again') media.drive_status = CDS_NO_DISC return self.identify(media, True) # Check for movies/audio/images on the disc num_video = disc_info['disc_num_video'] num_audio = disc_info['disc_num_audio'] num_image = disc_info['disc_num_image'] video_files = util.match_files(media.mountdir, config.VIDEO_SUFFIX) logger.debug('video_files=%r', video_files) media.item = DirItem(media.mountdir, None, create_metainfo=False) media.item.info = disc_info finally: util.umount(media.mountdir) # if there is a video file on the root dir of the disc, we guess # it's a video disc. There may also be audio files and images, but # they only belong to the movie if video_files: media.type = 'video' # try to find out if it is a series cd if not title: show_name = "" the_same = 1 volumes = '' start_ep = 0 end_ep = 0 video_files.sort(lambda l, o: cmp(l.upper(), o.upper())) for movie in video_files: if config.VIDEO_SHOW_REGEXP_MATCH(movie): show = config.VIDEO_SHOW_REGEXP_SPLIT( os.path.basename(movie)) if show_name and show_name != show[0]: the_same = 0 if not show_name: show_name = show[0] if volumes: volumes += ', ' current_ep = int(show[1]) * 100 + int(show[2]) if end_ep and current_ep == end_ep + 1: end_ep = current_ep elif not end_ep: end_ep = current_ep else: end_ep = -1 if not start_ep: start_ep = end_ep volumes += show[1] + "x" + show[2] if show_name and the_same and config.VIDEO_SHOW_DATA_DIR: if end_ep > 0: volumes = '%dx%02d - %dx%02d' % ( start_ep / 100, start_ep % 100, end_ep / 100, end_ep % 100) k = config.VIDEO_SHOW_DATA_DIR + show_name if os.path.isfile((k + ".png").lower()): image = (k + ".png").lower() elif os.path.isfile((k + ".jpg").lower()): image = (k + ".jpg").lower() title = show_name + ' (' + volumes + ')' if video.tv_show_information.has_key(show_name.lower()): tvinfo = video.tv_show_information[show_name.lower()] more_info = tvinfo[1] if not image: image = tvinfo[0] if not fxd_file: fxd_file = tvinfo[3] elif (not show_name) and len(video_files) == 1: movie = video_files[0] title = os.path.splitext(os.path.basename(movie))[0] # nothing found, give up: return the label if not title: title = label # If there are no videos and only audio files (and maybe images) # it is an audio disc (autostart will auto play everything) elif not num_video and num_audio: media.type = 'audio' title = '%s [%s]' % (media.drivename, label) # Only images? OK than, make it an image disc elif not num_video and not num_audio and num_image: media.type = 'image' title = '%s [%s]' % (media.drivename, label) # Mixed media? elif num_video or num_audio or num_image: media.type = None title = '%s [%s]' % (media.drivename, label) # Strange, no useable files else: media.type = None title = '%s [%s]' % (media.drivename, label) # set the info we have now if title: media.item.name = title if image: media.item.image = image if more_info: media.item.info.set_variables(more_info) if fxd_file and not media.item.fxd_file: media.item.set_fxd_file(fxd_file) # One video in the root dir. This sounds like a disc with one # movie on it. Save the information about it and autostart will # play this. if len(video_files) == 1 and media.item['num_dir_items'] == 0: util.mount(media.mountdir) try: if movie_info: media.videoitem = copy.deepcopy(movie_info) else: media.videoitem = VideoItem(video_files[0], None) finally: util.umount(media.mountdir) media.videoitem.media = media media.videoitem.media_id = media.id # set the info we have if title: media.videoitem.name = title if image: media.videoitem.image = image if more_info: media.videoitem.set_variables(more_info) if fxd_file: media.videoitem.fxd_file = fxd_file media.item.media = media
def identify(self, media, force_rebuild=False): """ magic! Try to find out as much as possible about the disc in the rom drive: title, image, play options, ... """ # Check drive status (tray pos, disc ready) try: CDSL_CURRENT = ((int)(~0 >> 1)) fd = os.open(media.devicename, os.O_RDONLY | os.O_NONBLOCK) if os.uname()[0] == 'FreeBSD': try: data = array.array('c', '\000' * 4096) (address, length) = data.buffer_info() buf = pack('BBHP', CD_MSF_FORMAT, 0, length, address) s = ioctl(fd, CDIOREADTOCENTRYS, buf) s = CDS_DISC_OK except: s = CDS_NO_DISC else: s = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) except: # maybe we need to close the fd if ioctl fails, maybe # open fails and there is no fd try: os.close(fd) except: pass media.drive_status = None return # Same as last time? If so we're done if s == media.drive_status: os.close(fd) return media.drive_status = s media.id = '' media.label = '' media.type = 'empty_cdrom' media.item = None media.videoitem = None media.cached = False # Is there a disc present? if s != CDS_DISC_OK: os.close(fd) return # if there is a disc, the tray can't be open media.tray_open = False disc_info = util.mediainfo.disc_info(media, force_rebuild) if not disc_info: # bad disc, e.g. blank disc. os.close(fd) return data = disc_info.mmdata # try to set the speed if config.ROM_SPEED and data and not data['mime'] == 'video/dvd': try: ioctl(fd, CDROM_SELECT_SPEED, config.ROM_SPEED) except: pass if data and data['mime'] == 'audio/cd': os.close(fd) disc_id = data['id'] media.item = AudioDiskItem(disc_id, parent=None, devicename=media.devicename, display_type='audio') media.type = media.item.type media.item.media = media if data['title']: media.item.name = data['title'] media.item.info = disc_info return os.close(fd) image = title = movie_info = more_info = fxd_file = None media.id = data['id'] media.label = data['label'] media.type = 'cdrom' label = data['label'] # is the id in the database? if media.id in video.fxd_database['id']: movie_info = video.fxd_database['id'][media.id] if movie_info: title = movie_info.name # no? Maybe we can find a label regexp match else: for (re_label, movie_info_t) in video.fxd_database['label']: if re_label.match(media.label): movie_info = movie_info_t if movie_info_t.name: title = movie_info.name m = re_label.match(media.label).groups() re_count = 1 # found, now change the title with the regexp. E.g.: # label is "bla_2", the label regexp "bla_[0-9]" and the title # is "Something \1", the \1 will be replaced with the first item # in the regexp group, here 2. The title is now "Something 2" for g in m: title = string.replace(title, '\\%s' % re_count, g) re_count += 1 break if movie_info: image = movie_info.image # DVD/VCD/SVCD: # There is data from mmpython for these three types if data['mime'] in ('video/vcd', 'video/dvd'): if not title: title = media.label.replace('_', ' ').lstrip().rstrip() title = '%s [%s]' % (data['mime'][6:].upper(), title) if movie_info: media.item = copy.copy(movie_info) else: media.item = VideoItem('', None) media.item.image = util.getimage( os.path.join(config.OVERLAY_DIR, 'disc-set', media.id)) variables = media.item.info.variables media.item.info = disc_info media.item.info.set_variables(variables) media.item.name = title media.item.set_url(data['mime'][6:] + '://') media.item.media = media media.type = data['mime'][6:] media.item.info.mmdata = data return # Disc is data of some sort. Mount it to get the file info util.mount(media.mountdir, force=True) if os.path.isdir(os.path.join(media.mountdir, 'VIDEO_TS')) or \ os.path.isdir(os.path.join(media.mountdir, 'video_ts')): if force_rebuild: _debug_('Double check without success') else: _debug_('Undetected DVD, checking again') media.drive_status = CDS_NO_DISC util.umount(media.mountdir) return self.identify(media, True) # Check for movies/audio/images on the disc num_video = disc_info['disc_num_video'] num_audio = disc_info['disc_num_audio'] num_image = disc_info['disc_num_image'] video_files = util.match_files(media.mountdir, config.VIDEO_SUFFIX) _debug_('identifymedia: mplayer = "%s"' % video_files, level=2) media.item = DirItem(media.mountdir, None, create_metainfo=False) media.item.info = disc_info util.umount(media.mountdir) # if there is a video file on the root dir of the disc, we guess # it's a video disc. There may also be audio files and images, but # they only belong to the movie if video_files: media.type = 'video' # try to find out if it is a series cd if not title: show_name = "" the_same = 1 volumes = '' start_ep = 0 end_ep = 0 video_files.sort(lambda l, o: cmp(l.upper(), o.upper())) for movie in video_files: if config.VIDEO_SHOW_REGEXP_MATCH(movie): show = config.VIDEO_SHOW_REGEXP_SPLIT( os.path.basename(movie)) if show_name and show_name != show[0]: the_same = 0 if not show_name: show_name = show[0] if volumes: volumes += ', ' current_ep = int(show[1]) * 100 + int(show[2]) if end_ep and current_ep == end_ep + 1: end_ep = current_ep elif not end_ep: end_ep = current_ep else: end_ep = -1 if not start_ep: start_ep = end_ep volumes += show[1] + "x" + show[2] if show_name and the_same and config.VIDEO_SHOW_DATA_DIR: if end_ep > 0: volumes = '%dx%02d - %dx%02d' % ( start_ep / 100, start_ep % 100, end_ep / 100, end_ep % 100) k = config.VIDEO_SHOW_DATA_DIR + show_name if os.path.isfile((k + ".png").lower()): image = (k + ".png").lower() elif os.path.isfile((k + ".jpg").lower()): image = (k + ".jpg").lower() title = show_name + ' (' + volumes + ')' if video.tv_show_informations.has_key(show_name.lower()): tvinfo = video.tv_show_informations[show_name.lower()] more_info = tvinfo[1] if not image: image = tvinfo[0] if not fxd_file: fxd_file = tvinfo[3] elif (not show_name) and len(video_files) == 1: movie = video_files[0] title = os.path.splitext(os.path.basename(movie))[0] # nothing found, give up: return the label if not title: title = label # If there are no videos and only audio files (and maybe images) # it is an audio disc (autostart will auto play everything) elif not num_video and num_audio: media.type = 'audio' title = '%s [%s]' % (media.drivename, label) # Only images? OK than, make it an image disc elif not num_video and not num_audio and num_image: media.type = 'image' title = '%s [%s]' % (media.drivename, label) # Mixed media? elif num_video or num_audio or num_image: media.type = None title = '%s [%s]' % (media.drivename, label) # Strange, no useable files else: media.type = None title = '%s [%s]' % (media.drivename, label) # set the infos we have now if title: media.item.name = title if image: media.item.image = image if more_info: media.item.info.set_variables(more_info) if fxd_file and not media.item.fxd_file: media.item.set_fxd_file(fxd_file) # One video in the root dir. This sounds like a disc with one # movie on it. Save the information about it and autostart will # play this. if len(video_files) == 1 and media.item['num_dir_items'] == 0: util.mount(media.mountdir) if movie_info: media.videoitem = copy.deepcopy(movie_info) else: media.videoitem = VideoItem(video_files[0], None) util.umount(media.mountdir) media.videoitem.media = media media.videoitem.media_id = media.id # set the infos we have if title: media.videoitem.name = title if image: media.videoitem.image = image if more_info: media.videoitem.set_variables(more_info) if fxd_file: media.videoitem.fxd_file = fxd_file media.item.media = media return
def play(self): if self.video_item: return self.video_item = VideoItem('file://' + self.file_path, None) self.video_item.play(menuw=self.menuw)