16

I am trying to retrieve a videoplayback URL from a YouTube link. I know this can be done with youtube-dl (youtube-dl --get-url http://www.youtube.com/watch?v=VIDEO_ID).

youtube-dl is written in Python and I know that it is somehow possible to bridge between Python and Java using Jython or Python-for-Android Py4A. But my question is how am I going to achieve this? Is there some relatively easy way to bridge between these two languages like it is between C and Java through JNI?

M--
  • 20,766
  • 7
  • 52
  • 87
sn0ep
  • 3,759
  • 8
  • 36
  • 60

1 Answers1

2

Python can be called from within many popular programming languages. Here is how I would do it in java.

Process py = Runtime.getRuntime().exec("youtube-dl.py");

Another good option is Jython. It is a library for Java that may give you a little more control over what you are doing. Good for if you do plan on making it a whole application as opposed to a small script.

This source shows three ways of executing python code in java

EDIT: Realized you noted Jython in your question but I will leave the source in for others.

King Popsicle
  • 475
  • 5
  • 17