-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/test/java=UTF-8 |
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
82 changes: 82 additions & 0 deletions
82
src/test/java/com/github/axet/vget/AppManagedDownload.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,82 @@ | ||
package com.github.axet.vget; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import com.github.axet.vget.info.VideoInfo; | ||
import com.github.axet.wget.info.DownloadInfo; | ||
import com.github.axet.wget.info.DownloadInfo.Part; | ||
import com.github.axet.wget.info.DownloadInfo.Part.States; | ||
|
||
public class AppManagedDownload { | ||
|
||
VideoInfo info; | ||
long last; | ||
|
||
public void run() { | ||
try { | ||
AtomicBoolean stop = new AtomicBoolean(false); | ||
Runnable notify = new Runnable() { | ||
@Override | ||
public void run() { | ||
VideoInfo i1 = info; | ||
DownloadInfo i2 = i1.getInfo(); | ||
|
||
// notify app or save download state | ||
// you can extract information from DownloadInfo info; | ||
switch (i1.getState()) { | ||
case EXTRACTING: | ||
case EXTRACTING_DONE: | ||
case DONE: | ||
System.out.println(i1.getState()); | ||
break; | ||
case RETRYING: | ||
System.out.println(i1.getState() + " " + i1.getDelay()); | ||
break; | ||
case DOWNLOADING: | ||
long now = System.currentTimeMillis(); | ||
if (now - 1000 > last) { | ||
last = now; | ||
|
||
String parts = ""; | ||
|
||
for (Part p : i2.getParts()) { | ||
if (p.getState().equals(States.DOWNLOADING)) { | ||
parts += String.format("Part#%d(%.2f) ", p.getNumber(), | ||
p.getCount() / (float) p.getLength()); | ||
} | ||
} | ||
|
||
System.out.println(String.format("%s %.2f %s", i1.getState(), | ||
i2.getCount() / (float) i2.getLength(), parts)); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
info = new VideoInfo(new URL("http://vimeo.com/52716355")); | ||
|
||
VGet v = new VGet(info, new File("/Users/axet/Downloads")); | ||
|
||
// optional. only if you dlike to get video title before start | ||
// download | ||
v.extract(stop, notify); | ||
System.out.println(info.getTitle()); | ||
|
||
v.download(stop, notify); | ||
} catch (RuntimeException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
AppManagedDownload e = new AppManagedDownload(); | ||
e.run(); | ||
} | ||
} |
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,17 @@ | ||
package com.github.axet.vget; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
public class DirectDownload { | ||
|
||
public static void main(String[] args) { | ||
try { | ||
VGet v = new VGet(new URL("http://www.youtube.com/watch?v=ZIPxGEaB5OM&feature=youtube_gdata"), new File("/Users/axet/Downloads")); | ||
v.download(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |