[tracker/rss-enclosures] functional-tests: parse correctly playlist output from the extractor



commit 743f0bab5686c42f8c30ad5c1a5847a7632b7026
Author: Ivan Frade <ivan frade nokia com>
Date:   Thu Sep 23 18:56:31 2010 +0300

    functional-tests: parse correctly playlist output from the extractor

 tests/functional-tests/common/utils/helpers.py     |   27 ++++++++++++++++++++
 .../test-extraction-data/playlists/Makefile.am     |    9 ++++++
 .../playlists/playlist-test-1.expected             |   13 +++++++++
 .../playlists/playlist-test-1.m3u                  |    8 ++++++
 4 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 905d329..c358469 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -226,6 +226,10 @@ class ExtractorHelper ():
         mlo:location [a mlo:GeoPoint; mlo:city "Delhi"; mlo:country "India"]
                 -> mlo:location:city "Delhi"
                 -> mlo:location:country "India"
+                
+        nfo:hasMediaFileListEntry [ a nfo:MediaFileListEntry ; nfo:entryUrl "file://x.mp3"; nfo:listPosition 1]
+                -> nfo:hasMediaFileListEntry:entryUrl "file://x.mp3"
+
         """
         
         # hasTag case
@@ -271,9 +275,32 @@ class ExtractorHelper ():
             else:
                 print "Something special in this line '%s'" % (line)
 
+        elif line.startswith ("nfo:hasMediaFileListEntry"):
+            return self.__handle_playlist_entries (line)
+        
         else:
             return [line]
 
+    def __handle_playlist_entries (self, line):
+        """
+        Playlist entries come in one big line:
+        nfo:hMFLE [ a nfo:MFLE; nfo:entryUrl '...'; nfo:listPosition X] , [ ... ], [ ... ]
+          -> nfo:hMFLE:entryUrl '...'
+          -> nfo:hMFLE:entryUrl '...'
+          ...
+        """
+        geturl = re.compile ("nfo:entryUrl \"([\w\.\:\/]+)\"")
+        entries = line.strip () [len ("nfo:hasMediaFileListEntry"):]
+        results = []
+        for entry in entries.split (","):
+            url_match = geturl.search (entry)
+            if (url_match):
+                new_line = 'nfo:hasMediaFileListEntry:entryUrl "%s" ;' % (url_match.group (1))
+                results.append (new_line)
+            else:
+                print " *** Something special in this line '%s'" % (entry)
+        return results
+
     def __clean_value (self, value):
         """
         the value comes with a ';' or a '.' at the end
diff --git a/tests/functional-tests/test-extraction-data/playlists/Makefile.am b/tests/functional-tests/test-extraction-data/playlists/Makefile.am
new file mode 100644
index 0000000..2286eb0
--- /dev/null
+++ b/tests/functional-tests/test-extraction-data/playlists/Makefile.am
@@ -0,0 +1,9 @@
+include $(top_srcdir)/Makefile.decl
+
+playlisttestdir = $(datadir)/tracker-tests/test-extraction-data/playlists
+
+playlisttest_DATA =		\
+	playlist-test-1.m3u	\
+	playlist-test-1.expected
+
+EXTRA_DIST = $(playlisttest_DATA)
\ No newline at end of file
diff --git a/tests/functional-tests/test-extraction-data/playlists/playlist-test-1.expected b/tests/functional-tests/test-extraction-data/playlists/playlist-test-1.expected
new file mode 100644
index 0000000..fd822f8
--- /dev/null
+++ b/tests/functional-tests/test-extraction-data/playlists/playlist-test-1.expected
@@ -0,0 +1,13 @@
+[TestFile]
+Filename=playlist-test-1.m3u
+Bugzilla=
+Comment=Regular m3u playlist file
+
+[Metadata]
+a=nmm:Playlist
+nfo_entryCounter=5
+nfo_hasMediaFileListEntry_entryUrl=http://www.apnaradio.com/live/ApnaRadio.mp3
+nfo_hasMediaFileListEntry_entryUrl=http://live.apnaradio.com:6464
+nfo_hasMediaFileListEntry_entryUrl=http://live.apnaradio.com:2424
+nfo_hasMediaFileListEntry_entryUrl=http://www.apnaradio.com/live/MaintenanceE.mp3
+nfo_hasMediaFileListEntry_entryUrl=http://www.apnaradio.com/live/MaintenanceP.mp3
diff --git a/tests/functional-tests/test-extraction-data/playlists/playlist-test-1.m3u b/tests/functional-tests/test-extraction-data/playlists/playlist-test-1.m3u
new file mode 100755
index 0000000..6107435
--- /dev/null
+++ b/tests/functional-tests/test-extraction-data/playlists/playlist-test-1.m3u
@@ -0,0 +1,8 @@
+[playlist]
+File1=http://www.apnaradio.com/live/ApnaRadio.mp3
+File2=http://live.apnaradio.com:6464
+File3=http://live.apnaradio.com:2424
+File4=http://www.apnaradio.com/live/MaintenanceE.mp3
+File5=http://www.apnaradio.com/live/MaintenanceP.mp3
+NumberOfEntries=5
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]