kopia lustrzana https://github.com/TeamNewPipe/NewPipe
implemented optimised version of YoutubeExtractor.getVideoId().
new version uses a regular expression instead of creating a HashMap and looping over them. Needs testing before pushing to originpull/82/head
rodzic
873564f2aa
commit
3411b53450
|
@ -67,8 +67,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
|
|||
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i);
|
||||
try {
|
||||
currentStreamingService = i;
|
||||
extractor = ServiceList.getService(i)
|
||||
.getExtractorInstance();
|
||||
extractor = ServiceList.getService(i).getExtractorInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -130,6 +130,26 @@ public class YoutubeExtractor implements Extractor {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVideoId(String videoUrl) {
|
||||
//https://www.youtube.com/watch?v=laF2D3QyAFQ
|
||||
String id;
|
||||
Pattern pat;
|
||||
if(videoUrl.contains("youtube")) {
|
||||
pat = Pattern.compile("youtube\\.com/watch\\?v=([a-zA-Z0-9_]{11})");
|
||||
}
|
||||
else if(videoUrl.contains("youtu.be")) {
|
||||
pat = Pattern.compile("youtu\\.be/([a-zA-Z0-9_]{11})");
|
||||
}
|
||||
else {
|
||||
Log.e(TAG, "Error could not parse url: " + videoUrl);
|
||||
return "";
|
||||
}
|
||||
Matcher mat = pat.matcher(videoUrl);
|
||||
id = mat.group(1);
|
||||
return (id == null ? "" : id);
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public String getVideoId(String videoUrl) {
|
||||
try {
|
||||
|
@ -165,7 +185,7 @@ public class YoutubeExtractor implements Extractor {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
*/
|
||||
@Override
|
||||
public String getVideoUrl(String videoId) {
|
||||
return "https://www.youtube.com/watch?v=" + videoId;
|
||||
|
|
Ładowanie…
Reference in New Issue