Permalink
Browse files

Merge pull request #15 from cancan101/master

Fixed issue with sending videos to YouTube. Also changed targetSdkVersion
  • Loading branch information...
freezy committed Dec 28, 2011
2 parents 66426d4 + f9c50a2 commit cc6f80c694506fce152f0c889b9aeaf85f53c0fe
View
@@ -72,7 +72,7 @@
<provider android:name=".business.provider.HostProvider" android:authorities="org.xbmc.android.provider.remote" />
</application>
- <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9" />
+ <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="10" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
View
@@ -1,18 +1,4 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
# Indicates whether an apk should be generated for each density.
split.density=false
-
# Project target.
-target=android-9
-
-# Enable Proguard
-#proguard.config=proguard.cfg
-
+target=android-10
@@ -29,6 +29,7 @@
import org.xbmc.android.remote.R.drawable;
import org.xbmc.android.remote.business.ManagerFactory;
import org.xbmc.android.remote.presentation.activity.MediaIntentActivity;
+import org.xbmc.android.util.YoutubeURLParser;
import org.xbmc.api.business.DataResponse;
import org.xbmc.api.business.IControlManager;
import org.xbmc.api.business.IInfoManager;
@@ -153,25 +154,18 @@ private void checkIntent(){
// The syntax for that is plugin://plugin.video.youtube/?path=/root/search%26action=play_video%26videoid=VIDEOID
Uri playuri = Uri.parse(path);
final String url;
- String message = null;
- if (playuri.getHost().endsWith("youtube.com") || playuri.getHost().endsWith("youtu.be")) {
- // We'll need to get the v= parameter from the URL and use
- // that to send to XBMC
- final Pattern pattern = Pattern.compile(".*v=([a-z0-9_\\-]+)(?:&.)*", Pattern.CASE_INSENSITIVE);
- final Matcher matcher = pattern.matcher(path);
- if (matcher.matches()) {
- url = "plugin://plugin.video.youtube/?path=/root/search&action=play_video&videoid=" + matcher.group(1);
- message = "Do you want to play\nYoutube video " + matcher.group(1) + " on XBMC? Youtube addon required!";
- } else {
- url = playuri.toString();
- }
- } else {
- // Not a youtube URL so just pass it on to XBMC as-is
+ final String message;
+ String youTubeVideoId = YoutubeURLParser.parseYoutubeURL(playuri);
+
+ if(youTubeVideoId != null){
+ url = "plugin://plugin.video.youtube/?path=/root/search&action=play_video&videoid=" + youTubeVideoId;
+ message = "Do you want to play\nYoutube video " + youTubeVideoId + " on XBMC? Youtube addon required!";
+ }else{
+ // Not a youtube URL or unparsable YouTube URL so just pass it on to XBMC as-is
url = playuri.toString();
- }
- if (message == null) {
message = "Do you want to play\n" + path + "\n on XBMC?";
- }
+ }
+
if (prefs.getBoolean(CONFIRM_PLAY_ON_XBMC, true)) {
final Builder builder = new Builder(mActivity);
builder.setTitle("Play URL on XBMC?");
@@ -29,6 +29,7 @@
import org.xbmc.android.remote.R.drawable;
import org.xbmc.android.remote.business.ManagerFactory;
import org.xbmc.android.remote.presentation.activity.UrlIntentActivity;
+import org.xbmc.android.util.YoutubeURLParser;
import org.xbmc.api.business.DataResponse;
import org.xbmc.api.business.IControlManager;
import org.xbmc.api.business.IInfoManager;
@@ -149,23 +150,15 @@ private void checkIntent(){
// The syntax for that is plugin://plugin.video.youtube/?path=/root/search%26action=play_video%26videoid=VIDEOID
Uri playuri = Uri.parse(path);
final String url;
- String message = null;
- if (playuri.getHost().endsWith("youtube.com") || playuri.getHost().endsWith("youtu.be")) {
- // We'll need to get the v= parameter from the URL and use
- // that to send to XBMC
- final Pattern pattern = Pattern.compile(".*v=([a-z0-9_\\-]+)(?:&.)*", Pattern.CASE_INSENSITIVE);
- final Matcher matcher = pattern.matcher(path);
- if (matcher.matches()) {
- url = "plugin://plugin.video.youtube/?path=/root/search&action=play_video&videoid=" + matcher.group(1);
- message = "Do you want to play\nYoutube video " + matcher.group(1) + " on XBMC? Youtube addon required!";
- } else {
- url = playuri.toString();
- }
- } else {
- // Not a youtube URL so just pass it on to XBMC as-is
+ final String message;
+ String youtubeVideoId = YoutubeURLParser.parseYoutubeURL(playuri);
+
+ if(youtubeVideoId != null){
+ url = "plugin://plugin.video.youtube/?path=/root/search&action=play_video&videoid=" + youtubeVideoId;
+ message = "Do you want to play\nYoutube video " + youtubeVideoId + " on XBMC? Youtube addon required!";
+ }else{
+ // Not a youtube URL or unparsable YouTube URL so just pass it on to XBMC as-is
url = playuri.toString();
- }
- if (message == null) {
message = "Do you want to play\n" + path + "\n on XBMC?";
}
@@ -0,0 +1,22 @@
+package org.xbmc.android.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import android.net.Uri;
+
+public class YoutubeURLParser {
+ public static String parseYoutubeURL(Uri playuri) {
+ if (playuri.getHost().endsWith("youtube.com") || playuri.getHost().endsWith("youtu.be")) {
+ // We'll need to get the v= parameter from the URL and use
+ // that to send to XBMC
+ final Pattern pattern = Pattern.compile("^http(:?s)?:\\/\\/(?:www\\.)?(?:youtube\\.com|youtu\\.be)\\/watch\\?(?=.*v=(\\w+))(?:\\S+)?$", Pattern.CASE_INSENSITIVE);
+// final Pattern pattern = Pattern.compile(".*v=([a-z0-9_\\-]+)(?:&.)*", Pattern.CASE_INSENSITIVE);
+ final Matcher matcher = pattern.matcher(playuri.toString());
+ if (matcher.matches()) {
+ return matcher.group(2);
+ }
+ }
+ return null;
+ }
+}

0 comments on commit cc6f80c

Please sign in to comment.