Browse Source

salabots euronews

Ivars 7 years ago
parent
commit
91704c44f5
3 changed files with 376 additions and 434 deletions
  1. 336
    408
      project.wpr
  2. 1
    0
      run.py
  3. 39
    26
      sources/euronews.py

+ 336
- 408
project.wpr
File diff suppressed because it is too large
View File


+ 1
- 0
run.py View File

@@ -684,6 +684,7 @@ def play_stream(stream, tmp_path=""):
684 684
 def player(url, title = "", subfile = "",headers={}, player="ffplay"):
685 685
     from subprocess import call
686 686
     title = cunicode(title).encode(sys.getfilesystemencoding())
687
+    url =  cunicode(url).encode(sys.getfilesystemencoding())
687 688
     # encode(sys.getfilesystemencoding())
688 689
     subfile = unicode(subfile).encode(sys.getfilesystemencoding())
689 690
     cmd1 = [r"c:\Program Files\VideoLAN\VLC\vlc.exe",url,

+ 39
- 26
sources/euronews.py View File

@@ -127,7 +127,7 @@ Connection: keep-alive
127 127
                     ptitle = article["pTitle"] if "pTitle" in article else ""
128 128
                     id = article["id"]
129 129
                     desc = "%s\n%s\n%s %s"%(title,atime,vert,ptitle)
130
-                    img = "http://static.euronews.com/articles/%s/399x225_%s.png"%(id,id)
130
+                    img = "http://static.euronews.com/articles/%s/399x225_%s.jpg"%(id,id)
131 131
                     if not atype in ("breakingnews","wire"):
132 132
                         data2 = "content/getArticle?lang=%s&id=%s"%(lang,id)
133 133
                     else:
@@ -161,29 +161,25 @@ Connection: keep-alive
161 161
         streams = []
162 162
 
163 163
         if path == "live":
164
-            url = "http://www.euronews.com/api/watchlive.json" if lang == "en" else "http://%s.euronews.com/api/watchlive.json" % lang
165
-            r = self._http_request(url)
166
-            try:
167
-                js = json.loads(r)
168
-                url = js["url"]
169
-            except:
170
-                raise Exception("No live stream found")
171
-            r = self._http_request(url)
172
-            try:
173
-                js = json.loads(r)
174
-                if not js["status"]=="ok":
175
-                    raise Exception("No live stream found")
176
-            except:
177
-                raise Exception("No live stream found")
178
-
179
-            stream = util.item()
180
-            stream["url"]=js["primary"]
181
-            stream["lang"]= lang
182
-            stream["quality"]="variant"
183
-            stream["name"]="Euronews live [%s]"%lang
184
-            stream["desc"]=stream["name"]
185
-            stream["type"]="hls" #stream_type(url)
186
-            streams.append(stream)
164
+            if "lang" in qs:
165
+                del qs["lang"]
166
+            languages = self.get_languages()
167
+            for lang in languages:
168
+                # http://api.euronews.com/ipad/androidPhoneEuronews-1.4/live.getUrl/en
169
+                data2 =  "live.getUrl/%s" % lang
170
+                js = self.call2(data2)
171
+                if not "primary" in js:
172
+                    continue
173
+                stream = util.item()
174
+                stream["url"]=js["primary"]
175
+                stream["lang"]= lang
176
+                stream["quality"]="variant"
177
+                stream["name"]="Euronews live [%s]"%lang
178
+                stream["desc"]=stream["name"]
179
+                stream["type"]="hls" #stream_type(url)
180
+                streams.append(stream)
181
+            if not streams:
182
+                raise Exception("No streams found!")
187 183
 
188 184
         elif clist=="content" and plist[1] == "getArticle":
189 185
             if "lang" in qs:
@@ -191,8 +187,8 @@ Connection: keep-alive
191 187
             languages = self.get_languages()
192 188
             for lang in languages:
193 189
                 id = qs["id"]
194
-                req = '{"methodName":"content.getArticle","apiKey":"androidPhoneEuronews-1.0","params":{"id":"%s"},"language":"%s"}'%(id,lang)
195
-                r = self.call(req)
190
+                url = "content.getArticle/%s?format=html&id=%s" % (lang, id)
191
+                r = self.call2(url)
196 192
                 if not r:
197 193
                     raise Exception("No live stream found")
198 194
                 if not "articlelist" in r:
@@ -289,6 +285,23 @@ content-disposition: form-data; name=request
289 285
         else:
290 286
             return None
291 287
 
288
+    def call2(self, data, headers=None):
289
+        if not headers: headers = self.headers
290
+        #if not lang: lang = self.country
291
+        url = "http://api.euronews.com/ipad/androidPhoneEuronews-1.4/" + data
292
+        headers = headers2dict("""
293
+User-Agent: okhttp/3.8.1
294
+   """)
295
+        content = self._http_request(url, headers=headers)
296
+        if content:
297
+            try:
298
+                result = json.loads(content)
299
+                return result
300
+            except Exception, ex:
301
+                return None
302
+        else:
303
+            return None
304
+
292 305
 
293 306
 if __name__ == "__main__":
294 307
     language= "en"