Author: duncan
Date: Sun May 20 13:03:18 2007
New Revision: 9589

Modified:
   branches/rel-1/freevo/freevo_config.py
   branches/rel-1/freevo/src/helpers/rssserver.py
   branches/rel-1/freevo/src/rssfeed.py
   branches/rel-1/freevo/src/rssperiodic.py

Log:
[ 1721637 ] rss file extension problems
Several fixes applied and changes made.
Several fixes applied and changes made.
Logging to the log instead of stdout, stderr
Using kaa.metadata to determine the correct media type
Fixed the date when 31 Apr is given
downloads the feed to a temporay directory


Modified: branches/rel-1/freevo/freevo_config.py
==============================================================================
--- branches/rel-1/freevo/freevo_config.py      (original)
+++ branches/rel-1/freevo/freevo_config.py      Sun May 20 13:03:18 2007
@@ -270,6 +270,7 @@
      Added MAJOR_AUDIO_CTRL_MUTE to be able to choose a differente control for 
mute in the Alsa mixer plugin
      Changed default locale from latin-1 to iso-8859-15, they are really the 
same
      Added MPLAYER_OLDTVCHANNELCHANGE to allow the PREV_CH button to swap to 
previous channel
+     Added RSS_DOWNLOAD for a place to save downloaded data
      ''' ),
 ]
 
@@ -1862,8 +1863,9 @@
 
 RSS_CHECK_INTERVAL = 3600
 RSS_FEEDS = '/etc/freevo/rss.feeds'
-RSS_VIDEO = "you must set RSS_VIDEO in your local_conf.py"
-RSS_AUDIO = "you must set RSS_AUDIO in your local_conf.py"
+RSS_DOWNLOAD = '/tmp'
+RSS_VIDEO = 'you must set RSS_VIDEO in your local_conf.py'
+RSS_AUDIO = 'you must set RSS_AUDIO in your local_conf.py'
 
 # ======================================================================
 # Internal stuff, you shouldn't change anything here unless you know

Modified: branches/rel-1/freevo/src/helpers/rssserver.py
==============================================================================
--- branches/rel-1/freevo/src/helpers/rssserver.py      (original)
+++ branches/rel-1/freevo/src/helpers/rssserver.py      Sun May 20 13:03:18 2007
@@ -81,20 +81,10 @@
     print 'usage freevo rssserver [ start | stop ]'
     sys.exit(0)
 
-'''
-# No debugging in this module
-DEBUG = hasattr(config, appconf+'_DEBUG') and eval('config.'+appconf+'_DEBUG') 
or config.DEBUG
 
 logfile = '%s/%s-%s.log' % (config.LOGDIR, appname, os.getuid())
 log.startLogging(open(logfile, 'a'))
 
-def _debug_(text, level=1):
-    if DEBUG >= level:
-        try:
-            log.debug(String(text))
-        except:
-           print String(text)
-'''
 # check for expired files and delete them
 to = threading.Thread(rssperiodic.checkForExpiration())
 to.start()
@@ -105,4 +95,10 @@
     t = threading.Thread(rssperiodic.checkForUpdates())
     t.start()
     t.join()
-    time.sleep(config.RSS_CHECK_INTERVAL)
+    try:
+        time.sleep(config.RSS_CHECK_INTERVAL)
+    except KeyboardInterrupt:
+        print 'Goodbye'
+        break
+    except Exception, e:
+        print e

Modified: branches/rel-1/freevo/src/rssfeed.py
==============================================================================
--- branches/rel-1/freevo/src/rssfeed.py        (original)
+++ branches/rel-1/freevo/src/rssfeed.py        Sun May 20 13:03:18 2007
@@ -54,7 +54,7 @@
         itemPattern = re.compile('<item>.*?</item>',re.DOTALL)
         titlePattern = re.compile('<title>.*?</title>',re.DOTALL)
         descriptionPattern = 
re.compile('<description>.*?</description>',re.DOTALL)
-        urlPattern = re.compile('url=".*?.mp4',re.DOTALL)
+        urlPattern = re.compile('url=".*?.mp.',re.DOTALL)
         httpPattern = re.compile('http',re.DOTALL )
         btPattern = re.compile('<link>.*?</link>',re.DOTALL)
         datePattern = re.compile('<pubDate>.*?</pubDate>',re.DOTALL)

Modified: branches/rel-1/freevo/src/rssperiodic.py
==============================================================================
--- branches/rel-1/freevo/src/rssperiodic.py    (original)
+++ branches/rel-1/freevo/src/rssperiodic.py    Sun May 20 13:03:18 2007
@@ -28,10 +28,23 @@
 #
 # -----------------------------------------------------------------------
 
-import re,os,glob,urllib,datetime,time
+import re,os,sys,glob,urllib,datetime,time,shutil
+from subprocess import Popen
 import cPickle, pickle
 import config
 import rssfeed
+import kaa.metadata as metadata
+
+appname = os.path.splitext(os.path.basename(sys.argv[0]))[0]
+appconf = appname.upper()
+DEBUG = hasattr(config, appconf+'_DEBUG') and eval('config.'+appconf+'_DEBUG') 
or config.DEBUG
+
+def _debug_(text, level=1):
+    if DEBUG >= level:
+        try:
+            log.debug(str(text))
+        except:
+           print str(text)
 
 def convertDate(string):
     if not re.search("\d+\s+\S+\s+\d+",string):
@@ -63,7 +76,15 @@
     else:
         month=12
     year=int(itemDateList[2])
-    itemDate = datetime.date(year,month,day)
+    try:
+        itemDate = datetime.date(year,month,day)
+    except ValueError:
+        '''There is some incorrect data out there, ie. 31 Apr 2006'''
+        newmonth = month + 1
+        year += month / 12
+        month = (month+1) % 12
+        day = 1
+        itemDate = datetime.date(year,month,day)+datetime.timedelta(-1)
     return itemDate
 
 def checkForDup(string):
@@ -143,11 +164,11 @@
             try:
                 os.remove(config.RSS_VIDEO+fxdfile)
             except OSError:
-                print"removing the file %s failed" % (fxdfile)
+                _debug_("removing the file %s failed" % (fxdfile))
             try:
                 os.remove(config.RSS_VIDEO+filename)
             except OSError:
-                print"removing the file %s failed" % (filename)
+                _debug_("removing the file %s failed" % (filename))
     for line in deletedItems:
 #      try:
         downloadedFiles.remove(line)
@@ -158,23 +179,15 @@
     except:
         pickle.dump(downloadedFiles, open(cacheFile,"w"))
 
-def createFxd(item,filename):
-    if "audio" in item.type:
-        fullFilename=config.RSS_AUDIO+filename
-    else:
-        fullFilename=config.RSS_VIDEO+filename
-    tempList=re.split("\.",filename)
-    ofile=tempList[0]
-    for line in tempList[1:-1]:
-        ofile=ofile+"."+line
-    ofile=ofile+".fxd"
+def createFxd(item, filename):
+    ofile = os.path.splitext(filename)[0]+'.fxd'
     try:
         file = open(ofile, 'w')
         file.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
         file.write('<freevo>\n')
         file.write('   <movie title="%s">\n' % item.title)
         file.write('      <video>\n')
-        file.write('         <file id="f1">%s</file>\n' % fullFilename)
+        file.write('         <file id="f1">%s</file>\n' % filename)
         file.write('      </video>\n')
         file.write('      <info>\n')
         file.write('         <plot>%s</plot>\n' % item.description)
@@ -183,13 +196,14 @@
         file.write('</freevo>\n')
         file.close()
     except IOError:
-        print "ERROR: Unable to write FXD file %s" % (ofile)
+        _debug_("ERROR: Unable to write FXD file %s" % (ofile))
+    return ofile
 
 def checkForUpdates():
     try:
         file = open(config.RSS_FEEDS,"r")
     except IOError:
-        print "ERROR: Could not open configuration file %s" % 
(config.RSS_FEEDS)
+        _debug_("ERROR: Could not open configuration file %s" % 
(config.RSS_FEEDS))
         return
 
     for line in file:
@@ -201,7 +215,7 @@
             (url,numberOfDays)=re.split(";", line)
         except ValueError:
             continue
-        print "Check %s for updates" % url
+        _debug_("Check %s for updates" % url)
         try:
             sock = urllib.urlopen(url)
             feedSource = sock.read()
@@ -209,27 +223,49 @@
             for item in rssfeed.Feed(feedSource).items:
                 diff = datetime.date.today() - convertDate(item.date)
                 goodUntil = datetime.date.today() + 
datetime.timedelta(days=int(numberOfDays))
-                if int(diff.days)<=int(numberOfDays) and not 
re.search("None",item.url):
-                    if "audio" in item.type:
-                        os.chdir(config.RSS_AUDIO)
-                    else:
-                        os.chdir(config.RSS_VIDEO)
-                    filename=re.split("/",item.url).pop()
-                    if (len(glob.glob(filename))==0) and not 
checkForDup(item.url):
-                        if re.search("torrent",item.url):
-                            print "Start downloading %s" % item.url
-                            exitStatus=os.popen("bittorrent-console %s" % 
(item.url)).close()
+                if int(diff.days) <= int(numberOfDays) and not 
re.search("None",item.url):
+                    os.chdir(config.RSS_DOWNLOAD)
+                    filename = os.path.basename(item.url)
+                    _debug_('"%s" -> %s' % (item.title, filename))
+                    if len(glob.glob(filename)) == 0 and not 
checkForDup(item.url):
+                        if re.search("torrent", item.url):
+                            _debug_("Start bittorrent downloading %s" % 
item.url)
+                            cmdlog=open(os.path.join(config.LOGDIR, 
'rss-bittorrent.out'), 'a')
+                            p = Popen('bittorrent-console %s' % (item.url), 
shell=True, stderr=cmdlog, stdout=cmdlog)
+                            exitStatus = p.wait()
                             filename=re.sub("\.torrent","",filename)
                         else:
-                            print "Start downloading %s" % item.url
-                            exitStatus=os.popen("wget %s" % (item.url)).close()
-                        if not exitStatus:
-                            createFxd(item,filename)
+                            _debug_("Start wget downloading %s as %s" % 
(item.url, filename))
+                            cmdlog=open(os.path.join(config.LOGDIR, 
'rss-wget.out'), 'a')
+                            p = Popen('wget -O %s %s' % (filename, item.url), 
shell=True, stderr=cmdlog, stdout=cmdlog)
+                            exitStatus = p.wait()
+                        if exitStatus:
+                            _debug_("Download failed - exit status %s." % 
exitStatus)
+                            os.remove(filename)
+                        else:
+                            _debug_("Download completed (%s bytes)" % 
os.path.getsize(filename))
+                            meta = metadata.parse(filename)
+                            if meta.has_key('media'):
+                                if meta.media == 'MEDIA_AUDIO':
+                                    try:
+                                        fxdpath = createFxd(item, filename)
+                                        shutil.move(filename, config.RSS_AUDIO)
+                                        shutil.move(fxdpath, config.RSS_AUDIO)
+                                    except:
+                                        _debug_('failed to move %s to %s' % 
(filename, newpath))
+                                elif meta.media == 'MEDIA_VIDEO':
+                                    try:
+                                        fxdpath = createFxd(item, filename)
+                                        shutil.move(filename, config.RSS_VIDEO)
+                                        shutil.move(fxdpath, config.RSS_VIDEO)
+                                    except:
+                                        _debug_('failed to move %s to %s' % 
(filename, newpath))
+                                else:
+                                    _debug_('Cannot move %s as it media type 
is %s', (filename, meta.media))
+                                    fxdpath = createFxd(item,filename)
+                            else:
+                                _debug_('Cannot move %s as cannot determine 
its media type', (filename))
                             addFileToCache(item.url)
                             addFileToExpiration(filename,goodUntil)
-                            print "Download completed (%s bytes)" % 
os.path.getsize(filename)
-                        else:
-                            print "Download failed - exit status %s." % 
exitStatus
-                            os.popen("rm %s" % (filename))
         except IOError:
-            print "ERROR: Unable to download %s. Connection may be down." % 
(url)
+            _debug_("ERROR: Unable to download %s. Connection may be down." % 
(url))

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to