Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: windows paths #39

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/walk-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const parseKey = function(requestOptions, basedir, decrypt, resources, manifest,
if (parent) {
key.file = path.dirname(parent.file);
}
key.file = path.join(key.file, fsSanitize(path.basename(key.uri)));
key.file = path.join(key.file, path.basename(fsSanitize(key.uri)));

manifest.content = Buffer.from(manifest.content.toString().replace(
key.uri,
Expand Down Expand Up @@ -208,7 +208,7 @@ const walkPlaylist = function(options) {
const manifest = {parent};

manifest.uri = uri;
manifest.file = path.join(basedir, fsSanitize(path.basename(uri)));
manifest.file = path.join(basedir, path.basename(fsSanitize(uri)));

// if we are not the master playlist
if (dashPlaylist && parent) {
Expand All @@ -218,7 +218,7 @@ const walkPlaylist = function(options) {
manifest.file = path.join(
path.dirname(parent.file),
'manifest' + manifestIndex,
fsSanitize(path.basename(manifest.file))
path.basename(fsSanitize(manifest.file))
);
// get the real uri of this playlist
if (!isAbsolute(manifest.uri)) {
Expand Down Expand Up @@ -298,7 +298,7 @@ const walkPlaylist = function(options) {
return;
}
// put segments in manifest-name/segment-name.ts
s.file = path.join(path.dirname(manifest.file), fsSanitize(path.basename(s.uri)));
s.file = path.join(path.dirname(manifest.file), path.basename(fsSanitize(s.uri)));

if (!isAbsolute(s.uri)) {
s.uri = joinURI(path.dirname(manifest.uri), s.uri);
Expand Down
10 changes: 10 additions & 0 deletions test/resources/windows.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:8
#EXT-X-VERSION:6
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:2.000,
foo\\bar\\chunk_0.ts
#EXTINF:1.999,
foo/bar/chunk_1.ts
24 changes: 24 additions & 0 deletions test/unit/walk-manifest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ const customError = function(errors) {

describe('walk-manifest', function() {
describe('walkPlaylist', function() {
/* eslint-disable no-console */
beforeEach(function() {
this.oldError = console.error;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We log errors about duplicate segments being downloaded, but its not an issue and we should prevent it from happening.


console.error = () => {};
});
afterEach(function() {
console.error = this.oldError;
if (!nock.isDone()) {
this.test.error(new Error('Not all nock interceptors were used!'));
nock.cleanAll();
}
});
/* eslint-enable no-console */

it('should return just top level error for bad m3u8 uri', function(done) {
nock(TEST_URL)
Expand Down Expand Up @@ -85,6 +93,22 @@ describe('walk-manifest', function() {
});
});

it('should return just segments for m3u8 with windows paths', function(done) {
nock(TEST_URL)
.get('/test.m3u8')
.replyWithFile(200, `${process.cwd()}/test/resources/windows.m3u8`);

const options = {decrypt: false, basedir: '.', uri: TEST_URL + '/test.m3u8', requestRetryMaxAttempts: 0};

walker(options)
.then(function(resources) {

assert.equal(resources[1].file, 'chunk_0.ts');
assert.equal(resources[2].file, 'chunk_1.ts');
done();
});
});

it('should return correct paths for m3u8', function(done) {
nock(TEST_URL)
.get('/test/test.m3u8')
Expand Down