@@ -60,73 +60,73 @@ public String getId(String url) throws ParsingException, IllegalArgumentExceptio
6060 throw new IllegalArgumentException ("The url parameter should not be empty" );
6161 }
6262
63- String id ;
6463 String lowercaseUrl = url .toLowerCase ();
6564 if (lowercaseUrl .contains ("youtube" )) {
65+ if (lowercaseUrl .contains ("list=" )) {
66+ throw new ParsingException ("Error no suitable url: " + url );
67+ }
6668 if (url .contains ("attribution_link" )) {
6769 try {
6870 String escapedQuery = Parser .matchGroup1 ("u=(.[^&|$]*)" , url );
6971 String query = URLDecoder .decode (escapedQuery , "UTF-8" );
70- id = Parser .matchGroup1 ("v=" + ID_PATTERN , query );
72+ return Parser .matchGroup1 ("v=" + ID_PATTERN , query );
7173 } catch (UnsupportedEncodingException uee ) {
7274 throw new ParsingException ("Could not parse attribution_link" , uee );
7375 }
74- } else if (url .contains ("vnd.youtube" )) {
75- id = Parser .matchGroup1 (ID_PATTERN , url );
76- } else if (url .contains ("embed" )) {
77- id = Parser .matchGroup1 ("embed/" + ID_PATTERN , url );
78- } else if (url .contains ("googleads" )) {
76+ }
77+ if (url .contains ("vnd.youtube" )) {
78+ return Parser .matchGroup1 (ID_PATTERN , url );
79+ }
80+ if (url .contains ("embed" )) {
81+ return Parser .matchGroup1 ("embed/" + ID_PATTERN , url );
82+ }
83+ if (url .contains ("googleads" )) {
7984 throw new FoundAdException ("Error found add: " + url );
80- } else {
81- id = Parser .matchGroup1 ("[?&]v=" + ID_PATTERN , url );
8285 }
83- } else if (lowercaseUrl .contains ("youtu.be" )) {
86+ return Parser .matchGroup1 ("[?&]v=" + ID_PATTERN , url );
87+ }
88+ if (lowercaseUrl .contains ("youtu.be" )) {
89+ if (lowercaseUrl .contains ("list=" )) {
90+ throw new ParsingException ("Error no suitable url: " + url );
91+ }
8492 if (url .contains ("v=" )) {
85- id = Parser .matchGroup1 ("v=" + ID_PATTERN , url );
86- } else {
87- id = Parser .matchGroup1 ("[Yy][Oo][Uu][Tt][Uu]\\ .[Bb][Ee]/" + ID_PATTERN , url );
93+ return Parser .matchGroup1 ("v=" + ID_PATTERN , url );
8894 }
89- } else if (lowercaseUrl .contains ("hooktube" )) {
90- if (lowercaseUrl .contains ("&v=" )
95+ return Parser .matchGroup1 ("[Yy][Oo][Uu][Tt][Uu]\\ .[Bb][Ee]/" + ID_PATTERN , url );
96+ }
97+ if (lowercaseUrl .contains ("hooktube" )) {
98+ if (lowercaseUrl .contains ("&v=" )
9199 || lowercaseUrl .contains ("?v=" )) {
92- id = Parser .matchGroup1 ("[?&]v=" + ID_PATTERN , url );
93- } else if (url .contains ("/embed/" )) {
94- id = Parser .matchGroup1 ("embed/" + ID_PATTERN , url );
95- } else if (url .contains ("/v/" )) {
96- id = Parser .matchGroup1 ("v/" + ID_PATTERN , url );
97- } else if (url .contains ("/watch/" )) {
98- id = Parser .matchGroup1 ("watch/" + ID_PATTERN , url );
99- } else {
100- throw new ParsingException ("Error no suitable url: " + url );
100+ return Parser .matchGroup1 ("[?&]v=" + ID_PATTERN , url );
101+ }
102+ if (url .contains ("/embed/" )) {
103+ return Parser .matchGroup1 ("embed/" + ID_PATTERN , url );
104+ }
105+ if (url .contains ("/v/" )) {
106+ return Parser .matchGroup1 ("v/" + ID_PATTERN , url );
107+ }
108+ if (url .contains ("/watch/" )) {
109+ return Parser .matchGroup1 ("watch/" + ID_PATTERN , url );
101110 }
102- } else {
103- throw new ParsingException ("Error no suitable url: " + url );
104- }
105-
106-
107- if (!id .isEmpty ()) {
108- return id ;
109- } else {
110- throw new ParsingException ("Error could not parse url: " + url );
111111 }
112+ throw new ParsingException ("Error no suitable url: " + url );
112113 }
113114
114115 @ Override
115116 public boolean onAcceptUrl (final String url ) throws FoundAdException {
116117 final String lowercaseUrl = url .toLowerCase ();
117- if (lowercaseUrl .contains ("youtube" )
118- || lowercaseUrl .contains ("youtu.be" )
119- || lowercaseUrl .contains ("hooktube" )) {
120- // bad programming I know
121- try {
122- getId (url );
123- return true ;
124- } catch (FoundAdException fe ) {
125- throw fe ;
126- } catch (ParsingException e ) {
127- return false ;
128- }
129- } else {
118+ if (!lowercaseUrl .contains ("youtube" ) &&
119+ !lowercaseUrl .contains ("youtu.be" ) &&
120+ !lowercaseUrl .contains ("hooktube" )) {
121+ return false ;
122+ // bad programming I know <-- nice meme
123+ }
124+ try {
125+ getId (url );
126+ return true ;
127+ } catch (FoundAdException fe ) {
128+ throw fe ;
129+ } catch (ParsingException e ) {
130130 return false ;
131131 }
132132 }
0 commit comments