Skip to content

Commit

Permalink
Minor changes (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarnobat committed Nov 6, 2016
1 parent 0112fd5 commit 7c9535e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class Yurl {
// Gets stored here: http://192.168.1.2:28017/cache/items/
private static final boolean MONGODB_ENABLED = YurlResource.MongoDbCache.ENABLED;
private static final String CHROMEDRIVER_PATH = "/home/sarnobat/github/yurl/chromedriver";
private static final String YOUTUBE_DOWNLOAD = "/home/sarnobat/bin/youtube_download";
private static final Integer ROOT_ID = 45;
public static final String YOUTUBE_DOWNLOAD = "/home/sarnobat/bin/youtube_download";
public static final Integer ROOT_ID = 45;
private static final String CYPHER_URI = "http://netgear.rohidekar.com:7474/db/data/cypher";
private static final String TARGET_DIR_PATH = "/media/sarnobat/Unsorted/Videos/";
private static final String QUEUE_FILE = "/home/sarnobat/sarnobat.git/";
Expand Down Expand Up @@ -920,7 +920,7 @@ public class Yurl {
Process p = new ProcessBuilder()
.directory(Paths.get(targetDirPath).toFile())
.command(
ImmutableList.of(YOUTUBE_DOWNLOAD,
ImmutableList.of(Yurl.YOUTUBE_DOWNLOAD,
iVideoUrl)).inheritIO().start();
p.waitFor();
if (p.exitValue() == 0) {
Expand Down
103 changes: 103 additions & 0 deletions video_download.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Map;

import javax.ws.rs.core.MediaType;

import org.apache.commons.io.IOUtils;
import org.json.JSONObject;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.json.JSONConfiguration;

public class VideoDownloadNeo4j {

private static final String YOUTUBE_DOWNLOAD = "/home/sarnobat/bin/youtube_download";
private static final Integer ROOT_ID = 45;
private static final String CYPHER_URI = "http://netgear.rohidekar.com:7474/db/data/cypher";
private static final String TARGET_DIR_PATH = "/media/sarnobat/Unsorted/Videos/";

public static void main(String[] args) {
String iVideoUrl = args[0];

try {
Process p = new ProcessBuilder()
.directory(Paths.get(TARGET_DIR_PATH).toFile())
.command(
ImmutableList.of(YOUTUBE_DOWNLOAD,
iVideoUrl)).inheritIO().start();
p.waitFor();
if (p.exitValue() == 0) {
System.out
.println("YurlWorldResource.downloadVideoInSeparateThread() - successfully downloaded "
+ iVideoUrl);
writeSuccessToDb(iVideoUrl);
} else {
System.err
.println("YurlWorldResource.downloadVideoInSeparateThread() - error downloading "
+ iVideoUrl);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void writeSuccessToDb(final String iVideoUrl)
throws IOException {
execute("start n=node(*) WHERE n.url = {url} SET n.downloaded_video = {date}",
ImmutableMap.<String, Object> of("url", iVideoUrl,
"date", new Long(System.currentTimeMillis())), true, "downloadVideo()");
System.out.println("downloadVideo() - Download recorded in database");
}

private static JSONObject execute(String iCypherQuery,
Map<String, Object> iParams, boolean doLogging, String... iCommentPrefix) {
String commentPrefix = iCommentPrefix.length > 0 ? iCommentPrefix[0] + " " : "";
if (doLogging) {
System.out.println(commentPrefix + " - \t" + iCypherQuery);
System.out.println(commentPrefix + "- \tparams - " + iParams);
}
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
Boolean.TRUE);

// POST {} to the node entry point URI
ClientResponse theResponse = Client.create(clientConfig).resource(
CYPHER_URI)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON).entity("{ }")
.post(ClientResponse.class, ImmutableMap
.<String, Object> of("query", iCypherQuery, "params",
Preconditions.checkNotNull(iParams)));
if (theResponse.getStatus() != 200) {
System.out.println(commentPrefix + "FAILED:\n\t" + iCypherQuery + "\n\tparams: "
+ iParams);
try {
throw new RuntimeException(IOUtils.toString(theResponse.getEntityInputStream()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
String theNeo4jResponse ;
try {
// Do not inline this. We need to close the stream after
// copying
theNeo4jResponse = IOUtils.toString(theResponse.getEntityInputStream());
theResponse.getEntityInputStream().close();
theResponse.close();
if (doLogging) {
System.out.println(commentPrefix + "end");
}
return new JSONObject(theNeo4jResponse);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
5 changes: 5 additions & 0 deletions videos_get_undownloaded.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl -X POST -H 'Content-type: application/json' \
'http://netgear.rohidekar.com:7474/db/data/cypher' -d '
{
"query": "START n=node(37658) MATCH n-->c WHERE HAS(c.url) AND NOT HAS(c.downloaded_video) RETURN c.url", "params":{}
}'

0 comments on commit 7c9535e

Please sign in to comment.