Ivars преди 6 години
родител
ревизия
42057d93fa
променени са 18 файла, в които са добавени 915 реда и са изтрити 599 реда
  1. 15
    7
      file.py
  2. Двоични данни
      picons/lr1.png
  3. Двоични данни
      picons/lr2.png
  4. Двоични данни
      picons/lr3.png
  5. Двоични данни
      picons/lr4.png
  6. Двоични данни
      picons/lr5.png
  7. Двоични данни
      picons/lr6.png
  8. Двоични данни
      picons/lr_1_lv.png
  9. Двоични данни
      picons/lr_2_lv.png
  10. Двоични данни
      picons/lr_3_lv.png
  11. Двоични данни
      picons/ltv1.png
  12. Двоични данни
      picons/ltv7.png
  13. Двоични данни
      picons/visiem.png
  14. 696
    429
      project.wpr
  15. 1
    0
      sources/filmix.py
  16. 3
    1
      sources/play24.py
  17. 176
    161
      sources/replay.py
  18. 24
    1
      util.py

+ 15
- 7
file.py Целия файл

@@ -112,7 +112,7 @@ def isdir(url):
112 112
         lines = []
113 113
         file.retrbinary(cmd, lines.append)
114 114
         file.close()
115
-        return False if "No such file or directory" in lines[0] else True
115
+        return False if lines and "No such file or directory" in lines[0] else True
116 116
     else:
117 117
         raise Exception("Not valid protocol")
118 118
 
@@ -198,23 +198,31 @@ def join(*arg):
198 198
 def encoding(url):
199 199
     p = parse_url(url)
200 200
     if p["protocol"] == "file":
201
-        return sys.getfilesystemencoding()
201
+        enc = sys.getfilesystemencoding()
202
+        #enc = "utf8"  # TODO
202 203
     else:
203
-        return "utf8"
204
+        enc = "utf8"
205
+    return enc
204 206
 
205 207
 def make_fname(name):
206 208
     #"\[.+?\]" "[/\n\r\t,:]"
207
-    name = name.strip()
208 209
     name = re.sub(r"[/\n\r\t,:/\\]", " ", name)
209 210
     name = re.sub("['""\?\*<>]","", name)
211
+    name = re.sub(r"(\[[^\[]*\])", "", name)
210 212
     name = name.replace("&quot;","")
213
+    name = name.strip()
211 214
     return name
212 215
 
213 216
 
214 217
 def encode(url):
215
-    if not isinstance(url, unicode):
216
-        url = url.decode("utf8")
217
-    return url.encode(encoding(url))
218
+    p = parse_url(url)
219
+    if p["protocol"] == "file":  # unicode
220
+        if not isinstance(url, unicode):
221
+            url = url.decode("utf8")
222
+    else:
223
+        if isinstance(url, unicode):
224
+            url = url.encode("utf8")
225
+    return url
218 226
 
219 227
 if __name__ == "__main__":
220 228
     res = join("aaa", "bbb")

Двоични данни
picons/lr1.png Целия файл


Двоични данни
picons/lr2.png Целия файл


Двоични данни
picons/lr3.png Целия файл


Двоични данни
picons/lr4.png Целия файл


Двоични данни
picons/lr5.png Целия файл


Двоични данни
picons/lr6.png Целия файл


Двоични данни
picons/lr_1_lv.png Целия файл


Двоични данни
picons/lr_2_lv.png Целия файл


Двоични данни
picons/lr_3_lv.png Целия файл


Двоични данни
picons/ltv1.png Целия файл


Двоични данни
picons/ltv7.png Целия файл


Двоични данни
picons/visiem.png Целия файл


+ 696
- 429
project.wpr
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 1
- 0
sources/filmix.py Целия файл

@@ -304,6 +304,7 @@ Cookie: FILMIXNET=%s;
304 304
                     stream["quality"]=st[0]
305 305
                     stream["name"]= title
306 306
                     stream["desc"]=desc
307
+                    stream["img"] = img
307 308
                     streams.append(stream)
308 309
             return streams
309 310
 

+ 3
- 1
sources/play24.py Целия файл

@@ -156,6 +156,8 @@ class Source(SourceBase):
156 156
                 m = re.search('<meta name="description" content="([^"]+)" />', r, re.DOTALL)
157 157
                 desc = m.group(1) if m else ""
158 158
                 desc = h.unescape(desc.decode("utf8")).encode("utf8")
159
+                m = re.search('"og:image" content="([^"]+)', r)
160
+                img = m.group(1) if m else ""
159 161
 
160 162
                 url = "http://player.tvnet.lv/v/%s"%id
161 163
             else:
@@ -172,7 +174,7 @@ class Source(SourceBase):
172 174
                 if t in s:
173 175
                     data2 = s[t][0]
174 176
                     break
175
-            return (title,data2,"",desc)
177
+            return (title,data2, img,desc)
176 178
 
177 179
 
178 180
     def is_video(self,data):

+ 176
- 161
sources/replay.py Целия файл

@@ -12,7 +12,7 @@ except:
12 12
     import simplejson as json
13 13
 import os
14 14
 import urllib2, urllib
15
-import datetime, re, sys
15
+import datetime, time, re, sys
16 16
 import ssl
17 17
 if "_create_unverified_context" in dir(ssl):
18 18
     ssl._create_default_https_context = ssl._create_unverified_context
@@ -42,49 +42,45 @@ class Source(SourceBase):
42 42
 
43 43
     def get_content(self, data):
44 44
         print "[replay] get_content:", data
45
-        if "::" in data:
46
-            data = data.split("::")[1]
47
-        path = data.split("?")[0]
48
-        clist = path.split("/")[0]
49
-        params = data[data.find("?"):] if "?" in data else ""
50
-        qs = dict(map(lambda x:x.split("="),re.findall("\w+=\w+",params)))
45
+        source, data, path, plist, clist, params, qs = self.parse_data(data)
51 46
         lang = qs["lang"] if "lang" in qs else self.country
52
-
53 47
         content=[]
54 48
         content.append(("..return", "back","back.png","Return back"))
55 49
 
56 50
         if clist=="home":
57 51
             content.extend([
58 52
                 ("Live streams", "replay::tiesraide","","TV live streams"),
59
-                ("Search LV", "replay::search/?term={0}&lang=lv","","Search content LV"),
60
-                ("Last videos LV", "replay::visi/jaunakie/?source=ltv&lang=lv","","Last aired videos LV"),
61
-                ("Last videos by categories LV", "replay::kategorijas/?lang=lv","","Last videos by categories LV"),
62
-                ("All programs LV", "replay::raidijumi/?type=video","","All programs by name LV"),
53
+                ("Search LV", "replay::meklet?term={0}&lang=lv","","Search content LV"),
54
+                ("Last videos LV", "replay::visi/jaunakie?mtype=video&page=1&lang=lv","","Last aired videos LV"),
55
+                ("Last videos by categories LV", "replay::kategorijas?lang=lv","","Last videos by categories LV"),
56
+                ("Last chance LV", "replay::visi/pedeja-iespeja?lang=lv","","Last videos by categories LV"),
57
+                ("Videos by popularity LV", "replay::visi/popularie?mtype=video&lang=lv","","Programs by popularity"),
58
+                ("All programs LV", "replay::raidijumi?mtype=video&lang=lv","","All programs by name LV"),
63 59
                 ("Programs by categories LV", "replay::categories?lang=lv","","All programs by categories LV"),
64 60
                 #("Channels", "replay::channels?language=%s"%self.country,"","TV channels"),
65
-                ("Videos by popularity LV", "replay::visi/popularie/?source=ltv&lang=lv","","Programs by popularity"),
66 61
 
67
-                ("Search RU", "replay::search/?term={0}&lang=ru","","Search content RU"),
68
-                ("Last videos RU", "replay::vse/novie/?source=ltv&lang=ru","","Last aired videos RU"),
69
-                ("Last videos by categories RU", "replay::kategorijas/?lang=ru","","Last videos by categories RU"),
70
-                ("All programs RU", "replay::peredachi/?lang=ru&type=video","","All programs by name"),
62
+                ("Search RU", "replay::poisk?term={0}&lang=ru","","Search content RU"),
63
+                ("Last videos RU", "replay::vse/novie?mtype=video&lang=ru","","Last aired videos RU"),
64
+                ("Last videos by categories RU", "replay::kategorijas?lang=ru","","Last videos by categories RU"),
65
+                ("All programs RU", "replay::peredachi?lang=ru&mtype=video","","All programs by name"),
71 66
                 ("Programs by categories RU", "replay::categories?lang=ru","","Programs by categories RU")
72 67
             ])
73 68
             return content
74 69
 
75 70
         ### programmu kategorijas ###
76 71
         elif clist=="categories":
77
-            url = "https://replay.lsm.lv/lv/raidijumi/?lang=lv&type=video" if lang =="lv" else "https://replay.lsm.lv/ru/peredachi/?lang=ru&type=video"
72
+            url = "https://replay.lsm.lv/lv/raidijumi" if lang =="lv" else "https://replay.lsm.lv/ru/peredachi"
78 73
             r = self._http_request(url)
79 74
             icons = {
80 75
                 #TODO
81
-                "1": "https://www.iconfinder.com/icons/314161/download/png/256",
76
+            "1": "https://www.iconfinder.com/icons/314161/download/png/256",
82 77
             }
83
-            for item in re.findall(r'<a .+href="(\?lang=\w+&type=video&theme=\d+)">([^<]+)</a>\t', r):
84
-                title = item[1]
85
-                data2 = url.split("?")[0]+item[0]
86
-                data2 = data2.replace(API_URL%lang,"")
87
-                theme =  item[0].split("theme=")[1]
78
+            result = re.findall(r'<a href="https://replay\.lsm\.lv/(lv|ru)/([^\?^"]+\?category=\d+)" class="badge badge-pill">([^<]+)</a>', r)
79
+            for item in result:
80
+
81
+                title = item[2].strip()
82
+                data2 = item[1].replace("&amp;", "&") + "&lang=%s" % item[0]
83
+                #theme =  item[0].split("theme=")[1]
88 84
                 img = self.img # TODO icons["1"]
89 85
                 desc = title
90 86
                 content.append((title,self.name+"::"+data2,img,desc))
@@ -94,54 +90,144 @@ class Source(SourceBase):
94 90
         elif clist=="kategorijas":
95 91
             url = "https://replay.lsm.lv/lv/" if lang =="lv" else "https://replay.lsm.lv/ru/"
96 92
             r = self._http_request(url)
97
-            for item in re.findall(r'<a href="/(lv|ru)/kategorija/(\w+)/">.+?<i class="[^"]+"></i>.+?<span>([^<]+)</span>', r, re.DOTALL):
98
-                title = item[2]
99
-                data2 = "kategorija/%s/?lang=%s"%(item[1],item[0])
93
+            for m in re.finditer(r'<a href="https://replay\.lsm\.lv/(lv|ru)/(kategorija/[\w-]+)" class="">.+?<span>([^<]+)</span>', r, re.DOTALL):
94
+                title = m.group(3)
95
+                data2 = "%s?lang=%s"%(m.group(2), m.group(1))
100 96
                 img = self.img
101 97
                 desc = title
102 98
                 content.append((title,self.name+"::"+data2,img,desc))
103 99
             return content
104 100
 
101
+
102
+        ### Raidijumi (programmas) ###
103
+        elif clist in ( "raidijumi","peredachi"):
104
+            r = self.call(data, lang=lang)
105
+            result = re.findall(r'<a href="https://replay\.lsm\.lv/(lv|ru)/([^"]+)"><span>([^<]+)</span>', r, re.DOTALL)
106
+            for item in result:
107
+                title = item[2].strip()
108
+                data2 = item[1]+"?lang=%s"%item[0]
109
+                img = ""
110
+                desc  = title
111
+                content.append((title,self.name+"::"+data2,img,desc))
112
+            return content
113
+
105 114
         ### Tiešraides kanānālu saraksts
106 115
         elif path=="tiesraide":
107
-            url2 = "https://replay.lsm.lv/styles/main.css"
108
-            r2= self._http_request(url2)
109 116
             url = "https://replay.lsm.lv/lv/tiesraide/ltv1/"
110 117
             # <div class="visible-xs">
111
-            r= self._http_request(url)
112
-            i2 = r.find('<div class="visible-xs">')
113
-            result = re.findall(r"""onclick="RE.tools.navigate\('/lv/(tiesraide/\w+/)'\).+?<h5>([^<]+)</h5>.+?<time>([^<]+)</time>""", r[0:i2], re.DOTALL)
118
+            r = self._http_request(url)
119
+            result = re.findall(r'class="small-guide.+?href="https://replay\.lsm\.lv/lv/([^"]+)".+?title="([^"]+)".+?<div class="item-body">([^<]+)</div>.+?<time>([^<]+)</time>', r, re.DOTALL)
114 120
             for item in result:
115 121
                 data2 = item[0]
116 122
                 ch = data2.split("/")[1]
117
-                title = ch.upper()
118
-                m = re.search(r'channel-logo--%s{background-image:url\("([^"]+)"\)' % ch, r2, re.DOTALL)
119
-                img = "https://replay.lsm.lv" + m.group(1)
120
-                desc = item[1]
121
-                # 00:10 &ndash; 00:45
122
-                desc = desc + " (%s)" % item[2].replace("&ndash;", "-")
123
+                title = item[1]
124
+                img = ch + ".png"
125
+                desc = item[2].strip()
126
+                desc = desc + " [%s]" % item[3]
123 127
                 title = title + " - " + desc
124 128
                 content.append((title,self.name+"::"+data2,img,desc))
125 129
             return content
126 130
 
131
+        ### Meklēsana ###
132
+        # TODO (jāsakrārto pēc jaunā templeita)
133
+        elif clist in ("search"):
134
+            r = self.call(data, lang=lang)
135
+            if not r:
136
+                return content
137
+            #for r2 in re.findall('<article itemtype="http://schema.org/Article" itemscope class="thumbnail thumbnail--default ">(.+?)</article>', r2, re.DOTALL):
138
+            for item in re.findall('itemprop="image" data-image="([^"]+)".+?<figcaption><h5 itemprop="name"><a itemprop="url" href="([^<]+)">([^<]+)</a></h5></figcaption>', r):
139
+                title = item[2]
140
+                data2 = item[1].replace("/%s/"%lang,"")+"?lang=%s"%lang
141
+                img = "https://replay.lsm.lv" + item[0]
142
+                desc  = title
143
+                content.append((title,self.name+"::"+data2,img,desc))
144
+
145
+            #for item in re.findall('itemprop="image" data-image="([^"]+)".+?<figcaption><h4 itemprop="about"><a href="([^"]+)">([^<]+)</a></h4>.*?<h5 itemprop="name"><a itemprop="url" href="([^"]+)">([^<]+)</a></h5>.+?datetime="([^"]+)" class="thumbnail__date ">([^<]+)</time>', r2):
146
+            for item in re.findall('itemprop="image" data-image="([^"]+)".+? class="icon-(ltv|lr).+?<figcaption><h4 itemprop="about"><a href="([^"]+)">([^<]+)</a></h4>.*?<h5 itemprop="name"><a itemprop="url" href="([^"]+)">([^<]+)</a></h5>.+?datetime="([^"]+)" class="thumbnail__date ">([^<]+)</time>', r):
147
+                if item[1]=="lr":continue
148
+                title = "%s - %s (%s)"%(item[3],item[5],item[7])
149
+                data2 = item[4].replace("/%s/"%lang,"")+"?lang=%s"%lang
150
+                img = item[0]  #.replace("https:","http:")
151
+                img = img.replace("lv//", "lv/")  # TODO eksperiments
152
+                desc = title
153
+                content.append((title,self.name+"::"+data2,img,desc))
154
+
155
+        # Raidijumu saraksti
156
+        elif True:
157
+            r = self.call(data, lang=lang)
158
+            if not r:
159
+                return content
160
+            result = re.findall("<article.+?>(.+?)</article>", r, re.DOTALL)
161
+            for item in result:
162
+                m = re.search(r'<h4 class="thumbnail__title"><a href="https://replay\.lsm\.lv/(\w+)/([^"]+)">([^<]+)</a></h4>', item, re.DOTALL)
163
+                if not m:
164
+                    continue
165
+                title = m.group(3).strip()
166
+                desc = title
167
+                data2 = m.group(2)
168
+                lang = m.group(1)
169
+                m = re.search(r'style="background-image: url\(([^\)]+)\)"', item, re.DOTALL)
170
+                img = m.group(1) if m else ""
171
+                m = re.search('datePublished" datetime="([^"]+)"', item, re.DOTALL)
172
+                if m:
173
+                    published = m.group(1)
174
+                    published = datetime.datetime.strptime(published,"%Y-%m-%dT%H:%M:%SZ")
175
+                    published = util.datetime_from_utc_to_local(published)
176
+                    published_datetime = datetime.datetime.strftime(published,"%d.%m.%Y %H:%M")
177
+                    published_date = datetime.datetime.strftime(published,"%d.%m.%Y")
178
+                    title = title + " (%s)" % published_date
179
+                    desc = desc + "\nPublished: %s" % published_datetime
180
+                m = re.search('thumbnail__duration">([^<]+)<', item, re.DOTALL)
181
+                if m:
182
+                    desc = desc + "\nDuration: %s" % m.group(1)
183
+                m = re.search(r'<a href="https://replay\.lsm\.lv/lv/raidijums/[^"]+">([^<]+)</a>', item, re.DOTALL)
184
+                if m:
185
+                    desc = desc + "\nProgram: %s" % m.group(1)
186
+                m = re.search('<li class="">(Vēl[^<]+)</li>', item, re.DOTALL)
187
+                if m:
188
+                    desc = desc + "\nRemaining: %s" % m.group(1)
189
+                content.append((title,self.name+"::"+data2,img,desc))
190
+
191
+            m = re.search(r'page=(\d+)" rel="next"', r, re.DOTALL)
192
+            if m:
193
+                page = int(m.group(1))
194
+                if "page="in data:
195
+                    data2 = re.sub("page=\d+","page=%s"%page,data)
196
+                else:
197
+                    if "?" in data:
198
+                        data2 =data+"&page=%s"%page
199
+                    else:
200
+                        data2 =data+"?page=%s"%page
201
+                content.append(("Next page",self.name+"::"+data2,"next.png","Next page"))
202
+
203
+            return content
204
+
205
+
206
+
207
+    def get_streams(self, data):
208
+        source, data, path, plist, clist, params, qs = self.parse_data(data)
209
+        lang = qs["lang"] if "lang" in qs else self.country
210
+
127 211
         ### Kanāla tiesraide
128
-        elif clist == "tiesraide" and "/" in data:
212
+        # TODO - jāuztaisa get_streams/get_info
213
+        if clist == "tiesraide" and "/" in data:
214
+            r = self.call(data, lang=lang)
129 215
             ch = data.split('/')[1]
130 216
             veids = "audio" if "lr" in ch else "video"
131 217
             #url = "https://replay.lsm.lv/lv/tiesraide/ltv7/"
132 218
             url = "https://replay.lsm.lv/lv/tiesraide/%s/"%ch
133 219
             r= self._http_request(url)
134 220
 
135
-            m = re.search('%s/">.+?<h5>([^<]+)+</h5>.*?<time>([^<]+)</time>'%ch, r, re.DOTALL)
221
+            m = re.search('span class="badge badge-primary">Tagad</span>([^<]+)<.+?<time>([^<]+)</time>', r, re.DOTALL)
136 222
             tagad = m.group(1).strip() if m else ""
137 223
             laiks = m.group(2).strip() if m else ""
138 224
             laiks = h.unescape(laiks).encode("utf8")
139
-            m = re.search("<h1>([^<]+)</h1>", r)
140 225
             title = m.group(1).strip() if m else path.split("/")[1].upper()
141
-            title = "%s - %s (%s)"%(title,tagad,laiks)
226
+            title = "%s - %s [%s]"%(ch.upper(), title,laiks)
227
+            desc = title
142 228
 
143 229
             if veids == "video":
144
-                m = re.search('<div class="video"><iframe.+src="([^"]+)"', r)
230
+                m = re.search('<iframe.+?src="([^"]+)"', r)
145 231
                 if not m:
146 232
                     raise Exception("No stream found")
147 233
                 url = m.group(1)
@@ -157,7 +243,7 @@ class Source(SourceBase):
157 243
                     raise Exception("No stream found")
158 244
                 url = m.group(1).replace('\\/', "/")
159 245
                 m = re.search('poster":"([^"]+)"', r, re.DOTALL)
160
-                img =  "https://ltv.lsm.lv" + m.group(1).replace("\\","") if m else ""
246
+                img =  "https://ltv.lsm.lv" + m.group(1).replace("\\","") if m else ch + '.png'
161 247
 
162 248
                 r = self._http_request(url,headers=headers)
163 249
                 m = re.search('"([^"]+m3u8[^"]+)"', r)
@@ -168,135 +254,64 @@ class Source(SourceBase):
168 254
 
169 255
             else: # audio
170 256
                 lrn = ch.replace("lr","")
171
-                url = "https:///www.latvijasradio.lsm.lv/lv/tiesraide/?channel=%s"%lrn
257
+                url = "https://latvijasradio.lsm.lv/lv/tiesraide/?channel=%s"%lrn
172 258
                 r = self._http_request(url)
173 259
                 m = re.search('"file":"([^"]+?m3u8.*?)"', r)
174 260
                 if not m:
175 261
                     raise Exception("No stream found")
176 262
                 data2 = m.group(1).replace("\\","")
177
-                img = self.img
178
-                desc = ""
179
-
180
-            desc = title
181
-            content =(title,data2,img,desc)
182
-            return content
183
-
184
-        #m = re.search(r'(\?page=\d+)" class=" paging__prev', r, re.IGNORECASE)
185
-        #if m:
186
-        #    data = re.sub("\?page=\d+", "", data)
187
-        #    data2 = data+m.group(1)
188
-        #    content.append(("Previous page",self.name+"::"+data2,"","Previous page"))
189
-
190
-        r = self.call(data, lang=lang)
191
-        if not r:
192
-            return content
193
-
194
-        if clist == "search":
195
-            #for r2 in re.findall('<article itemtype="http://schema.org/Article" itemscope class="thumbnail thumbnail--default ">(.+?)</article>', r2, re.DOTALL):
196
-            for item in re.findall('itemprop="image" data-image="([^"]+)".+?<figcaption><h5 itemprop="name"><a itemprop="url" href="([^<]+)">([^<]+)</a></h5></figcaption>', r):
197
-                title = item[2]
198
-                data2 = item[1].replace("/%s/"%lang,"")+"?lang=%s"%lang
199
-                img = "https://replay.lsm.lv" + item[0]
200
-                desc  = title
201
-                content.append((title,self.name+"::"+data2,img,desc))
202
-
203
-            #for item in re.findall('itemprop="image" data-image="([^"]+)".+?<figcaption><h4 itemprop="about"><a href="([^"]+)">([^<]+)</a></h4>.*?<h5 itemprop="name"><a itemprop="url" href="([^"]+)">([^<]+)</a></h5>.+?datetime="([^"]+)" class="thumbnail__date ">([^<]+)</time>', r2):
204
-            for item in re.findall('itemprop="image" data-image="([^"]+)".+? class="icon-(ltv|lr).+?<figcaption><h4 itemprop="about"><a href="([^"]+)">([^<]+)</a></h4>.*?<h5 itemprop="name"><a itemprop="url" href="([^"]+)">([^<]+)</a></h5>.+?datetime="([^"]+)" class="thumbnail__date ">([^<]+)</time>', r):
205
-                if item[1]=="lr":continue
206
-                title = "%s - %s (%s)"%(item[3],item[5],item[7])
207
-                data2 = item[4].replace("/%s/"%lang,"")+"?lang=%s"%lang
208
-                img = item[0]  #.replace("https:","http:")
209
-                img = img.replace("lv//", "lv/")  # TODO eksperiments
210
-                desc = title
211
-                content.append((title,self.name+"::"+data2,img,desc))
263
+                img = ch + ".png"
212 264
 
213
-        ### Raidijumi (programmas) ###
214
-        elif clist in ( "raidijumi","peredachi"):
215
-            for item in re.findall('<li itemprop="name"><a href="([^"]+)" itemprop="url">([^<]+)', r):
216
-            #for item in re.findall('<li itemprop="name"><a href="([^"]+)" itemprop="url">([^<]+)</a></li>', r):
217
-                title = item[1].strip()
218
-                data2 = item[0].replace("/%s/"%lang,"")+"?lang=%s"%lang
219
-                img = ""
220
-                desc  = ""
221
-                content.append((title,self.name+"::"+data2,img,desc))
222
-
223
-        ### Raidijuma ieraksti speciālie###
224
-        elif clist in ( "visi","vse",):
225
-            for item in re.findall('(?i)<figure><a href="([^"]+)" itemprop="image" data-image="([^"]+)".+class="thumbnail__duration">([^<]+)</time></figure><figcaption><h4 itemprop="about"><a href="[^"]+">([^<]+)</a></h4>.+>([^<]+).*</h5>.+>([^<]+)</time></figcaption>', r):
226
-                title = item[3].strip()
227
-                data2 = item[0].replace("/%s/"%lang,"")+"?lang=%s"%lang
228
-                img = item[1]  #.replace("https:","http:")
229
-                img = img.replace("lv//", "lv/")  # TODO eksperiments
230
-                desc  = "%s - %s\n%s"%(item[5],item[2],item[4])
231
-                content.append((title,self.name+"::"+data2,img,desc))
232
-
233
-        ### Raidijuma ieraksti (videos)
234
-        elif clist in ("raidijums","peredacha","kategorija"):
235
-            for item in re.findall('<article .+ href="([^"]+)".+image="([^"]+)".+class="thumbnail__duration">([^<]+).+">([^<]+).+class="thumbnail__date ">([^"]+)</time></figcaption></article>', r):
236
-                title = item[3].strip()
237
-                data2 = item[0].replace("/%s/"%lang,"")+"?lang=%s"%lang
238
-                img = item[1]  #.replace("https:","http:")
239
-                img = img.replace("lv//", "lv/")  # TODO eksperiments
240
-                desc = "%s - %s"%(item[4],item[2])
241
-                desc = desc.strip()
242
-                content.append((title,self.name+"::"+data2,img,desc))
243 265
 
244 266
         ### Ieraksts (video) ###
245 267
         elif clist in ("ieraksts","statja"):
246
-            m = re.search('src="([^"]+)"></iframe>', r)
268
+            r = self.call(data, lang=lang)
269
+            m = re.search('<iframe src="([^"]+)"', r)
270
+            if not m:
271
+                raise Exception("No stream found")
272
+            url2 = m.group(1).replace("&amp;", "&")
273
+            m = re.search('<h1 class="title">([^<]+)</h1>', r)
274
+            title = m.group(1).strip()
275
+            m = re.search('<meta content="([^"]+)" property="og:image">', r)
276
+            img = m.group(1) if m else ""
277
+            m = re.search('<div class="description">(.+?)</div>', r, re.DOTALL)
247 278
             if m:
248
-                url2 = m.group(1)
249
-                m = re.search('<meta property="og:title" content="([^"]+)"', r, re.DOTALL)
250
-                title = m.group(1)
251
-                m = re.search('<meta property="og:image" content="([^"]+)"', r, re.DOTALL)
252
-                img = m.group(1)
253
-                img = img.replace("lv//", "lv/")  # TODO eksperiments
254
-                m = re.search('<meta property="og:description" content="([^"]+)"', r, re.DOTALL)
255 279
                 desc = m.group(1)
256
-                m = re.search('<div class="media-description">(.+)<div id="tab-comments">', r, re.DOTALL)
257
-                if m:
258
-                    rr = re.sub("<.+?>", " ", m.group(1))
259
-                    rr = re.sub("[\t\n]", " ", rr)
260
-                    desc =  re.sub(" {2,100}", " ", rr).strip()
261
-
262
-                headers = headers2dict("""
263
-User-Agent: Mozilla/5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
264
-Referer: https://replay.lsm.lv/lv/ieraksts/ltv/70398/tiesa-runa.-lielbritanija-gatavojas-referendumam-par-tu/
265
-            """)
266
-                r2 = self._http_request(url2,headers=headers)
267
-                m = re.search('"file":"([^"]+)', r2)
268
-                if m:
269
-                    data2 = m.group(1).replace("\\","")
270
-                    m = re.search('"idstring":"([^"]+)', r2)
271
-                    #title = m.group(1).strip() if m else ""
272
-                    #title = title.decode("unicode-escape").encode("utf8")
273
-                    #title = title.replace("\n","")
274
-                    #img = ""
275
-                    #desc = ""
276
-                    if "youtube" in data2:
277
-                        video_id = re.search(r"/watch\?v=([^&]+)",data2).group(1)
278
-                        data2 = YouTubeVideoUrl().extract(video_id)
279
-                        if not data2:
280
-                            content=("No stream found %s"%data,"","","No stream found")
281
-                            return content
282
-                    content =(title,data2,img,desc)
283
-                    return content
284
-            content=("No stream found %s"%data,"","","No stream found")
285
-            return content
286
-
287
-        m = re.search(r'href="\?([^"]+)" class=" paging__next', r)
288
-        if m:
289
-            page = int(re.search("page=(\d+)",m.group(1)).group(1))
290
-            if "page="in data:
291
-                data2 = re.sub("page=\d+","page=%i"%page,data)
280
+                rr = re.sub("<.+?>", " ", m.group(1))
281
+                rr = re.sub("[\t\n]", " ", rr)
282
+                desc =  re.sub(" {2,100}", " ", rr).strip()
292 283
             else:
293
-                if "?" in data:
294
-                    data2 =data+"&page=%i"%page
295
-                else:
296
-                    data2 =data+"?page=%i"%page
297
-            content.append(("Next page",self.name+"::"+data2,"next.png","Next page"))
298
-
299
-        return content
284
+                desc = ""
285
+            headers = headers2dict("""
286
+User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
287
+Referer: https://replay.lsm.lv/%s/%s
288
+Host: ltv.lsm.lv
289
+            """% (lang, data))
290
+            r2 = self._http_request(url2,headers=headers)
291
+            m = re.search(r"<script>LTV.Video.players.create\('videoplay', ({.+?})\);</script>", r2, re.DOTALL)
292
+            #m = re.search('"file":"([^"]+)', r2)
293
+            if not m:
294
+                raise Exception("No stream found")
295
+            js = json.loads(m.group(1))
296
+            if "playlist" in js["player"]:
297
+                data2 = js["player"]["playlist"][0]["sources"][0]["file"]
298
+            elif "file" in  js["player"]:
299
+                data2 = js["player"]["file"]
300
+            else:
301
+                raise Exception("No stram found")
302
+            if "youtube" in data2:
303
+                video_id = re.search(r"/watch\?v=([^&]+)",data2).group(1)
304
+                data2 = YouTubeVideoUrl().extract(video_id)
305
+                if not data2:
306
+                    raise Exception("No stream found %s"%data)
307
+
308
+        stream = util.item()
309
+        stream["name"] = title
310
+        stream["url"] = data2
311
+        stream["img"] = img
312
+        stream["desc"] = desc
313
+        stream["resolver"] = "replay"
314
+        return [stream]
300 315
 
301 316
     def is_video(self,data):
302 317
         if "::" in data:

+ 24
- 1
util.py Целия файл

@@ -21,7 +21,7 @@
21 21
 # */
22 22
 import os, sys, re
23 23
 import urllib, urllib2
24
-import datetime
24
+import datetime, time
25 25
 import traceback
26 26
 import cookielib
27 27
 import requests
@@ -337,6 +337,21 @@ def ttaf2srt(s):
337 337
         out += "%s\n%s --> %s\n%s\n\n"%(i,begin,end,txt2)
338 338
     return out
339 339
 
340
+def vtt2srt(s):
341
+    out = ""
342
+    i = 0
343
+    # result = re.findall(r"([\d:\. ]+-->[\d:\. ]+)\n(.+?\n)+", r.content)
344
+    for t1, t2, txt in re.findall(r"([\d:\.]+)\s*-->\s*([\d:\.]+)\n(.+?\n)+", s):
345
+        i +=1
346
+        if len(t1.split(":")) == 2:
347
+            t1 = "00:" + t1
348
+        t1 = t1.replace(".", ",")
349
+        if len(t2.split(":")) == 2:
350
+            t2 = "00:" + t2
351
+        t2 = t2.replace(".", ",")
352
+        out += "%s\n%s --> %s\n%s\n\n"%(i,t1,t2,txt)
353
+    return out
354
+
340 355
 
341 356
 def item():
342 357
     """Default item content"""
@@ -653,11 +668,19 @@ def extract_jwplayer_setup(data):
653 668
         #return demjson.decode(data.group(1).decode('string_escape')) ### III
654 669
     return None
655 670
 
671
+def datetime_from_utc_to_local(utc_datetime):
672
+    now_timestamp = time.time()
673
+    offset = datetime.datetime.fromtimestamp(now_timestamp) - datetime.datetime.utcfromtimestamp(now_timestamp)
674
+    return utc_datetime + offset
656 675
 
657 676
 #def parse_html(url):
658 677
 #    return BeautifulSoup(request(url), 'html5lib', from_encoding='utf-8')
659 678
 
660 679
 if __name__ == "__main__":
680
+    s = open("The LEGO Ninjago Movie (2017).lv.vtt").read()
681
+    s2 = vtt2srt(s)
682
+    open("The LEGO Ninjago Movie (2017).lv.srt", "w").write(s2)
683
+
661 684
     s = 'B\xc4\x93thovena D\xc4\x81rgumu Taka (2014)/Beethoven&#x27;s Treasure [LV]'
662 685
     #s = s.decode("utf8")
663 686
     #s=unescape(s)