Author: duncan
Date: Wed Feb 28 19:58:31 2007
New Revision: 9294

Modified:
   branches/rel-1/freevo/src/util/fxdimdb.py
   branches/rel-1/freevo/src/video/videoitem.py

Log:
[ 1670296 ] Crash when fetching information from IMDB
Fixes applied for new IMDB structure
Changed videoitem to cope with new layout


Modified: branches/rel-1/freevo/src/util/fxdimdb.py
==============================================================================
--- branches/rel-1/freevo/src/util/fxdimdb.py   (original)
+++ branches/rel-1/freevo/src/util/fxdimdb.py   Wed Feb 28 19:58:31 2007
@@ -620,7 +620,7 @@
                 continue
             try:
                 infostr = infoh5.next
-                key = infostr.string.strip(':').lower()
+                key = infostr.string.strip(':').lower().replace(' ', '_')
                 nextsibling = nextsibling = infoh5.nextSibling.strip()
                 sections = info.findAll('a', { 'href' : 
re.compile('/Sections') })
                 lists = info.findAll('a', { 'href' : re.compile('/List') })
@@ -630,16 +630,15 @@
                     items = []
                     for item in sections:
                         items.append(item.string)
-                    self.info[key] = items
+                    self.info[key] = ' / '.join(items)
                 elif len(lists) > 0:
                     items = []
                     for item in lists:
                         items.append(item.string)
-                    self.info[key] = items
+                    self.info[key] = ' / '.join(items)
             except:
                 pass
 
-        print self.info
         # Find Plot Outline/Summary:
         # Normally the tag is named "Plot Outline:" - however sometimes
         # the tag is "Plot Summary:". Search for both strings.
@@ -659,30 +658,35 @@
         else:
             self.info['tagline'] = u''
 
-        self.info['genre'] = ''
-        genre=soup.find(text='Genre:').parent
-        genres = []
-        while genre.findNextSibling('a').string != 'more':
-            genres.append(genre.findNextSibling('a').string.strip())
-            genre=genre.findNextSibling('a')
-        self.info['genre'] = genres[0]
-        for i in genres[1:]:
-            self.info['genre'] += ' / ' + i
         rating = soup.find(text='User 
Rating:').findNext(text=re.compile('/10'))
         if rating:
             votes = rating.findNext('a')
             self.info['rating'] = rating.strip() + ' (' + votes.string.strip() 
+ ')'
         else:
             self.info['rating'] = ''
+
         runtime = soup.find(text='Runtime:')
         if runtime and runtime.next:
             self.info['runtime'] = runtime.next.strip()
         else:
             self.info['runtime'] = ''
+
+        # Replace special characters in the items
+        for (k,v) in self.info.items():
+            s = v.strip()
+            s = s.replace('\n',' ')
+            s = s.replace('  ',' ')
+            s = s.replace('&','&')
+            s = s.replace('<','&lt;')
+            s = s.replace('>','&gt;')
+            s = s.replace('"','&quot;')
+            self.info[k] = s
+
         if config.DEBUG:
             for (k,v) in self.info.items():
                 print 'items:', k, ':', v
             print 'id:', id, 'dvd:', dvd
+            print self.info
 
         # Add impawards.com poster URLs.
         self.impawardsimages(self.info['title'], self.info['year'])

Modified: branches/rel-1/freevo/src/video/videoitem.py
==============================================================================
--- branches/rel-1/freevo/src/video/videoitem.py        (original)
+++ branches/rel-1/freevo/src/video/videoitem.py        Wed Feb 28 19:58:31 2007
@@ -218,47 +218,38 @@
                 return aspect
             
         if key == 'runtime':
-            total = 0
-            length = 0
 
             if self.info['runtime']:
-                length = self.info['runtime']
-                # Assuming that runtime is always a string
-                # Assume that a time 1:40 is hours:minutes
-                # Not sure when a '/' is used
-                p=re.compile('([0-9]+)[:/]*([0-9]*)')
-                m=p.match(length)
-                if m:
-                    length = int(m.group(1))
-                    if m.group(2):
-                        length *= 60 + int(m.group(2))
-                else:
-                    length = 0
-                total = '%s min' % str(int(length))
+                if self.info['runtime'] != 'None':
+                    return self.info['runtime']
 
-            if length == 0:
-                if self.subitems:
-                    for s in self.subitems:
-                        if s.info['length']:
-                            length = s.info['length']
-                        if not length and hasattr(s, 'length'):
-                            length = s.length
-                        if not length:
-                            continue
-                        try:
-                            total += length
-                        except ValueError, TypeError:
-                            pass
-                    total = '%s min' % str(int(total) / 60)
+            total = ''
+            if self.subitems:
+                for s in self.subitems:
+                    if s.info['length']:
+                        length = s.info['length']
+                    if not length and hasattr(s, 'length'):
+                        length = s.length
+                    if not length:
+                        continue
+                    try:
+                        total += length
+                    except ValueError, TypeError:
+                        pass
+                total = '%s min' % str(int(total) / 60)
 
-                else:
-                    if self.info['length']:
-                        total = self.info['length']
-                    elif hasattr(self, 'length'):
-                        total = self.length
-                    if total != 'None':
-                        total = '%s min' % str(int(total) / 60)
-                    else:
+            else:
+                if self.info['length']:
+                    total = self.info['length']
+                elif hasattr(self, 'length'):
+                    total = self.length
+
+                try:
+                    total = '%s min' % str(int(total) / 60)
+                except ValueError:
+                    try:
+                        runtime = self.info['runtime']
+                    except:
                         total = ''
 
             return total

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to