''

def _launch_iTunes(self):

    if self.verbose:
        logger().info(('    %s._launch_iTunes():\n        Instantiating    iTunes' % self.__class__.__name__))
    if isosx:
        import appscript
        as_name = appscript.__name__
        as_version = appscript.__version__
        '\n                                                Launch    iTunes    if    not    already    running\n                                                '
        running_apps = appscript.app('System    Events')
        if ('iTunes' not in running_apps.processes.name()):
            if self.verbose:
                logger().info(('%s:_launch_iTunes():    Launching    iTunes' % self.__class__.__name__))
            try:
                self.iTunes = iTunes = appscript.app('iTunes', hide=True)
            except:
                self.iTunes = None
                raise UserFeedback(('    %s._launch_iTunes():    unable    to    find    installed    iTunes' % self.__class__.__name__), details=None, level=UserFeedback.WARN)
            iTunes.run()
            self.initial_status = 'launched'
        else:
            self.iTunes = appscript.app('iTunes')
            self.initial_status = 'already    running'
        '\n                                                Test    OSA    communication    with    iTunes.\n                                                If    unable    to    communicate    with    iTunes,    set    self.iTunes    to    None,    then\n                                                report    to    user    in    open()\n                                                '
        as_binding = 'dynamic'
        try:
            self.iTunes.name()
        except:
            import itunes
            self.iTunes = appscript.app('iTunes', terms=itunes)
            try:
                self.iTunes.name()
                as_binding = 'static'
            except:
                self.iTunes = None
                if self.verbose:
                    logger().info(('            unable    to    communicate    with    iTunes    via    %s    %s    using    any    binding' % (as_name, as_version)))
                return
        '\n                                                #    Read    the    current    storage    path    for    iTunes    media\n                                                cmd    =    "defaults    read    com.apple.itunes    NSNavLastRootDirectory"\n                                                proc    =    subprocess.Popen(    cmd,    shell=True,    cwd=os.curdir,    stdout=subprocess.PIPE)\n                                                proc.wait()\n                                                media_dir    =    os.path.expanduser(proc.communicate()[0].strip())\n                                                if    os.path.exists(media_dir):\n                                                                self.iTunes_media    =    media_dir\n                                                else:\n                                                                logger().error("        could    not    confirm    valid    iTunes.media_dir    from    %s"    %    \'com.apple.itunes\')\n                                                                logger().error("        media_dir:    %s"    %    media_dir)\n                                                '
        if self.verbose:
            import platform
            logger().info(('        %s    %s' % (__appname__, __version__)))
            logger().info(('        [OSX    %s,    %s    %s    (%s),    %s    driver    version    %d.%d.%d]' % (platform.mac_ver()[0], self.iTunes.name(), self.iTunes.version(), self.initial_status, self.__class__.__name__, self.version[0], self.version[1], self.version[2])))
            logger().info(('        communicating    with    iTunes    via    %s    %s    using    %s    binding' % (as_name, as_version, as_binding)))
            logger().info(('        calibre_library_path:    %s' % self.calibre_library_path))
    if iswindows:
        import win32com.client
        '\n                                                Launch    iTunes    if    not    already    running\n                                                Assumes    pythoncom    wrapper\n\n                                                ***    Current    implementation    doesn\'t    handle    UNC    paths    correctly,\n                                                                and    python    has    two    incompatible    methods    to    parse    UNCs:\n                                                                os.path.splitdrive()    and    os.path.splitunc()\n                                                                need    to    use    os.path.normpath    on    result    of    splitunc()\n\n                                                                Once    you    have    the    //server/share,    convert    with    os.path.normpath(\'//server/share\')\n                                                                os.path.splitdrive    doesn\'t    work    as    advertised,    so    use    os.path.splitunc\n                                                                os.path.splitunc("//server/share")    returns    (\'//server/share\',\'\')\n                                                                os.path.splitunc("C:/Documents")    returns    (\'c:\',\'/documents\')\n                                                                os.path.normpath("//server/share")    returns    "\\\\server\\share"\n                                                '
        try:
            self.iTunes = win32com.client.Dispatch('iTunes.Application')
        except:
            self.iTunes = None
            raise OpenFeedback(('Unable    to    launch    iTunes.\n' + 'Try    launching    calibre    as    Administrator'))
        if (not self.verbose):
            self.iTunes.Windows[0].Minimized = True
        self.initial_status = 'launched'
        try:
            logger().info(('        automation    interface    with    iTunes    %s    established' % self.iTunes.Version))
        except:
            self.iTunes = None
            raise OpenFeedback((('Unable    to    connect    to    iTunes.\n' + '    iTunes    automation    interface    non-responsive,    ') + 'recommend    reinstalling    iTunes'))
        '\n                                                #    Read    the    current    storage    path    for    iTunes    media    from    the    XML    file\n                                                media_dir    =    \'\'\n                                                string    =    None\n                                                with    lopen(self.iTunes.LibraryXMLPath,    \'r\')    as    xml:\n                                                                for    line    in    xml:\n                                                                                if    line.strip().startswith(\'<key>Music    Folder\'):\n                                                                                                soup    =    BeautifulSoup(line)\n                                                                                                string    =    soup.find(\'string\').renderContents()\n                                                                                                media_dir    =    os.path.abspath(string[len(\'file://localhost/\'):].replace(\'%20\',\'    \'))\n                                                                                                break\n                                                                if    os.path.exists(media_dir):\n                                                                                self.iTunes_media    =    media_dir\n                                                                elif    hasattr(string,\'parent\'):\n                                                                                logger().error("        could    not    extract    valid    iTunes.media_dir    from    %s"    %    self.iTunes.LibraryXMLPath)\n                                                                                logger().error("        %s"    %    string.parent.prettify())\n                                                                                logger().error("        \'%s\'    not    found"    %    media_dir)\n                                                                else:\n                                                                                logger().error("        no    media    dir    found:    string:    %s"    %    string)\n                                                '
        if self.verbose:
            logger().info(('        %s    %s' % (__appname__, __version__)))
            logger().info(('        [Windows    %s    -    %s    (%s),    driver    version    %d.%d.%d]' % (self.iTunes.Windows[0].name, self.iTunes.Version, self.initial_status, self.version[0], self.version[1], self.version[2])))
            logger().info(('        calibre_library_path:    %s' % self.calibre_library_path))
