<commit_before>const path = require("path");
const { dialog } = require("electron");
const notification = require("./notification");
const Caption = require("caption-core");
const { triggerDonateWindow } = require("./donate");

const multiDownload = files => {
  const resultSet = [];
  const { mainWindow } = global.windows;

  try {
    const downloadFiles = files.map(({ file, subtitle }) =>
      new Promise(resolve => {
        const downloadLocation = path.dirname(file.path);
        const originalFileName = file.name;
        const subtitleFilename = originalFileName.replace(/\.[^/.]+$/, "");

        return Caption.download(
          {
            downloadUrl: subtitle.url,
          },
          "opensubtitles",
          `${downloadLocation}/${subtitleFilename}.srt`,
        ).then(() => {
          resultSet.push(`${downloadLocation}/${subtitleFilename}.srt`);
          mainWindow.webContents.send("updateFileSearchStatus", {
            filePath: file.path,
            status: "done",
          });
          resolve();
        });
      }));

    Promise.all(downloadFiles).then(() => {
      const message =
        resultSet.length > 0
          ? `${resultSet.length} subtitles have been successfully downloaded!`
          : "Could not find any subtitles.";

      notification(message);
      mainWindow.webContents.send("allFilesDownloaded");

      triggerDonateWindow();
    });
  } catch (err) {<commit_msg>Pass along search-item to Caption.download instead of hardcoded payload for openSubtitles<commit_after>const path = require("path");
const { dialog } = require("electron");
const notification = require("./notification");
const Caption = require("caption-core");
const { triggerDonateWindow } = require("./donate");

const multiDownload = files => {
  const resultSet = [];
  const { mainWindow } = global.windows;

  try {
    const downloadFiles = files.map(item =>
      new Promise(resolve => {
        const downloadLocation = path.dirname(item.file.path);
        const originalFileName = item.file.name;
        const subtitleFilename = originalFileName.replace(/\.[^/.]+$/, "");

        return Caption.download(
          item,
          item.source,
          `${downloadLocation}/${subtitleFilename}.srt`,
        ).then(() => {
          resultSet.push(`${downloadLocation}/${subtitleFilename}.srt`);
          mainWindow.webContents.send("updateFileSearchStatus", {
            filePath: item.file.path,
            status: "done",
          });
          resolve();
        });
      }));

    Promise.all(downloadFiles).then(() => {
      const message =
        resultSet.length > 0
          ? `${resultSet.length} subtitles have been successfully downloaded!`
          : "Could not find any subtitles.";

      notification(message);
      mainWindow.webContents.send("allFilesDownloaded");

      triggerDonateWindow();
    });
  } catch (err) {
{'fraction_non_alphanumeric': 0.1459552495697074, 'fraction_numerical': 0.0006884681583476765, 'mean_word_length': 2.623441396508728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6226192', 'n_tokens_mistral': 765, 'n_tokens_neox': 755, 'n_words': 157}