/** @param file */
  private IMDBEntry lookUpIMDB(File file) {
    boolean tryAgain = true;
    String searchString = file.getName();
    IMDBEntry entry = null;

    System.out.println("Trying to retrieve IMDB entry...");

    while (tryAgain) {
      try {
        entry = PARSER.find(searchString);

        if (entry.getTitle() == null) {
          System.out.println(
              "Searched for \""
                  + searchString
                  + "\" but didn't find anything. Try again with different string? [y/N]");
          if (!askUserYesNo()) {
            System.out.println("File was not imported!");
            return null;
          }

          System.out.println("Insert new search string to search for: ");
          searchString = readInput();
        } else {
          System.out.println("Found entry " + entry.getTitle() + " " + entry.getGenres() + ".");
          System.out.println(" Do you want to use that? [y/N]");

          if (askUserYesNo()) {
            tryAgain = false;
          } else {
            System.out.println("Insert new search string to search for: ");
            searchString = readInput();
          }
        }
      } catch (Exception e) {
        System.out.println(
            "Can't reach web service to ask for IMDB data ("
                + e.getClass()
                + "). Try again? [y/N]");
        if (!askUserYesNo()) {
          System.out.println("File was not imported!");
          return null;
        }
      }
    }

    return entry;
  }
    private IMDBEntry parse(BufferedReader reader) throws IOException {
      IMDBEntry entry = new IMDBEntry();

      String line = reader.readLine();
      while (line != null) {
        if (line.startsWith(ENTRY_TITLE)) {
          entry.setTitle(getValue(line));
        } else if (line.startsWith(ENTRY_URL)) {
          entry.setImdbUrl(getValue(line));
        } else if (line.startsWith(ENTRY_GENRES)) {
          String genres = getValue(line);
          List<String> genreList = Arrays.asList(genres.split(","));
          entry.setGenres(genreList);
        } else if (line.startsWith(ENTRY_RATING)) {
          entry.setImdbRating(getValue(line));
        } else if (line.startsWith(ENTRY_YEAR)) {
          entry.setYear(getValue(line));
        } else if (line.startsWith(ENTRY_SERIES)) {
          entry.setSeries(Boolean.parseBoolean(getValue(line)));
        }

        line = reader.readLine();
      }
      return entry;
    }
  @Override
  public void importFile(Collection<IMolecule> molecules, File file, String repository) {
    IMDBEntry entry = lookUpIMDB(file);
    if (entry == null) {
      System.out.println(
          "Failed to retrieve an IMDB entry for this file. Do you want to import this file anyway? [y/N]");
      if (askUserYesNo()) {
        IMoleculeImporter importer =
            MoleculeHandlerFactory.getInstance().getNextImporter(file, this);
        importer.importFile(molecules, file);
      }
      return;
    }

    boolean isRemote = true;
    String targetDirName = Configuration.getRepository(repository);

    if (repository != null && targetDirName == null) {
      System.out.println("Unkown remote location \"" + repository + "\". Check your config.");
      return;
    }

    if (targetDirName == null) {
      targetDirName = Configuration.get().getString("base.dir");
      isRemote = false;
    }

    String fileName = GenericImporter.copyFile(file, targetDirName);
    if (fileName == null) {
      System.out.println("Error. No file imported.");
      return;
    }

    IAtom title = Atom.build().withData(entry.getTitle()).withTag("title").buildWithDataAndTag();
    AtomBuilder binRefBuilder =
        Atom.build()
            .withData("/" + fileName)
            .withTag(CoreTags.FILEREF_TAG)
            .withTag(CoreTags.FILETYPE_VIDEO);

    if (isRemote) {
      binRefBuilder.withTag(CoreTags.FILEREF_REMOTE_TAG);
    }

    MoleculeBuilder mBuilder =
        Molecule.build()
            .withAtom(title)
            .withAtom(binRefBuilder.buildWithDataAndTag())
            .withTag("video");

    if (entry.isSeries()) {
      mBuilder.withTag("series");
    } else {
      mBuilder.withTag("movie");
    }

    if (isRemote) {
      IAtom remote =
          Atom.build()
              .withData(repository)
              .withTag(CoreTags.FILEREF_REMOTE_LOCATION)
              .buildWithDataAndTag();
      mBuilder.withAtom(remote);
    }

    if (entry.getImdbRating() != null) {
      IAtom rating =
          Atom.build().withData(entry.getImdbRating()).withTag("IMDB-rating").buildWithDataAndTag();
      mBuilder.withAtom(rating);
    }
    if (entry.getYear() != null) {
      IAtom year = Atom.build().withData(entry.getYear()).withTag("year").buildWithDataAndTag();
      mBuilder.withAtom(year);
    }
    if (entry.getImdbUrl() != null) {
      IAtom url = Atom.build().withData(entry.getImdbUrl()).withTag("url").buildWithDataAndTag();
      mBuilder.withAtom(url);
    }

    IMolecule molecule = mBuilder.buildWithAtomsAndTags();
    ATService.getMoleculeService().save(molecule);
    molecules.add(molecule);
  }