Author: duncan
Date: Sun Apr 29 08:32:30 2007
New Revision: 9514

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

Log:
[ 1709515 ] FreevoRSS a couple bugs and their patch
Patch from Sami Lechner applied


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 Apr 29 08:32:30 2007
@@ -40,17 +40,18 @@
 # Download directory for audio files.
 RSS_AUDIO='/path/to/podcasts/'
 
-You will need to make a rss.feeds file: it contains the URL and the number of
-days it's been published.
+You will need to make a rss.feeds file: it contains the URL. And after the 
+semicolon the number of days it's been published and how long the copy
+should stay on the local machine before it gets deleted.
 
 # Begin /etc/freevo/rss.feeds
-http://twit.libsyn.com/rss,7
-http://leo.am/podcasts/twit,7
-http://leo.am/podcasts/itn,7
-http://feeds.feedburner.com/TechRenegades,7
-http://www.linuxactionshow.com/?feed=rss2&cat=3,30
-http://www.thelinuxlink.net/tllts/tllts.rss,30
-http://www.linux-games.ca/2006/redneck.xml,360
+http://twit.libsyn.com/rss;7
+http://leo.am/podcasts/twit;7
+http://leo.am/podcasts/itn;7
+http://feeds.feedburner.com/TechRenegades;7
+http://www.linuxactionshow.com/?feed=rss2&cat=3;30
+http://www.thelinuxlink.net/tllts/tllts.rss;30
+http://www.linux-games.ca/2006/redneck.xml;360
 # End /etc/freevo/rss.feeds
 '''
 
@@ -80,6 +81,7 @@
     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
 
@@ -91,8 +93,14 @@
         try:
             log.debug(String(text))
         except:
-            print String(text)
+           print String(text)
+'''
+# check for expired files and delete them
+to = threading.Thread(rssperiodic.checkForExpiration())
+to.start()
+to.join()
 
+# than starting server to poll podcasts
 while True:
     t = threading.Thread(rssperiodic.checkForUpdates())
     t.start()

Modified: branches/rel-1/freevo/src/rssfeed.py
==============================================================================
--- branches/rel-1/freevo/src/rssfeed.py        (original)
+++ branches/rel-1/freevo/src/rssfeed.py        Sun Apr 29 08:32:30 2007
@@ -3,7 +3,7 @@
 # rssfeed.py - This is the Freevo RSS Feed module
 # -----------------------------------------------------------------------
 # $Id$
-#
+# 
 # Notes:
 # Todo:        
 #
@@ -54,8 +54,8 @@
         itemPattern = re.compile('<item>.*?</item>',re.DOTALL)
         titlePattern = re.compile('<title>.*?</title>',re.DOTALL)
         descriptionPattern = 
re.compile('<description>.*?</description>',re.DOTALL)
-        urlPattern = re.compile('<enclosure[^>]*?url=".*?/>',re.DOTALL)
-        httpPattern = re.compile('http',re.DOTALL)
+        urlPattern = re.compile('url=".*?.mp4',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 Apr 29 08:32:30 2007
@@ -28,7 +28,7 @@
 #
 # -----------------------------------------------------------------------
 
-import re,os,glob,urllib,datetime,pickle
+import re,os,glob,urllib,datetime,pickle,time
 import config
 import rssfeed
 
@@ -89,6 +89,53 @@
     downloadedUrls.append(string)
     pickle.dump(downloadedUrls, open(cacheFile,"w"))
 
+def addFileToExpiration(string,goodUntil):
+    ''' the new file gets added with the expiration date to the expiration 
file '''
+    cacheFile=config.FREEVO_CACHEDIR+"/rss.expiration"
+    downloadedFiles=[]
+    try:
+       downloadedFiles = pickle.load(open(cacheFile,"r"))
+    except IOError:
+       pass
+    downloadedFiles.append(string + ";" + goodUntil.__str__())
+    pickle.dump(downloadedFiles, open(cacheFile,"w"))
+
+def checkForExpiration():
+    ''' checking for expired files by reading the rss.expiration file the file
+    contains the expiration date. once a file is expired it and its fxd gets
+    deleted at the end the file gets removed from the rss.expiration file '''
+    cacheFile=config.FREEVO_CACHEDIR+"/rss.expiration"
+    try:
+       downloadedFiles=pickle.load(open(cacheFile,"r"))
+    except IOError:
+       return 
+    deletedItems = []
+    for line in downloadedFiles:
+        (filename,goodUntil)=re.split(";", line)
+        expirationdate = datetime.datetime(*time.strptime(goodUntil, 
"%Y-%m-%d")[0:5])
+        diff = expirationdate - datetime.datetime.today()
+        if int(diff.days)<=0:
+            deletedItems.append(line)
+            tempList=re.split("\.",filename)
+            fxdfile=tempList[0]
+            for line in tempList[1:-1]:
+                fxdfile=fxdfile+"."+line
+            fxdfile=fxdfile+".fxd"
+            try:
+                os.remove(config.RSS_VIDEO+fxdfile)
+            except OSError:
+                print"removing the file %s failed"%(fxdfile)
+            try:
+                os.remove(config.RSS_VIDEO+filename)
+            except OSError:
+                print"removing the file %s failed"%(filename)
+    for line in deletedItems:
+#      try:
+       downloadedFiles.remove(line)
+#      except ValueError:
+#          _debug_("removing the line %s failed" % (line))
+    pickle.dump(downloadedFiles, open(cacheFile,"w"))
+
 def createFxd(item,filename):
     if "audio" in item.type:
         fullFilename=config.RSS_AUDIO+filename
@@ -128,7 +175,7 @@
         if re.search("^#",line):
             continue
         try:
-            (url,numberOfDays)=re.split(",", line)
+            (url,numberOfDays)=re.split(";", line)
         except ValueError:
             continue
         print "Check %s for updates" % url
@@ -138,6 +185,7 @@
             sock.close()
             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)
@@ -155,6 +203,7 @@
                         if not exitStatus:
                             createFxd(item,filename)
                             addFileToCache(item.url)
+                            addFileToExpiration(filename,goodUntil)
                             print "Download completed (%s bytes)" % 
os.path.getsize(filename)
                         else:
                             print "Download failed - exit status %s." % 
exitStatus

-------------------------------------------------------------------------
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