Example #1
0
    def get(self, parent, files):
        """
        return a list of items based on the files
        """
        items = []

        all_files = util.find_matches(files, config.VIDEO_SUFFIX)
        # sort all files to make sure 1 is before 2 for auto-join
        all_files.sort(lambda l, o: cmp(l.upper(), o.upper()))

        hidden_files = []

        pat = re.compile(config.VIDEO_AUTOJOIN_REGEX)
        for file in all_files:
            if parent and parent.type == 'dir' and \
                   hasattr(parent, 'VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS') and \
                   parent.VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS:
                util.videothumb.snapshot(file, update=False, popup=True)

            if file in hidden_files:
                files.remove(file)
                continue

            x = VideoItem(file, parent)

            # join video files
            if config.VIDEO_AUTOJOIN:
                mat = pat.search(file)
                if mat is not None:
                    add_file = []
                    start = file.find(mat.group(1), mat.start())
                    end = start + len(mat.group(1))
                    stem = file[:start]
                    tail = file[end:]
                    next = 2
                    for f in all_files:
                        next_str = '%0*d' % (end - start, next)
                        filename = stem + next_str + tail
                        if filename in all_files:
                            add_file.append(filename)
                        else:
                            break
                        next += 1
                    if len(add_file) > 0:
                        name = stem + tail
                        x = VideoItem(name, parent)
                        x.files = FileInformation()
                        x.subitems.append(VideoItem(file, x))
                        x.set_url(file, True)
                        for filename in add_file:
                            x.files.append(filename)
                            x.subitems.append(VideoItem(filename, x))
                            hidden_files.append(filename)

            if parent and parent.media:
                file_id = String(
                    parent.media.id
                ) + file[len(os.path.join(parent.media.mountdir, '')):]
                try:
                    x.mplayer_options = discset_information[file_id]
                    logger.debug('x.mplayer_options=%r', x.mplayer_options)
                except KeyError:
                    pass
            items.append(x)
            files.remove(file)

        for i in copy.copy(files):
            if os.path.isdir(i + '/VIDEO_TS'):
                # DVD Image, trailing slash is important for Xine
                items.append(VideoItem('dvd://' + i[1:] + '/VIDEO_TS/',
                                       parent))
                files.remove(i)

        return items
Example #2
0
    def get(self, parent, files):
        """
        return a list of items based on the files
        """
        items = []

        all_files = util.find_matches(files, config.VIDEO_SUFFIX)
        # sort all files to make sure 1 is before 2 for auto-join
        all_files.sort(lambda l, o: cmp(l.upper(), o.upper()))

        hidden_files = []

        pat = re.compile(config.VIDEO_AUTOJOIN_REGEX)
        for file in all_files:
            if parent and parent.type == 'dir' and \
                   hasattr(parent, 'VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS') and \
                   parent.VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS:
                util.videothumb.snapshot(file, update=False, popup=True)

            if file in hidden_files:
                files.remove(file)
                continue

            x = VideoItem(file, parent)

            # join video files
            if config.VIDEO_AUTOJOIN:
                mat = pat.search(file)
                if mat is not None:
                    add_file = []
                    start = file.find(mat.group(1), mat.start())
                    end = start + len(mat.group(1))
                    stem = file[:start]
                    tail = file[end:]
                    next = 2
                    for f in all_files:
                        next_str = '%0*d' % (end-start, next)
                        filename = stem+next_str+tail
                        if filename in all_files:
                            add_file.append(filename)
                        else:
                            break
                        next += 1
                    if len(add_file) > 0:
                        name = stem+tail
                        x = VideoItem(name, parent)
                        x.files = FileInformation()
                        x.subitems.append(VideoItem(file, x))
                        x.set_url(file, True)
                        for filename in add_file:
                            x.files.append(filename)
                            x.subitems.append(VideoItem(filename, x))
                            hidden_files.append(filename)

            if parent and parent.media:
                file_id = String(parent.media.id) + file[len(os.path.join(parent.media.mountdir, '')):]
                try:
                    x.mplayer_options = discset_information[file_id]
                    logger.debug('x.mplayer_options=%r', x.mplayer_options)
                except KeyError:
                    pass
            items.append(x)
            files.remove(file)

        for i in copy.copy(files):
            if os.path.isdir(i+'/VIDEO_TS'):
                # DVD Image, trailing slash is important for Xine
                items.append(VideoItem('dvd://' + i[1:] + '/VIDEO_TS/', parent))
                files.remove(i)

        return items
Example #3
0
def parse_movie(fxd, node):
    """
    Callback for VideoItem <movie>::

        <movie title>
            <cover-img>file</cover-img>
            <video mplayer-options>
                <dvd|vcd|file id name media_id mplayer-options>file</>+
            <variants>
                <variant>
                    <part ref mplayer-options>
                        <subtitle media_id>file</subtitle>
                        <audio media_id>file</audio>
                    </part>+
                </variant>+
            </variants>
            <info/>
        </movie>
    """

    files = []

    def parse_video_child(fxd, node, dirname):
        """
        parse a subitem from <video>
        """
        filename = String(fxd.gettext(node))
        media_id = fxd.getattr(node, "media-id")
        mode = node.name
        id = fxd.getattr(node, "id")
        options = fxd.getattr(node, "mplayer-options")
        player = fxd.childcontent(node, "player")
        playlist = fxd.get_children(node, "playlist") and True or False

        if mode == "file":
            if not media_id:
                filename = os.path.join(dirname, filename)
                if vfs.isoverlay(filename):
                    filename = vfs.normalize(filename)
            if filename and not filename in files:
                files.append(filename)
        if mode == "url":
            return id, filename, media_id, options, player, playlist
        return id, String("%s://%s" % (String(mode), String(filename))), media_id, options, player, playlist

    item = VideoItem("", fxd.getattr(None, "parent", None), parse=False)

    dirname = os.path.dirname(fxd.filename)
    image = ""
    title = fxd.getattr(node, "title")
    item.name = title
    item.image = fxd.childcontent(node, "cover-img")
    if item.image:
        try:
            item.image = vfs.abspath(os.path.join(dirname, str(item.image)))
        except UnicodeEncodeError:
            logger.debug("os.path.join(dirname=%r, item.image=%r)", dirname, item.image)
            raise
        image = item.image

    fxd.parse_info(node, item, {"runtime": "length"})

    video = fxd.get_children(node, "video")
    if video:
        mplayer_options = fxd.getattr(video[0], "mplayer-options")
        video = (
            fxd.get_children(video[0], "file")
            + fxd.get_children(video[0], "vcd")
            + fxd.get_children(video[0], "dvd")
            + fxd.get_children(video[0], "url")
        )

    variants = fxd.get_children(node, "variants")
    if variants:
        variants = fxd.get_children(variants[0], "variant")

    if variants:
        # a list of variants
        id = {}
        for v in video:
            video_child = parse_video_child(fxd, v, dirname)
            id[video_child[0]] = video_child

        for variant in variants:
            mplayer_options += " " + fxd.getattr(variant, "mplayer-options")
            parts = fxd.get_children(variant, "part")
            if len(parts) == 1:
                # a variant with one file
                ref = fxd.getattr(parts[0], "ref")
                v = VideoItem(id[ref][1], parent=item, info=item.info, parse=False)
                v.files = None
                v.media_id, v.mplayer_options, player, is_playlist = id[ref][2:]
                if player:
                    v.force_player = player
                if is_playlist:
                    v.is_playlist = True

                audio = fxd.get_children(parts[0], "audio")
                if audio:
                    audio = {"media_id": fxd.getattr(audio[0], "media-id"), "file": fxd.gettext(audio[0])}
                    if not audio["media_id"]:
                        audio["file"] = os.path.join(dirname, audio["file"])
                else:
                    audio = {}
                v.audio_file = audio

                subtitle = fxd.get_children(parts[0], "subtitle")
                if subtitle:
                    subtitle = {"media_id": fxd.getattr(subtitle[0], "media-id"), "file": fxd.gettext(subtitle[0])}
                    if not subtitle["media_id"]:
                        subtitle["file"] = os.path.join(dirname, subtitle["file"])
                else:
                    subtitle = {}
                v.subtitle_file = subtitle

                # global <video> mplayer_options
                if mplayer_options:
                    v.mplayer_options += mplayer_options
            else:
                # a variant with a list of files
                v = VideoItem("", parent=item, info=item.info, parse=False)
                for p in parts:
                    ref = fxd.getattr(p, "ref")
                    audio = fxd.get_children(p, "audio")
                    subtitle = fxd.get_children(p, "subtitle")

                    if audio:
                        audio = {"media_id": fxd.getattr(audio[0], "media-id"), "file": fxd.gettext(audio[0])}
                        if not audio["media_id"]:
                            audio["file"] = os.path.join(dirname, audio["file"])
                    else:
                        audio = {}

                    if subtitle:
                        subtitle = {"media_id": fxd.getattr(subtitle[0], "media-id"), "file": fxd.gettext(subtitle[0])}
                        if not subtitle["media_id"]:
                            subtitle["file"] = os.path.join(dirname, subtitle["file"])
                    else:
                        subtitle = {}

                    sub = VideoItem(id[ref][1], parent=v, info=item.info, parse=False)
                    sub.files = None
                    sub.media_id, sub.mplayer_options, player, is_playlist = id[ref][2:]
                    sub.subtitle_file = subtitle
                    sub.audio_file = audio
                    # global <video> mplayer_options
                    if mplayer_options:
                        sub.mplayer_options += mplayer_options
                    v.subitems.append(sub)

            v.name = fxd.getattr(variant, "name")
            item.variants.append(v)

    else:
        # one or more files, this is directly for the item

        try:
            id, url, item.media_id, item.mplayer_options, player, is_playlist = parse_video_child(
                fxd, video[0], dirname
            )
        except (IndexError, TypeError), why:
            logger.warning("%r is corrupt", fxd.filename)
            raise
        if url.startswith("file://") and os.path.isfile(url[7:]):
            variables = item.info.get_variables()
            item.set_url(url, info=True)
            item.info.set_variables(variables)
        elif url.startswith("file://") and os.path.isdir(url[7:]):
            # dvd dir
            variables = item.info.get_variables()
            item.set_url(url.replace("file://", "dvd:/") + "/VIDEO_TS/", info=True)
            item.info.set_variables(variables)
        else:
            item.set_url(url, info=False)
        if title:
            item.name = title
        if player:
            item.force_player = player
        if is_playlist:
            item.is_playlist = True
        if len(video) == 1:
            # global <video> mplayer_options
            if mplayer_options:
                item.mplayer_options += mplayer_options

        # if there is more than one item add them to subitems
        if len(video) > 1:
            # a list of files
            subitem_matched = False
            for s in video:
                # id, url, item.media_id, mplayer_options, player, is_playlist = parse_video_child(fxd, s, dirname)
                video_child = parse_video_child(fxd, s, dirname)
                url = video_child[1]

                v = VideoItem(url, parent=item, info=item.info, parse=False)

                if url.startswith("file://"):
                    v.files = FileInformation()

                    v.files.append(url[7:])
                    if url == item.url and not subitem_matched:
                        subitem_matched = True
                        v.files.fxd_file = fxd.filename
                        if item.image:
                            v.files.image = item.image
                else:
                    v.files = None

                v.media_id, v.mplayer_options, player, is_playlist = video_child[2:]
                if player:
                    v.force_player = player
                if is_playlist:
                    item.is_playlist = True
                # global <movie> mplayer_options
                if mplayer_options:
                    v.mplayer_options += " " + mplayer_options
                item.subitems.append(v)
Example #4
0
    def get(self, parent, files):
        """
        return a list of items based on the files
        """
        items = []

        all_files = util.find_matches(files, config.VIDEO_SUFFIX)
        # sort all files to make sure 1 is before 2 for auto-join
        all_files.sort(lambda l, o: cmp(l.upper(), o.upper()))

        hidden_files = []

        for file in all_files:
            if parent and parent.type == 'dir' and \
                   hasattr(parent, 'VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS') and \
                   parent.VIDEO_DIRECTORY_AUTOBUILD_THUMBNAILS:
                util.videothumb.snapshot(file, update=False, popup=True)

            if file in hidden_files:
                files.remove(file)
                continue

            x = VideoItem(file, parent)

            # join video files
            if config.VIDEO_AUTOJOIN and file.find('1') > 0:
                pos = 0
                for count in range(file.count('1')):
                    # only count single digests
                    if file[pos+file[pos:].find('1')-1] in string.digits or \
                           file[pos+file[pos:].find('1')+1] in string.digits:
                        pos += file[pos:].find('1') + 1
                        continue
                    add_file = []
                    missing = 0
                    for i in range(2, 6):
                        current = file[:pos] + file[pos:].replace(
                            '1', str(i), 1)
                        if current in all_files:
                            add_file.append(current)
                            end = i
                        elif not missing:
                            # one file missing, stop searching
                            missing = i

                    if add_file and missing > end:
                        if len(add_file) > 3:
                            # more than 4 files, I don't belive it
                            break
                        # create new name
                        name = file[:pos] + file[pos:].replace(
                            '1', '1-%s' % end, 1)
                        x = VideoItem(name, parent)
                        x.files = FileInformation()
                        x.set_url(file, True)
                        for f in [file] + add_file:
                            x.files.append(f)
                            x.subitems.append(VideoItem(f, x))
                            hidden_files.append(f)
                        break
                    else:
                        pos += file[pos:].find('1') + 1

            if parent.media:
                file_id = String(parent.media.id) + \
                          file[len(os.path.join(parent.media.mountdir, "")):]
                try:
                    x.mplayer_options = discset_information[file_id]
                    _debug_('x.mplayer_options=%r' % x.mplayer_options)
                except KeyError:
                    pass
            items.append(x)
            files.remove(file)

        for i in copy.copy(files):
            if os.path.isdir(i + '/VIDEO_TS'):
                # DVD Image, trailing slash is important for Xine
                items.append(VideoItem('dvd://' + i[1:] + '/VIDEO_TS/',
                                       parent))
                files.remove(i)

        return items
Example #5
0
def parse_movie(fxd, node):
    """
    Callback for VideoItem <movie>::

        <movie title>
            <cover-img>file</cover-img>
            <video mplayer-options>
                <dvd|vcd|file id name media_id mplayer-options>file</>+
            <variants>
                <variant>
                    <part ref mplayer-options>
                        <subtitle media_id>file</subtitle>
                        <audio media_id>file</audio>
                    </part>+
                </variant>+
            </variants>
            <info/>
        </movie>
    """

    files = []

    def parse_video_child(fxd, node, dirname):
        """
        parse a subitem from <video>
        """
        filename   = String(fxd.gettext(node))
        media_id   = fxd.getattr(node, 'media-id')
        mode       = node.name
        id         = fxd.getattr(node, 'id')
        options    = fxd.getattr(node, 'mplayer-options')
        player     = fxd.childcontent(node, 'player')
        playlist   = fxd.get_children(node, 'playlist') and True or False

        if mode == 'file':
            if not media_id:
                filename = os.path.join(dirname, filename)
                if vfs.isoverlay(filename):
                    filename = vfs.normalize(filename)
            if filename and not filename in files:
                files.append(filename)
        if mode == 'url':
            return id, filename, media_id, options, player, playlist
        return id, String('%s://%s' % (String(mode), String(filename))), \
               media_id, options, player, playlist


    item = VideoItem('', fxd.getattr(None, 'parent', None), parse=False)

    dirname  = os.path.dirname(fxd.filename)
    image      = ''
    title      = fxd.getattr(node, 'title')
    item.name  = title
    item.image = fxd.childcontent(node, 'cover-img')
    if item.image:
        try:
            item.image = vfs.abspath(os.path.join(dirname, str(item.image)))
        except UnicodeEncodeError:
            logger.debug('os.path.join(dirname=%r, item.image=%r)', dirname, item.image)
            raise
        image = item.image

    fxd.parse_info(node, item, {'runtime': 'length'})

    video = fxd.get_children(node, 'video')
    if video:
        mplayer_options = fxd.getattr(video[0], 'mplayer-options')
        video = fxd.get_children(video[0], 'file') + \
                fxd.get_children(video[0], 'vcd') + \
                fxd.get_children(video[0], 'dvd') + \
                fxd.get_children(video[0], 'url')

    variants = fxd.get_children(node, 'variants')
    if variants:
        variants = fxd.get_children(variants[0], 'variant')

    if variants:
        # a list of variants
        id = {}
        for v in video:
            video_child = parse_video_child(fxd, v, dirname)
            id[video_child[0]] = video_child

        for variant in variants:
            mplayer_options += " " + fxd.getattr(variant, 'mplayer-options');
            parts = fxd.get_children(variant, 'part')
            if len(parts) == 1:
                # a variant with one file
                ref = fxd.getattr(parts[0] ,'ref')
                v = VideoItem(id[ref][1], parent=item, info=item.info, parse=False)
                v.files = None
                v.media_id, v.mplayer_options, player, is_playlist = id[ref][2:]
                if player:
                    v.force_player = player
                if is_playlist:
                    v.is_playlist  = True

                audio = fxd.get_children(parts[0], 'audio')
                if audio:
                    audio = { 'media_id': fxd.getattr(audio[0], 'media-id'),
                              'file'    : fxd.gettext(audio[0]) }
                    if not audio['media_id']:
                        audio['file'] = os.path.join(dirname, audio['file'])
                else:
                    audio = {}
                v.audio_file = audio

                subtitle = fxd.get_children(parts[0], 'subtitle')
                if subtitle:
                    subtitle = { 'media_id': fxd.getattr(subtitle[0], 'media-id'),
                                 'file'    : fxd.gettext(subtitle[0]) }
                    if not subtitle['media_id']:
                        subtitle['file'] = os.path.join(dirname, subtitle['file'])
                else:
                    subtitle = {}
                v.subtitle_file = subtitle

                # global <video> mplayer_options
                if mplayer_options:
                    v.mplayer_options += mplayer_options
            else:
                # a variant with a list of files
                v = VideoItem('', parent=item, info=item.info, parse=False)
                for p in parts:
                    ref = fxd.getattr(p ,'ref')
                    audio    = fxd.get_children(p, 'audio')
                    subtitle = fxd.get_children(p, 'subtitle')

                    if audio:
                        audio = { 'media_id': fxd.getattr(audio[0], 'media-id'),
                                  'file'    : fxd.gettext(audio[0]) }
                        if not audio['media_id']:
                            audio['file'] = os.path.join(dirname, audio['file'])
                    else:
                        audio = {}

                    if subtitle:
                        subtitle = { 'media_id': fxd.getattr(subtitle[0], 'media-id'),
                                     'file'    : fxd.gettext(subtitle[0]) }
                        if not subtitle['media_id']:
                            subtitle['file'] = os.path.join(dirname, subtitle['file'])
                    else:
                        subtitle = {}

                    sub = VideoItem(id[ref][1], parent=v, info=item.info, parse=False)
                    sub.files = None
                    sub.media_id, sub.mplayer_options, player, is_playlist = id[ref][2:]
                    sub.subtitle_file = subtitle
                    sub.audio_file    = audio
                    # global <video> mplayer_options
                    if mplayer_options:
                        sub.mplayer_options += mplayer_options
                    v.subitems.append(sub)

            v.name = fxd.getattr(variant, 'name')
            item.variants.append(v)

    else:
        # one or more files, this is directly for the item

        try:
            id, url, item.media_id, item.mplayer_options, player, is_playlist = parse_video_child(
                fxd, video[0], dirname)
        except (IndexError, TypeError), why:
            logger.warning('%r is corrupt', fxd.filename)
            raise
        if url.startswith('file://') and os.path.isfile(url[7:]):
            variables = item.info.get_variables()
            item.set_url(url, info=True)
            item.info.set_variables(variables)
        elif url.startswith('file://') and os.path.isdir(url[7:]):
            # dvd dir
            variables = item.info.get_variables()
            item.set_url(url.replace('file://', 'dvd:/')+ '/VIDEO_TS/', info=True)
            item.info.set_variables(variables)
        else:
            item.set_url(url, info=False)
        if title:
            item.name = title
        if player:
            item.force_player = player
        if is_playlist:
            item.is_playlist  = True
        if len(video) == 1:
            # global <video> mplayer_options
            if mplayer_options:
                item.mplayer_options += mplayer_options

        # if there is more than one item add them to subitems
        if len(video) > 1:
            # a list of files
            subitem_matched = False
            for s in video:
                #id, url, item.media_id, mplayer_options, player, is_playlist = parse_video_child(fxd, s, dirname)
                video_child = parse_video_child(fxd, s, dirname)
                url = video_child[1]

                v = VideoItem(url, parent=item, info=item.info, parse=False)

                if url.startswith('file://'):
                    v.files = FileInformation()

                    v.files.append(url[7:])
                    if url == item.url and not subitem_matched:
                        subitem_matched = True
                        v.files.fxd_file  = fxd.filename
                        if item.image:
                            v.files.image = item.image
                else:
                    v.files = None

                v.media_id, v.mplayer_options, player, is_playlist = video_child[2:]
                if player:
                    v.force_player = player
                if is_playlist:
                    item.is_playlist = True
                # global <movie> mplayer_options
                if mplayer_options:
                    v.mplayer_options += ' ' + mplayer_options
                item.subitems.append(v)
Example #6
0
def parse_movie(fxd, node):
    """
    Callback for VideoItem <movie>::

        <movie title>
            <cover-img>file</cover-img>
            <video mplayer-options>
                <dvd|vcd|file id name media_id mplayer-options>file</>+
            <variants>
                <variant>
                    <part ref mplayer-options>
                        <subtitle media_id>file</subtitle>
                        <audio media_id>file</audio>
                    </part>+
                </variant>+
            </variants>
            <info/>
        </movie>
    """

    files = []

    def parse_video_child(fxd, node, dirname):
        """
        parse a subitem from <video>
        """
        filename   = String(fxd.gettext(node))
        media_id   = fxd.getattr(node, 'media-id')
        mode       = node.name
        id         = fxd.getattr(node, 'id')
        options    = fxd.getattr(node, 'mplayer-options')
        player     = fxd.childcontent(node, 'player')
        playlist   = fxd.get_children(node, 'playlist') and True or False

        if mode == 'file':
            if not media_id:
                filename = os.path.join(dirname, filename)
                if vfs.isoverlay(filename):
                    filename = vfs.normalize(filename)
            if filename and not filename in files:
                files.append(filename)
        if mode == 'url':
            return id, filename, media_id, options, player, playlist
        return id, String('%s://%s' % (String(mode), String(filename))), \
               media_id, options, player, playlist


    item       = VideoItem('', fxd.getattr(None, 'parent', None), parse=False)
    title      = name=fxd.getattr(node, 'title')
    item.name  = title
    dirname    = os.path.dirname(fxd.filename)
    image      = fxd.childcontent(node, 'cover-img')

    if image:
        try:
            image = vfs.abspath(os.path.join(dirname, str(image)))
        except UnicodeEncodeError:
            logger.debug('os.path.join(dirname=%r, item.image=%r)', dirname, item.image)
            raise
        item.image = image 
        item.files.image = image
    else:
        # no image for this item, see if we have a cover img
        image = util.getimage(os.path.join(dirname, 'cover'))
        if image:
            item.image = image

    fxd.parse_info(node, item, {'runtime': 'length'})

    video = fxd.get_children(node, 'video')
    if video:
        mplayer_options = fxd.getattr(video[0], 'mplayer-options')
        video = fxd.get_children(video[0], 'file') + \
                fxd.get_children(video[0], 'vcd') + \
                fxd.get_children(video[0], 'dvd') + \
                fxd.get_children(video[0], 'url')

    variants = fxd.get_children(node, 'variants')
    if variants:
        variants = fxd.get_children(variants[0], 'variant')

    if variants:
        # a list of variants
        id = {}
        for v in video:
            video_child = parse_video_child(fxd, v, dirname)
            id[video_child[0]] = video_child

        for variant in variants:
            mplayer_options += " " + fxd.getattr(variant, 'mplayer-options');
            parts = fxd.get_children(variant, 'part')
            if len(parts) == 1:
                # a variant with one file
                ref = fxd.getattr(parts[0] ,'ref')
                v = VideoItem(id[ref][1], parent=item, info=item.info, parse=False)
                v.files = None
                v.media_id, v.mplayer_options, player, is_playlist = id[ref][2:]
                if player:
                    v.force_player = player
                if is_playlist:
                    v.is_playlist  = True

                audio = fxd.get_children(parts[0], 'audio')
                if audio:
                    audio = { 'media_id': fxd.getattr(audio[0], 'media-id'),
                              'file'    : fxd.gettext(audio[0]) }
                    if not audio['media_id']:
                        audio['file'] = os.path.join(dirname, audio['file'])
                else:
                    audio = {}
                v.audio_file = audio

                subtitle = fxd.get_children(parts[0], 'subtitle')
                if subtitle:
                    subtitle = { 'media_id': fxd.getattr(subtitle[0], 'media-id'),
                                 'file'    : fxd.gettext(subtitle[0]) }
                    if not subtitle['media_id']:
                        subtitle['file'] = os.path.join(dirname, subtitle['file'])
                else:
                    subtitle = {}
                v.subtitle_file = subtitle

                # global <video> mplayer_options
                if mplayer_options:
                    v.mplayer_options += mplayer_options
            else:
                # a variant with a list of files
                v = VideoItem('', parent=item, info=item.info, parse=False)
                for p in parts:
                    ref = fxd.getattr(p ,'ref')
                    audio    = fxd.get_children(p, 'audio')
                    subtitle = fxd.get_children(p, 'subtitle')

                    if audio:
                        audio = { 'media_id': fxd.getattr(audio[0], 'media-id'),
                                  'file'    : fxd.gettext(audio[0]) }
                        if not audio['media_id']:
                            audio['file'] = os.path.join(dirname, audio['file'])
                    else:
                        audio = {}

                    if subtitle:
                        subtitle = { 'media_id': fxd.getattr(subtitle[0], 'media-id'),
                                     'file'    : fxd.gettext(subtitle[0]) }
                        if not subtitle['media_id']:
                            subtitle['file'] = os.path.join(dirname, subtitle['file'])
                    else:
                        subtitle = {}

                    sub = VideoItem(id[ref][1], parent=v, info=item.info, parse=False)
                    sub.files = None
                    sub.media_id, sub.mplayer_options, player, is_playlist = id[ref][2:]
                    sub.subtitle_file = subtitle
                    sub.audio_file    = audio
                    # global <video> mplayer_options
                    if mplayer_options:
                        sub.mplayer_options += mplayer_options
                    v.subitems.append(sub)

            v.name = fxd.getattr(variant, 'name')
            item.variants.append(v)

    else:
        # one or more files, this is directly for the item

        try:
            id, url, item.media_id, item.mplayer_options, player, is_playlist = parse_video_child(
                fxd, video[0], dirname)
        except (IndexError, TypeError), why:
            logger.warning('%r is corrupt', fxd.filename)
            raise
        if url.startswith('file://') and os.path.isfile(url[7:]):
            variables = item.info.get_variables()
            item.set_url(url, info=True)
            item.info.set_variables(variables)
        elif url.startswith('file://') and os.path.isdir(url[7:]):
            # dvd dir
            variables = item.info.get_variables()
            item.set_url(url.replace('file://', 'dvd:/')+ '/VIDEO_TS/', info=True)
            item.info.set_variables(variables)
        else:
            item.set_url(url, info=False)
#        if title:
#            item.name = title
        if player:
            item.force_player = player
        if is_playlist:
            item.is_playlist  = True
        if len(video) == 1:
            # global <video> mplayer_options
            if mplayer_options:
                item.mplayer_options += mplayer_options

        # if there is more than one item add them to subitems
        if len(video) > 1:
            # a list of files
            subitem_matched = False
            for s in video:
                #id, url, item.media_id, mplayer_options, player, is_playlist = parse_video_child(fxd, s, dirname)
                video_child = parse_video_child(fxd, s, dirname)
                url = video_child[1]

                v = VideoItem(url, parent=item, info=item.info, parse=False)

                if url.startswith('file://'):
                    v.files = FileInformation()

                    v.files.append(url[7:])
                    if url == item.url and not subitem_matched:
                        subitem_matched = True
                        v.files.fxd_file  = fxd.filename
                        if item.image:
                            v.files.image = item.image
                else:
                    v.files = None

                v.media_id, v.mplayer_options, player, is_playlist = video_child[2:]
                if player:
                    v.force_player = player
                if is_playlist:
                    item.is_playlist = True
                # global <movie> mplayer_options
                if mplayer_options:
                    v.mplayer_options += ' ' + mplayer_options
                item.subitems.append(v)