Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
lasers
NewPipeExtractor
Commits
44c80e68
Commit
44c80e68
authored
Sep 08, 2017
by
Mauricio Colli
Browse files
Remove unnecessary error when dashMpd fails
- Also fix some failing tests
parent
97ad1a20
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java
View file @
44c80e68
...
...
@@ -4,9 +4,7 @@ import org.schabi.newpipe.extractor.*;
import
org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
;
import
org.schabi.newpipe.extractor.exceptions.ExtractionException
;
import
org.schabi.newpipe.extractor.utils.DashMpdParser
;
import
org.schabi.newpipe.extractor.utils.Utils
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -144,26 +142,28 @@ public class StreamInfo extends Info {
if
(
streamInfo
.
video_only_streams
==
null
)
streamInfo
.
video_only_streams
=
new
ArrayList
<>();
if
(
streamInfo
.
audio_streams
==
null
)
streamInfo
.
audio_streams
=
new
ArrayList
<>();
Exception
dashMpdError
=
null
;
if
(
streamInfo
.
dashMpdUrl
!=
null
&&
!
streamInfo
.
dashMpdUrl
.
isEmpty
())
{
try
{
DashMpdParser
.
getStreams
(
streamInfo
);
}
catch
(
Exception
e
)
{
// Sometimes we receive 403 (forbidden) error when trying to download the manifest,
// (similar to https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L1888)
// just skip the exception, as we later check if we have any streams
if
(!
Utils
.
hasCauseThrowable
(
e
,
FileNotFoundException
.
class
))
{
streamInfo
.
addException
(
new
ExtractionException
(
"Couldn't get streams from dash mpd"
,
e
));
}
// Sometimes we receive 403 (forbidden) error when trying to download the manifest (similar to what happens with youtube-dl),
// just skip the exception (but store it somewhere), as we later check if we have streams anyway.
dashMpdError
=
e
;
}
}
// either dash_mpd audio_only or video has to be available, otherwise we didn't get a stream,
// and therefore failed. (Since video_only_streams are just optional they don't caunt).
// Either audio or video has to be available, otherwise we didn't get a stream (since videoOnly are optional, they don't count).
if
((
streamInfo
.
video_streams
==
null
||
streamInfo
.
video_streams
.
isEmpty
())
&&
(
streamInfo
.
audio_streams
==
null
||
streamInfo
.
audio_streams
.
isEmpty
())
&&
(
streamInfo
.
dashMpdUrl
==
null
||
streamInfo
.
dashMpdUrl
.
isEmpty
()))
{
throw
new
StreamExtractException
(
"Could not get any stream. See error variable to get further details."
);
&&
(
streamInfo
.
audio_streams
==
null
||
streamInfo
.
audio_streams
.
isEmpty
()))
{
if
(
dashMpdError
!=
null
)
{
// If we don't have any video or audio and the dashMpd 'errored', add it to the error list
// (it's optional and it don't get added automatically, but it's good to have some additional error context)
streamInfo
.
addException
(
dashMpdError
);
}
throw
new
StreamExtractException
(
"Could not get any stream. See error variable to get further details."
);
}
return
streamInfo
;
...
...
src/main/java/org/schabi/newpipe/extractor/utils/Utils.java
View file @
44c80e68
...
...
@@ -20,31 +20,6 @@ public class Utils {
return
toRemove
.
replaceAll
(
"\\D+"
,
""
);
}
/**
* Check if throwable have the cause
*/
public
static
boolean
hasCauseThrowable
(
Throwable
throwable
,
Class
<?>...
causesToCheck
)
{
// Check if getCause is not the same as cause (the getCause is already the root),
// as it will cause a infinite loop if it is
Throwable
cause
,
getCause
=
throwable
;
for
(
Class
<?>
causesEl
:
causesToCheck
)
{
if
(
throwable
.
getClass
().
isAssignableFrom
(
causesEl
))
{
return
true
;
}
}
while
((
cause
=
throwable
.
getCause
())
!=
null
&&
getCause
!=
cause
)
{
getCause
=
cause
;
for
(
Class
<?>
causesEl
:
causesToCheck
)
{
if
(
cause
.
getClass
().
isAssignableFrom
(
causesEl
))
{
return
true
;
}
}
}
return
false
;
}
/**
* Check if the url matches the pattern.
*
...
...
src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java
View file @
44c80e68
...
...
@@ -32,17 +32,17 @@ public class SoundcloudChannelExtractorTest {
@Test
public
void
testGetName
()
throws
Exception
{
assertEquals
(
extractor
.
getName
()
,
"LIL UZI VERT"
);
assertEquals
(
"LIL UZI VERT"
,
extractor
.
getName
());
}
@Test
public
void
testGetDescription
()
throws
Exception
{
assert
Equals
(
extractor
.
getDescription
()
,
""
);
assert
True
(
extractor
.
getDescription
()
!=
null
);
}
@Test
public
void
testGetAvatarUrl
()
throws
Exception
{
assert
Equals
(
extractor
.
getAvatarUrl
()
,
"https://a1.sndcdn.com/images/default_avatar_large.png"
);
assert
True
(
extractor
.
getAvatarUrl
()
.
contains
(
"https://"
)
);
}
@Test
...
...
src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java
View file @
44c80e68
...
...
@@ -41,7 +41,7 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public
void
testGetThumbnailUrl
()
throws
Exception
{
assert
Equals
(
extractor
.
getThumbnailUrl
(),
"https://i1.sndcdn.com/artworks-000174203688-bweu12-large.jpg"
);
assert
True
(
extractor
.
getThumbnailUrl
(),
extractor
.
getThumbnailUrl
().
contains
(
"https://"
)
);
}
@Test
...
...
@@ -56,7 +56,7 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public
void
testGetUploaderAvatarUrl
()
throws
Exception
{
assert
Equals
(
extractor
.
getUploaderAvatarUrl
(),
"https://a1.sndcdn.com/images/default_avatar_large.png"
);
assert
True
(
extractor
.
getUploaderAvatarUrl
(),
extractor
.
getUploaderAvatarUrl
().
contains
(
"https://"
)
);
}
@Test
...
...
src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java
View file @
44c80e68
...
...
@@ -77,12 +77,12 @@ public class SoundcloudStreamExtractorDefaultTest {
@Test
public
void
testGetThumbnailUrl
()
throws
ParsingException
{
assert
Equals
(
extractor
.
getThumbnailUrl
(),
"https://i1.sndcdn.com/artworks-000174195399-iw6seg-large.jpg"
);
assert
True
(
extractor
.
getThumbnailUrl
(),
extractor
.
getThumbnailUrl
().
contains
(
"https://"
)
);
}
@Test
public
void
testGetUploaderAvatarUrl
()
throws
ParsingException
{
assert
Equals
(
extractor
.
getUploaderAvatarUrl
(),
"https://a1.sndcdn.com/images/default_avatar_large.png"
);
assert
True
(
extractor
.
getUploaderAvatarUrl
(),
extractor
.
getUploaderAvatarUrl
().
contains
(
"https://"
)
);
}
@Test
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment