]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
Work in progress, doesn't work
authorJan-Pascal van Best <janpascal@vanbest.org>
Wed, 4 Apr 2012 19:11:53 +0000 (21:11 +0200)
committerJan-Pascal van Best <janpascal@vanbest.org>
Wed, 4 Apr 2012 19:11:53 +0000 (21:11 +0200)
src/main/java/org/vanbest/xmltv/AbstractEPGSource.java
src/main/java/org/vanbest/xmltv/Config.java
src/main/java/org/vanbest/xmltv/EPGSource.java
src/main/java/org/vanbest/xmltv/EPGSourceFactory.java
src/main/java/org/vanbest/xmltv/RTL.java
src/main/java/org/vanbest/xmltv/TvGids.java

index 2eb200e3c4387a3738cd05c75ab19119d8d0ffd9..d9e268468af1e94c19a30cd294aa55c04694b7a9 100644 (file)
@@ -20,8 +20,9 @@ public abstract class AbstractEPGSource implements EPGSource {
        
        public static final int MAX_FETCH_TRIES=5;
 
-       public AbstractEPGSource(Config config) {
+       public AbstractEPGSource(int sourceId, Config config) {
                this.config = config;
+               this.sourceId = sourceId;
                cache = new ProgrammeCache(config);
        }
 
index 835627ba8926b0c04b6e1dd2b97ad5a9e6e55131..60ef33339b1e84cc375f2445109e95c8077ac4ae 100644 (file)
@@ -64,8 +64,7 @@ public class Config {
        
        private Config() {
                Properties configProp = new Properties();
-        InputStream in = ClassLoader.getSystemResourceAsStream("/tv_grab_nl_java.properties");
-        System.out.println(in);
+        InputStream in = ClassLoader.getSystemResourceAsStream("tv_grab_nl_java.properties");
         try {
             configProp.load(in);
         } catch (IOException e) {
index d3211b7a34a52e7b99308fbac5eff61b413ea821..2c53e553cf56ca68dbab05001846bfc803a61a57 100644 (file)
@@ -14,7 +14,7 @@ public interface EPGSource {
 
        public int getId();
        public void setId(int id);
-    public String getName();
+    public String getName(); // must be static
 
        public List<Channel> getChannels();
        // Convenience method
index 7a78bc87a44ffc41ce466e426c9c07a330c1d133..1263e9c6fd7dc36b1c09d886ff1d6411925d0666 100644 (file)
@@ -3,11 +3,13 @@ package org.vanbest.xmltv;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
@@ -16,12 +18,13 @@ public class EPGSourceFactory {
        private static Map<Integer,Class<EPGSource>> classes = new HashMap<Integer,Class<EPGSource>>();
        private static Map<Integer,String> names = new HashMap<Integer,String>();
        private static boolean initialised=false;
+       private static List<Integer> sources=new ArrayList<Integer>();
 
        static void init() {
                if(initialised) return;
                Properties configProp = new Properties();
         ClassLoader loader = ClassLoader.getSystemClassLoader();
-        InputStream in = loader.getResourceAsStream("/org/vanbest/xmltv/tv_grab_nl_java.properties");
+        InputStream in = loader.getResourceAsStream("tv_grab_nl_java.properties");
         try {
             configProp.load(in);
         } catch (IOException e) {
@@ -33,10 +36,13 @@ public class EPGSourceFactory {
                        try {
                                Class<EPGSource> clazz = (Class<EPGSource>) loader.loadClass(name);
                                classes.put(source,  clazz);
-                               Method getName=clazz.getMethod("getName");
-                               String sourceName=(String)getName.invoke(null);
+                               System.out.println("clazz: " + clazz.toString());
+                               Field NAME=clazz.getField("NAME");
+                               System.out.println("NAME: " + NAME.toString());
+                               String sourceName=(String)NAME.get(null);
                                names.put(source,sourceName);
                                ids.put(sourceName,source);
+                               sources.add(source);
                        } catch (ClassNotFoundException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
@@ -62,7 +68,7 @@ public class EPGSourceFactory {
        public EPGSource createEPGSource(int source, Config config) {
                Constructor<EPGSource> constructor;
                try {
-                       constructor = classes.get(source).getConstructor(Config.class);
+                       constructor = classes.get(source).getConstructor(Integer.class,Config.class);
                        return constructor.newInstance(source, config);
                } catch (NoSuchMethodException e) {
                        // TODO Auto-generated catch block
@@ -100,11 +106,9 @@ public class EPGSourceFactory {
        }
 
        public int[] getAll() {
-               Integer[] list = (Integer[]) classes.keySet().toArray();
-               Arrays.sort(list);
-               int[] result = new int[list.length];
+               int[] result = new int[sources.size()];
                for(int i=0; i<result.length; i++) {
-                       result[i]=list[i];
+                       result[i]=sources.get(i);
                }
                return result;
        }
index 038f9bcc5e14cad94dba6627074f8328773868a3..fcf2583c60f69a7a339129120af61ede57b2d21d 100644 (file)
@@ -60,6 +60,7 @@ public class RTL extends AbstractEPGSource implements EPGSource  {
        private static final String detail_url="http://www.rtl.nl/active/epg_data/uitzending_data/";\r
        private static final String icon_url="http://www.rtl.nl/service/gids/components/vaste_componenten/";\r
        private static final int MAX_PROGRAMMES_PER_DAY = 9999;\r
+       public static final String NAME="rtl.nl";\r
        \r
        String[] xmlKeys = {"zendernr", "pgmsoort", "genre", "bijvnwlanden", "ondertiteling", "begintijd", "titel", \r
                        "site_path", "wwwadres", "presentatie", "omroep", "eindtijd", "inhoud", "tt_inhoud", "alginhoud", "afl_titel", "kijkwijzer" };\r
@@ -72,12 +73,12 @@ public class RTL extends AbstractEPGSource implements EPGSource  {
                }\r
        }\r
        \r
-       public RTL(Config config) {\r
-               super(config);\r
+       public RTL(int sourceId, Config config) {\r
+               super(sourceId, config);\r
        }\r
        \r
        public String getName() {\r
-               return "rtl.nl";\r
+               return NAME;\r
        }\r
        \r
        public List<Channel> getChannels() {\r
@@ -335,7 +336,7 @@ public class RTL extends AbstractEPGSource implements EPGSource  {
         */\r
        public static void main(String[] args) {\r
                Config config = Config.getDefaultConfig();\r
-               RTL rtl = new RTL(config);\r
+               RTL rtl = new RTL(2, config);\r
                try {\r
                        List<Channel> channels = rtl.getChannels();\r
                        System.out.println("Channels: " + channels);\r
index 92d223992f8ca4a25c4ad69552f294b7c1806407..91582f347baf8433a2f01382619ec92fbecc9f52 100644 (file)
@@ -57,13 +57,14 @@ public class TvGids extends AbstractEPGSource implements EPGSource {
        static String html_detail_base_url = "http://www.tvgids.nl/programma/";
        
        private static final int MAX_PROGRAMMES_PER_DAY = 9999;
+       public static String NAME="tvgids.nl";
 
-       public TvGids(Config config) {
-               super(config);
+       public TvGids(int sourceId, Config config) {
+               super(sourceId, config);
        }
        
        public String getName() {
-               return "tvgids.nl";
+               return NAME;
        }
        
        public static URL programmeUrl(List<Channel> channels, int day) throws Exception {
@@ -439,7 +440,7 @@ public class TvGids extends AbstractEPGSource implements EPGSource {
         */
        public static void main(String[] args) {
                Config config = Config.getDefaultConfig();
-               TvGids gids = new TvGids(config);
+               TvGids gids = new TvGids(1, config);
                try {
                        List<Channel> channels = gids.getChannels();
                        System.out.println("Channels: " + channels);