Merge lp:~jpakkane/mediascanner2/blacklist into lp:mediascanner2

Proposed by Jussi Pakkanen
Status: Merged
Approved by: James Henstridge
Approved revision: 287
Merged at revision: 292
Proposed branch: lp:~jpakkane/mediascanner2/blacklist
Merge into: lp:mediascanner2
Diff against target: 81 lines (+31/-2)
3 files modified
src/daemon/MetadataExtractor.cc (+14/-0)
test/media/playlist.m3u (+3/-0)
test/test_metadataextractor.cc (+14/-2)
To merge this branch: bzr merge lp:~jpakkane/mediascanner2/blacklist
Reviewer Review Type Date Requested Status
James Henstridge Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+239214@code.launchpad.net

Commit message

Add blacklist functionality and use it to block music playlists.

Description of the change

Add blacklist functionality and use it to block music playlists.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good

review: Approve
lp:~jpakkane/mediascanner2/blacklist updated
288. By Jussi Pakkanen

Merged trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/daemon/MetadataExtractor.cc'
2--- src/daemon/MetadataExtractor.cc 2014-10-21 22:04:14 +0000
3+++ src/daemon/MetadataExtractor.cc 2015-01-22 09:04:29 +0000
4@@ -35,6 +35,8 @@
5 #include <string>
6 #include <stdexcept>
7 #include <vector>
8+#include <array>
9+#include <algorithm>
10
11 #include <unistd.h>
12 #include <sys/types.h>
13@@ -43,6 +45,17 @@
14 using namespace std;
15
16 namespace {
17+// This list was obtained by grepping /usr/share/mime/audio/.
18+std::array<const char*, 4> blacklist{{"audio/x-iriver-pla", "audio/x-mpegurl", "audio/x-ms-asx", "audio/x-scpls"}};
19+
20+void validate_against_blacklist(const std::string &filename, const std::string &content_type) {
21+
22+ auto result = std::find(blacklist.begin(), blacklist.end(), content_type);
23+ if(result != blacklist.end()) {
24+ throw runtime_error("File " + filename + " is of blacklisted type " + content_type + ".");
25+ }
26+}
27+
28 const char exif_date_template[] = "%Y:%m:%d %H:%M:%S";
29 const char iso8601_date_format[] = "%Y-%m-%dT%H:%M:%S";
30 const char iso8601_date_with_zone_format[] = "%Y-%m-%dT%H:%M:%S%z";
31@@ -116,6 +129,7 @@
32 throw runtime_error("Could not determine content type.");
33 }
34
35+ validate_against_blacklist(filename, content_type);
36 MediaType type;
37 if (content_type.find("audio/") == 0) {
38 type = AudioMedia;
39
40=== added file 'test/media/playlist.m3u'
41--- test/media/playlist.m3u 1970-01-01 00:00:00 +0000
42+++ test/media/playlist.m3u 2015-01-22 09:04:29 +0000
43@@ -0,0 +1,3 @@
44+# This is a playlist
45+file1.mp3
46+
47
48=== modified file 'test/test_metadataextractor.cc'
49--- test/test_metadataextractor.cc 2014-10-09 11:27:18 +0000
50+++ test/test_metadataextractor.cc 2015-01-22 09:04:29 +0000
51@@ -133,8 +133,21 @@
52 EXPECT_DOUBLE_EQ(153.1727346, file.getLongitude());
53 }
54
55-// PNG files don't have exif entries, so test we work with those, too.
56+TEST_F(MetadataExtractorTest, blacklist) {
57+ MetadataExtractor e;
58+ string testfile = SOURCE_DIR "/media/playlist.m3u";
59+ try {
60+ e.detect(testfile);
61+ } catch(const std::runtime_error &e) {
62+ std::string error_message(e.what());
63+ ASSERT_NE(error_message.find("blacklist"), std::string::npos);
64+ return;
65+ }
66+ ASSERT_TRUE(false) << "Blacklist exception was not thrown.\n";
67+}
68+
69 TEST_F(MetadataExtractorTest, png_file) {
70+ // PNG files don't have exif entries, so test we work with those, too.
71 MetadataExtractor e;
72 MediaFile file = e.extract(e.detect(SOURCE_DIR "/media/image3.png"));
73
74@@ -156,7 +169,6 @@
75
76 EXPECT_DOUBLE_EQ(0, file.getLatitude());
77 EXPECT_DOUBLE_EQ(0, file.getLongitude());
78-
79 }
80
81 int main(int argc, char **argv) {

Subscribers

People subscribed via source and target branches