conduit r1317 - in trunk: . conduit/datatypes conduit/modules conduit/modules/FeedModule test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1317 - in trunk: . conduit/datatypes conduit/modules conduit/modules/FeedModule test/python-tests
- Date: Thu, 14 Feb 2008 20:48:34 +0000 (GMT)
Author: jstowers
Date: Thu Feb 14 20:48:34 2008
New Revision: 1317
URL: http://svn.gnome.org/viewvc/conduit?rev=1317&view=rev
Log:
2008-02-15 John Stowers <john stowers gmail com>
* conduit/datatypes/Audio.py:
* conduit/datatypes/Photo.py:
* conduit/datatypes/Video.py:
* conduit/modules/AudioVideoConverterModule.py:
* conduit/modules/FeedModule/FeedModule.py: Put the common mimetype testing
logic into the appropriate datatype. Fixes bug #516523
* test/python-tests/TestDataProviderFeed.py: Add an mp3 podcast feed test
Modified:
trunk/ChangeLog
trunk/conduit/datatypes/Audio.py
trunk/conduit/datatypes/Photo.py
trunk/conduit/datatypes/Video.py
trunk/conduit/modules/AudioVideoConverterModule.py
trunk/conduit/modules/FeedModule/FeedModule.py
trunk/test/python-tests/TestDataProviderFeed.py
Modified: trunk/conduit/datatypes/Audio.py
==============================================================================
--- trunk/conduit/datatypes/Audio.py (original)
+++ trunk/conduit/datatypes/Audio.py Thu Feb 14 20:48:34 2008
@@ -5,6 +5,17 @@
"ogg":{"acodec":"vorbis","format":"ogg","file_extension":"ogg"},
"wav":{"acodec":"pcm_mulaw","format":"wav","file_extension":"wav"}
}
+
+def mimetype_is_audio(mimetype):
+ """
+ @returns: True if the given mimetype string represents an audio file
+ """
+ if mimetype.startswith("audio/"):
+ return True
+ elif mimetype == "application/ogg":
+ return True
+ else:
+ return False
class Audio(File.File):
Modified: trunk/conduit/datatypes/Photo.py
==============================================================================
--- trunk/conduit/datatypes/Photo.py (original)
+++ trunk/conduit/datatypes/Photo.py Thu Feb 14 20:48:34 2008
@@ -7,6 +7,15 @@
"jpeg":{'formats':'image/jpeg','default-format':'image/jpeg'},
"png":{'formats':'image/png','default-format':'image/png'}
}
+
+def mimetype_is_photo(mimetype):
+ """
+ @returns: True if the given mimetype string represents an image file
+ """
+ if mimetype.startswith("image/"):
+ return True
+ else:
+ return False
class Photo(File.File):
"""
Modified: trunk/conduit/datatypes/Video.py
==============================================================================
--- trunk/conduit/datatypes/Video.py (original)
+++ trunk/conduit/datatypes/Video.py Thu Feb 14 20:48:34 2008
@@ -12,6 +12,17 @@
"flv":{"arate":22050,"abitrate":32,"format":"flv","acodec":"mp3","mencoder":True,"file_extension":"flv"}
}
+def mimetype_is_video(mimetype):
+ """
+ @returns: True if the given mimetype string represents a video file
+ """
+ if mimetype.startswith("video/"):
+ return True
+ elif mimetype == "application/ogg":
+ return True
+ else:
+ return False
+
class Video(File.File):
_name_ = "file/video"
Modified: trunk/conduit/modules/AudioVideoConverterModule.py
==============================================================================
--- trunk/conduit/modules/AudioVideoConverterModule.py (original)
+++ trunk/conduit/modules/AudioVideoConverterModule.py Thu Feb 14 20:48:34 2008
@@ -106,24 +106,10 @@
"file,file/audio" : self.file_to_audio
}
- def _is_video(self, f):
- mimetype = f.get_mimetype()
- if mimetype.startswith("video/"):
- return True
- elif mimetype == "application/ogg":
- return True
- else:
- log.debug("File is not video type: %s" % mimetype)
-
- def _is_audio(self, f):
- mimetype = f.get_mimetype()
- if mimetype.startswith("audio/"):
- return True
- else:
- log.debug("File is not audio type: %s" % mimetype)
-
def transcode_video(self, video, **kwargs):
- if not self._is_video(video):
+ mimetype = video.get_mimetype()
+ if not Video.mimetype_is_video(mimetype):
+ log.debug("File %s is not video type: %s" % (video,mimetype))
return None
input_file = video.get_local_uri()
@@ -181,7 +167,9 @@
return video
def transcode_audio(self, audio, **kwargs):
- if not self._is_audio(audio):
+ mimetype = audio.get_mimetype()
+ if not Audio.mimetype_is_audio(mimetype):
+ log.debug("File %s is not audio type: %s" % (audio,mimetype))
return None
input_file = audio.get_local_uri()
@@ -228,7 +216,8 @@
return audio
def file_to_audio(self, f, **kwargs):
- if self._is_audio(f):
+ mimetype = f.get_mimetype()
+ if Audio.mimetype_is_audio(mimetype):
a = Audio.Audio(
URI=f._get_text_uri()
)
@@ -241,7 +230,8 @@
return None
def file_to_video(self, f, **kwargs):
- if self._is_video(f):
+ mimetype = f.get_mimetype()
+ if Video.mimetype_is_video(mimetype):
v = Video.Video(
URI=f._get_text_uri()
)
Modified: trunk/conduit/modules/FeedModule/FeedModule.py
==============================================================================
--- trunk/conduit/modules/FeedModule/FeedModule.py (original)
+++ trunk/conduit/modules/FeedModule/FeedModule.py Thu Feb 14 20:48:34 2008
@@ -3,9 +3,7 @@
except:
from xml.etree import ElementTree
-import mimetypes
import traceback
-
import urllib2
import os
from os.path import abspath, expanduser
@@ -19,6 +17,9 @@
import conduit.dataproviders.DataProvider as DataProvider
import conduit.Exceptions as Exceptions
import conduit.datatypes.File as File
+import conduit.datatypes.Audio as Audio
+import conduit.datatypes.Video as Video
+import conduit.datatypes.Photo as Photo
MODULES = {
"RSSSource" : { "type": "dataprovider" }
@@ -34,34 +35,24 @@
_out_type_ = "file"
_icon_ = "feed"
- PHOTO_TYPES = []
- AUDIO_TYPES = []
- VIDEO_TYPES = []
-
def __init__(self, *args):
DataProvider.DataSource.__init__(self)
-
self.feedUrl = ""
self.files = {}
-
self.limit = 0
self.downloadPhotos = True
self.downloadAudio = True
self.downloadVideo = True
-
- mimetypes.init()
-
- # loop through all mime types and detect common mime types
- for m in mimetypes.types_map.values():
- if m[:6] == "image/":
- RSSSource.PHOTO_TYPES.append(m)
- elif m[:6] == "audio/":
- RSSSource.AUDIO_TYPES.append(m)
- elif m[:6] == "video/":
- RSSSource.VIDEO_TYPES.append(m)
-
- # why on gods green earth is there an application/ogg :(
- self.AUDIO_TYPES.append("application/ogg")
+
+ def _is_allowed_type(self, mimetype):
+ ok = False
+ if not ok and self.downloadPhotos:
+ ok = Photo.mimetype_is_photo(mimetype)
+ if not ok and self.downloadAudio:
+ ok = Audio.mimetype_is_audio(mimetype)
+ if not ok and self.downloadVideo:
+ ok = Video.mimetype_is_video(mimetype)
+ return ok
def initialize(self):
return True
@@ -70,8 +61,8 @@
tree = Utils.dataprovider_glade_get_widget(
__file__,
"config.glade",
- "RSSSourceConfigDialog"
- )
+ "RSSSourceConfigDialog"
+ )
#get a whole bunch of widgets
url = tree.get_widget("url")
@@ -108,16 +99,6 @@
def refresh(self):
DataProvider.DataSource.refresh(self)
-
- #Add allowed mimetypes to filter
- allowedTypes = []
- if self.downloadPhotos:
- allowedTypes += RSSSource.PHOTO_TYPES
- if self.downloadAudio:
- allowedTypes += RSSSource.AUDIO_TYPES
- if self.downloadVideo:
- allowedTypes += RSSSource.VIDEO_TYPES
-
self.files = {}
try:
url_info = urllib2.urlopen(self.feedUrl)
@@ -141,12 +122,12 @@
#Check if we have all the info
if url and t and title:
log.debug("Got enclosure %s %s (%s)" % (title,url,t))
- if t in allowedTypes:
+ if self._is_allowed_type(t):
if ((url not in allreadyInserted) and ((len(allreadyInserted) < self.limit) or (self.limit == 0))):
allreadyInserted.append(url)
self.files[url] = (title,t)
else:
- log.debug("Enclosure %s is on non-allowed type (%s)" % (title,t))
+ log.debug("Enclosure %s is an illegal type (%s)" % (title,t))
except:
log.info("Error getting/parsing feed \n%s" % traceback.format_exc())
raise Exceptions.RefreshError
@@ -161,11 +142,11 @@
f = File.File(URI=url)
f.set_UID(url)
f.set_open_URI(url)
+ name, ext = f.get_filename_and_extension()
- #create the correct extension and filename
+ #create the correct filename and retain the original extension
try:
title,t = self.files[url]
- ext = mimetypes.guess_extension(t)
f.force_new_filename(title)
f.force_new_file_extension(ext)
except:
Modified: trunk/test/python-tests/TestDataProviderFeed.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderFeed.py (original)
+++ trunk/test/python-tests/TestDataProviderFeed.py Thu Feb 14 20:48:34 2008
@@ -9,16 +9,18 @@
TESTS = (
("Photos", "http://www.flickr.com/services/feeds/photos_public gne?id=44124362632 N01&format=rss_200_enc"),
- ("Audio", "http://www.lugradio.org/episodes.ogg.rss"),
+ ("Audio (ogg)", "http://www.lugradio.org/episodes.ogg.rss"),
+ ("Audio (mp3)", "http://feeds.feedburner.com/TheLinuxLinkTechShowMp3Feed"),
("Video", "http://telemusicvision.com/videos/tmv.rss")
)
+NUM_ENCLOSURES = 5
for name,url in TESTS:
ok("%s: Url %s" % (name,url), True)
config = {
"feedUrl": url,
- "limit": 1,
+ "limit": NUM_ENCLOSURES,
"downloadPhotos": True,
"downloadAudio": True,
"downloadVideo": True
@@ -34,9 +36,9 @@
try:
enclosures = dp.get_all()
- ok("%s: Got enclosures" % name, len(enclosures) > 0)
+ ok("%s: Got %s enclosures" % (name,NUM_ENCLOSURES), len(enclosures) == NUM_ENCLOSURES)
except Exception, err:
- ok("%s: Got enclosures (%s)" % (name,err), False)
+ ok("%s: Got %s enclosures (%s)" % (name,NUM_ENCLOSURES,err), False)
try:
f = dp.get(enclosures[0])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]