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.subsmax.JSubsMaxApi;
import org.lodder.subtools.multisubdownloader.subtitleproviders.subsmax.model.SubMaxSubtitleDescriptor;
import org.lodder.subtools.sublibrary.JSubAdapter;
import org.lodder.subtools.sublibrary.Manager;
import org.lodder.subtools.sublibrary.control.ReleaseParser;
import org.lodder.subtools.sublibrary.logging.Logger;
import org.lodder.subtools.sublibrary.model.Release;
import org.lodder.subtools.sublibrary.model.TvRelease;
import org.lodder.subtools.sublibrary.model.MovieRelease;
import org.lodder.subtools.sublibrary.model.Subtitle;
import org.lodder.subtools.sublibrary.model.SubtitleMatchType;

public class JSubsMaxAdapter implements JSubAdapter, SubtitleProvider  {

  private static JSubsMaxApi jsmapi;

  public JSubsMaxAdapter(Manager manager) {
    try {
      if (jsmapi == null) {
        jsmapi = new JSubsMaxApi(manager);
      }
    } catch (Exception e) {
      Logger.instance.error("API JSubsMax INIT: " + e.getCause());
    }
  }
  
  @Override
  public String getName() {
    return "SubsMax";
  }

  @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) {
    String showName = "";
    if (tvRelease.getOriginalShowName().length() > 0) {
      showName = tvRelease.getOriginalShowName();
    } else {
      showName = tvRelease.getShow();
    }
    
    List<SubMaxSubtitleDescriptor> lSubtitles =
        jsmapi.searchSubtitles(showName, tvRelease.getSeason(), tvRelease
            .getEpisodeNumbers().get(0), sublanguageids[0]);
    
    List<Subtitle> listFoundSubtitles = new ArrayList<Subtitle>();
    
    for (SubMaxSubtitleDescriptor sub:lSubtitles){
      listFoundSubtitles.add(new Subtitle(Subtitle.SubtitleSource.SUBSMAX, sub.getFilename(),
        sub.getLink(), sublanguageids[0], "", SubtitleMatchType.EVERYTHING, ReleaseParser
            .extractReleasegroup(sub.getFilename()), "", false));
    }
    
    return listFoundSubtitles;
  }

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

}

@@ -555,62 +555,8 @@
 er;%0A
-import org.lodder.subtools.sublibrary.logging.Logger;%0A
 impo
@@ -833,16 +833,73 @@
 tchType;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Apublic
@@ -962,17 +962,16 @@
 rovider 
- 
 %7B%0A%0A  pri
@@ -1001,16 +1001,105 @@
  jsmapi;
+%0A  private static final Logger LOGGER = LoggerFactory.getLogger(JPodnapisiAdapter.class);
 %0A%0A  publ
@@ -1264,22 +1264,13 @@
    L
-ogger.instance
+OGGER
 .err
@@ -1294,26 +1294,12 @@
 INIT
-: %22 + e.getCause()
+%22, e
 );%0A 
@@ -1307,18 +1307,16 @@
   %7D%0A  %7D%0A
-  
 %0A  @Over
@@ -1618,16 +1618,17 @@
 Release)
+ 
 %7B%0A      
@@ -2026,28 +2026,24 @@
 ow();%0A    %7D%0A
-    
 %0A    List%3CSu
@@ -2152,29 +2152,16 @@
 vRelease
-%0A            
 .getEpis
@@ -2172,16 +2172,29 @@
 umbers()
+%0A            
 .get(0),
@@ -2214,20 +2214,16 @@
 ds%5B0%5D);%0A
-    
 %0A    Lis
@@ -2282,20 +2282,16 @@
 tle%3E();%0A
-    
 %0A    for
@@ -2324,9 +2324,11 @@
  sub
-:
+ : 
 lSub
@@ -2334,16 +2334,17 @@
 btitles)
+ 
 %7B%0A      
@@ -2430,16 +2430,20 @@
 ename(),
+ sub
 %0A       
@@ -2443,19 +2443,18 @@
         
-sub
+  
 .getLink
@@ -2524,18 +2524,16 @@
 eParser%0A
-  
         
@@ -2594,20 +2594,16 @@
 ;%0A    %7D%0A
-    
 %0A    ret

Convert JSubsMaxAdapter from old logger to new LOGGER slf4j