package org.lodder.subtools.multisubdownloader.subtitleproviders.adapters;

import java.util.ArrayList;
import java.util.List;

import org.lodder.subtools.multisubdownloader.subtitleproviders.SubtitleProvider;
import org.lodder.subtools.multisubdownloader.subtitleproviders.addic7ed.JAddic7edApi;
import org.lodder.subtools.multisubdownloader.subtitleproviders.addic7ed.model.Addic7edSubtitleDescriptor;
import org.lodder.subtools.sublibrary.JSubAdapter;
import org.lodder.subtools.sublibrary.Manager;
import org.lodder.subtools.sublibrary.logging.Logger;
import org.lodder.subtools.sublibrary.model.*;
import org.lodder.subtools.sublibrary.util.StringUtils;

public class JAddic7edAdapter implements JSubAdapter, SubtitleProvider {

  private static JAddic7edApi jaapi;

  public JAddic7edAdapter(boolean isLoginEnabled, String username, String password, boolean speedy, Manager manager) {
    try {
      if (jaapi == null) {
        if (isLoginEnabled) {
          jaapi = new JAddic7edApi(username, password, speedy, manager);
        } else {
          jaapi = new JAddic7edApi(speedy, manager);
        }
      }
    } catch (Exception e) {
      Logger.instance.error("API JAddic7ed INIT: " + e.getCause());
    }
  }

  @Override
  public String getName() {
    return "Addic7ed";
  }

  @Override
  public List<Subtitle> search(Release release, String languageCode) {
    if (release instanceof MovieRelease) {
      return this.searchSubtitles((MovieRelease) release, languageCode);
    } else if (release instanceof TvRelease) {
      return this.searchSubtitles((TvRelease) release, languageCode);
    }
    return new ArrayList<Subtitle>();
  }

  @Override
  public List<Subtitle> searchSubtitles(TvRelease tvRelease, String... sublanguageids) {
    List<Addic7edSubtitleDescriptor> lSubtitles = new ArrayList<Addic7edSubtitleDescriptor>();
    List<Subtitle> listFoundSubtitles = new ArrayList<Subtitle>();
    try {
      String showName = "";

      if (tvRelease.getShow().length() > 0) {
        showName = jaapi.searchSerieName(tvRelease.getShow());
      }

      if (showName.length() == 0) {
        if (tvRelease.getOriginalShowName().length() > 0) {
          showName = jaapi.searchSerieName(tvRelease.getOriginalShowName());
        }
      }

      if (showName.length() > 0) {
        lSubtitles.addAll(jaapi.searchSubtitles(showName, tvRelease.getSeason(), tvRelease
            .getEpisodeNumbers().get(0), tvRelease.getTitle()));
      }

    } catch (Exception e) {
      Logger.instance.error("API JAddic7ed searchSubtitles using title: " + e);
    }
    for (Addic7edSubtitleDescriptor sub : lSubtitles) {
      if (sub.getLanguage().equals("Dutch")) sub.setLanguage("nl");
      if (sub.getLanguage().equals("English")) sub.setLanguage("en");
      if (sublanguageids[0].equals(sub.getLanguage())) {
        listFoundSubtitles.add(new Subtitle(Subtitle.SubtitleSource.ADDIC7ED, StringUtils
            .removeIllegalFilenameChars(sub.getTitel() + " " + sub.getVersion()), sub.getUrl(), sub
            .getLanguage(), sub.getVersion(), SubtitleMatchType.EVERYTHING, sub.getVersion(), sub
            .getUploader(), sub.isHearingImpaired()));
      }
    }
    return listFoundSubtitles;
  }

  @Override
  public List<Subtitle> searchSubtitles(MovieRelease movieRelease, String... sublanguageids) {
    // TODO Auto-generated method stub
    return null;
  }

}

@@ -537,22 +537,196 @@
 ary.
-logging.Logger
+model.MovieRelease;%0Aimport org.lodder.subtools.sublibrary.model.Release;%0Aimport org.lodder.subtools.sublibrary.model.Subtitle;%0Aimport org.lodder.subtools.sublibrary.model.SubtitleMatchType
 ;%0Aim
@@ -771,9 +771,17 @@
 del.
-*
+TvRelease
 ;%0Aim
@@ -833,16 +833,73 @@
 ngUtils;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Apublic
@@ -1004,16 +1004,105 @@
 jaapi;%0A%0A
+  private static final Logger LOGGER = LoggerFactory.getLogger(JAddic7edAdapter.class);%0A%0A
   public
@@ -1192,16 +1192,22 @@
  speedy,
+%0A     
  Manager
@@ -1477,38 +1477,29 @@
 e) %7B%0A      L
-ogger.instance
+OGGER
 .error(%22API 
@@ -1519,23 +1519,11 @@
 T: %22
- + e.getCause()
+, e
 );%0A 
@@ -2816,22 +2816,13 @@
    L
-ogger.instance
+OGGER
 .err
@@ -2870,13 +2870,11 @@
 itle
-:
  %22
- +
+,
  e);

Convert JAddic7edAdapter from old logger to new LOGGER slf4j