Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial ("Default") profile: an easier way to override the default args

  • Loading branch information...
commit 419d2490f2a2d6b2dfcacf7746c2b36e6b6311b5 1 parent bee1108
@chocolateboy authored
View
2  README.md
@@ -1,6 +1,6 @@
# Synopsis <a name="Synopsis"></a>
-This is a plugin for [PS3 Media Server](http://code.google.com/p/ps3mediaserver/) (PMS) that adds configurable support for web video streaming via MEncoder.
+This is a plugin for [PS3 Media Server](http://code.google.com/p/ps3mediaserver/) (PMS) that adds configurable support for web video streaming.
# Prerequisites <a name="Prerequisites"></a>
View
6 TODO.groovy
@@ -9,4 +9,8 @@
format: 'html' // default if xpath is defined
)
-/* add tests for ytaccept */
+/* add tests for $YOUTUBE_ACCEPT */
+
+/* make scripts hot-swappable */
+
+/* wrap profiles in a try/catch block? */
View
1  examples/pmsencoder.conf
View
9 src/main/groovy/com/chocolatey/pmsencoder/PMSEncoder.groovy
@@ -79,7 +79,6 @@ public class Command extends Logger {
this(new Stash(map), [], [])
}
- // copy constructor (clone doesn't work in Groovy++)
public Command(Command other) {
this(new Stash(other.stash), new ArrayList<String>(other.args), new ArrayList<String>(other.matches))
}
@@ -105,7 +104,11 @@ public class Command extends Logger {
}
class Matcher extends Logger {
- private final Config config
+ // FIXME: this is only public for a (single) test
+ // 1) Config has the same scope as Matcher so they could be merged,
+ // but we don't want to expose load
+ // 2) the config "globals" (e.g. $DEFAULT_MENCODER_PATH) could be moved here
+ public final Config config
Matcher(PMS pms) {
this.config = new Config(pms)
@@ -259,7 +262,7 @@ class Profile extends Logger {
}
boolean match(Command command) {
- def newCommand = new Command(command) // clone() doesn't work with Groovy++
+ def newCommand = new Command(command)
// the pattern block has its own command object (which is initially the same as the action block's).
// if the match succeeds, then the pattern block's stash is merged into the action block's stash.
// this ensures that a partial match (i.e. a failed match) with side-effects/bindings doesn't contaminate
View
19 src/main/resources/pmsencoder.groovy
@@ -41,6 +41,25 @@ config {
5 // 240p
]
+ /*
+ this is placed here (i.e. first) as a convenience so that scripts can create/override
+ settings common to all other profiles without modifying $DEFAULT_MENCODER_ARGS e.g.
+
+ set the default audio bitrate to 348 Kbps (see default_profile.groovy test):
+
+ profile ('Default') {
+ pattern { match { true } }
+ action {
+ tr '-lavcopts': [ 'abitrate=\\d+': 'abitrate=384' ]
+ }
+ }
+ */
+
+ profile ('Default') {
+ pattern { match { false } }
+ action { }
+ }
+
profile ('YouTube') {
// extract the resource's video_id from the URI of the standard YouTube page
pattern {
View
57 src/test/groovy/CustomConfigTest.groovy
@@ -18,18 +18,43 @@ class CustomConfigTest extends PMSEncoderTestCase {
)
}
+ // confirm that the default TED profile works
+ void testProfile() {
+ /// XXX clone doesn't work
+ def TEDArgs = new ArrayList<String>(matcher.config.$DEFAULT_MENCODER_ARGS)
+ def index = TEDArgs.findIndexOf { it == '25' }
+
+ assert index > -1 // power assert!
+ TEDArgs[index] = '24'
+
+ def uri = 'http://feedproxy.google.com/~r/TEDTalks_video'
+ def command = new Command([ '$URI': uri ])
+ def wantCommand = new Command([ '$URI': uri ], TEDArgs)
+
+ assertMatch(
+ command, // supplied command
+ wantCommand, // expected command
+ [ 'TED' ], // expected matches
+ true // use default args
+ )
+ }
+
+ // now confirm that it can be overridden
void testProfileReplace() {
def customConfig = this.getClass().getResource('/profile_replace.groovy')
def uri = 'http://feedproxy.google.com/~r/TEDTalks_video'
def command = new Command([ '$URI': uri ])
- def wantCommand = new Command([ '$URI': uri + '/foo/bar.baz' ], [ '-foo', 'bar' ])
+ def TEDArgs = new ArrayList<String>(matcher.config.$DEFAULT_MENCODER_ARGS)
+ def wantArgs = (TEDArgs + [ '-foo', 'bar' ]) as List<String> // FIXME: type-inference fail (or use Scala)
+ def wantCommand = new Command([ '$URI': uri + '/foo/bar.baz' ], wantArgs)
matcher.load(customConfig)
assertMatch(
command, // supplied command
wantCommand, // expected command
- [ 'TED' ] // expected matches
+ [ 'TED' ], // expected matches
+ true // use default args
)
}
@@ -115,4 +140,32 @@ class CustomConfigTest extends PMSEncoderTestCase {
true // use default args
)
}
+
+ void testDefaultProfileOverride() {
+ def customConfig = this.getClass().getResource('/profile_default.groovy')
+ def uri = 'http://www.example.com'
+ def command = new Command([ '$URI': uri ])
+ def wantArgs = [
+ '-prefer-ipv4',
+ '-oac', 'lavc',
+ '-of', 'lavf',
+ '-lavfopts', 'format=dvd',
+ '-ovc', 'lavc',
+ // make sure nbcores is interpolated here as 3 in threads=3
+ '-lavcopts', "vcodec=mpeg2video:vbitrate=4096:threads=3:acodec=ac3:abitrate=384",
+ '-ofps', '25',
+ '-cache', '16384',
+ '-vf', 'harddup'
+ ]
+
+ def wantCommand = new Command([ '$URI': uri ], wantArgs)
+ matcher.load(customConfig)
+
+ assertMatch(
+ command, // supplied command
+ wantCommand, // expected command
+ [ 'Default' ], // expected matches
+ true // use default args
+ )
+ }
}
View
9 src/test/resources/profile_default.groovy
@@ -0,0 +1,9 @@
+config {
+ profile ('Default') {
+ pattern { match { true } }
+
+ action {
+ tr '-lavcopts': [ 'abitrate=\\d+': 'abitrate=384' ]
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.