Diff of /plugin.video.elisa.viihde/addon.py [dafd62] .. [064626]  Maximize  Restore

Switch to side-by-side view

--- a/plugin.video.elisa.viihde/addon.py
+++ b/plugin.video.elisa.viihde/addon.py
@@ -204,6 +204,18 @@
 
 def get_prog_data(prog_id):
     prog_url = "http://elisaviihde.fi/etvrecorder/program.sl?programid=" + str(prog_id) + "&ajax"
+    # Limit concurrent download threads to 60
+    # It there are too many threads (depending on hardware and OS)
+    # the master Python process will stop execution and whole plugin fails.
+    #
+    # Also it seems that Elisa.fi is throttling concurrent requests from
+    # same client, so better not bombard them with over 300 requests per
+    # second anyway.
+    #
+    # Best solution would be a thread pool, but this quick hack
+    # "while sleep" solves the problem too.
+    while threading.active_count() > 60:
+        time.sleep(2)
     req = urllib2.Request(prog_url)
     response = urllib2.urlopen(req)
     link = response.read()
@@ -243,12 +255,12 @@
 
 def fix_chars(string):
     string = string.replace("%20", " ")
-    string = re.sub('%C3%A4','\u00E4',string) #ä
-    string = re.sub('%C3%B6','\u00F6',string) #ö
-    string = re.sub('%C3%A5','\u00E5',string) #ĺ
-    string = re.sub('%C3%84','\u00C4',string) #Ä
-    string = re.sub('%C3%96','\u00D6',string) #Ö
-    string = re.sub('%C3%85','\u00C5',string) #Ĺ
+    string = re.sub('%C3%A4','\u00E4',string) #\E4
+    string = re.sub('%C3%B6','\u00F6',string) #\F6
+    string = re.sub('%C3%A5','\u00E5',string) #\E5
+    string = re.sub('%C3%84','\u00C4',string) #\C4
+    string = re.sub('%C3%96','\u00D6',string) #\D6
+    string = re.sub('%C3%85','\u00C5',string) #\C5
     string = re.sub('%2C', ',',string) #pilkku
     string = re.sub('%26', '&',string) #&
     string = re.sub('%3F', '?',string) #?
@@ -305,6 +317,8 @@
         else:
             date_name = str(vkopaivat[weekday_numb]) + " " + time.strftime("%d.%m.%Y %H:%M", parsed_time)
 
+        date_string = time.strftime("%Y-%m-%d", parsed_time)
+
         name = print_star + row['name'] + " (" + row['channel'] + ", " + date_name + ")"
 
         link = add_watch_link(name,
@@ -312,7 +326,7 @@
                    playcount=row['viewcount'],
                    totalItems=totalItems,
                    duration=row['length'],
-                   date=date_name
+                   date=date_string
                    )
         t = UpdateProgramDataThread(row['program_id'],
                                 link)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks