-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.0.28 - Added Vk video (single and albums) rippers #8
- Loading branch information
Showing
4 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/rarchives/ripme/ripper/rippers/video/VkRipper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.rarchives.ripme.ripper.rippers.video; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
|
||
import com.rarchives.ripme.ripper.VideoRipper; | ||
|
||
public class VkRipper extends VideoRipper { | ||
|
||
private static final String HOST = "vk"; | ||
private static final Logger logger = Logger.getLogger(VkRipper.class); | ||
|
||
public VkRipper(URL url) throws IOException { | ||
super(url); | ||
} | ||
|
||
@Override | ||
public String getHost() { | ||
return HOST; | ||
} | ||
|
||
@Override | ||
public boolean canRip(URL url) { | ||
Pattern p = Pattern.compile("^https?://[wm.]*vk\\.com/video[0-9]+.*$"); | ||
Matcher m = p.matcher(url.toExternalForm()); | ||
return m.matches(); | ||
} | ||
|
||
@Override | ||
public URL sanitizeURL(URL url) throws MalformedURLException { | ||
return url; | ||
} | ||
|
||
@Override | ||
public String getGID(URL url) throws MalformedURLException { | ||
Pattern p = Pattern.compile("^https?://[wm.]*vk\\.com/video([0-9]+).*$"); | ||
Matcher m = p.matcher(url.toExternalForm()); | ||
if (m.matches()) { | ||
return m.group(1); | ||
} | ||
|
||
throw new MalformedURLException( | ||
"Expected vk video URL format:" | ||
+ "vk.com/videos####" | ||
+ " Got: " + url); | ||
} | ||
|
||
@Override | ||
public void rip() throws IOException { | ||
logger.info(" Retrieving " + this.url); | ||
String videoURL = getVideoURLAtPage(this.url.toExternalForm()); | ||
addURLToDownload(new URL(videoURL), HOST + "_" + getGID(this.url)); | ||
waitForThreads(); | ||
} | ||
|
||
public static String getVideoURLAtPage(String url) throws IOException { | ||
Document doc = Jsoup.connect(url) | ||
.userAgent(USER_AGENT) | ||
.get(); | ||
String html = doc.outerHtml(); | ||
String videoURL = null; | ||
for (String quality : new String[] {"1080", "720", "480", "240"}) { | ||
quality = "url" + quality + "\\\":\\\""; | ||
if (html.contains(quality)) { | ||
videoURL = html.substring(html.indexOf(quality) + quality.length()); | ||
videoURL = videoURL.substring(0, videoURL.indexOf("\"")); | ||
videoURL = videoURL.replace("\\", ""); | ||
break; | ||
} | ||
} | ||
if (videoURL == null) { | ||
throw new IOException("Could not find video URL at " + url); | ||
} | ||
return videoURL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters