2012年10月5日 星期五

Download Youtube Video (2012 09)

Since fucking Google/Youtube change the get_video_info again, it add a new parameter "signature", and it cause the old method not work anymore,

now here is the solution.


package vimeok.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import android.util.Log;


public class VideoParser {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

List<VideoInfoObj> videoList= getVideoList("jd2-Nf86jvA");
for(VideoInfoObj vo: videoList){

System.err.println(vo.getVideoType());
System.err.println(vo.getDwName());
System.err.println(vo.getUrl());

File f=new File(vo.getDwName());
       try {
org.apache.commons.io.FileUtils.copyURLToFile(new URL(vo.getUrl()),f);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
public static List<VideoInfoObj> getVideoList(String vid){
String[] fmt_str = new String[103];
fmt_str[0]  = "(FLV, 320 x 240, Mono 22KHz MP3)"; // delete ?
fmt_str[5]  = "(FLV, 400 x 240, Mono 44KHz MP3)";
fmt_str[6]  = "(FLV, 480 x 360, Mono 44KHz MP3)"; // delete ?
fmt_str[34] = "(FLV, 640 x 360, Stereo 44KHz AAC)";
fmt_str[35] = "(FLV, 854 x 480, Stereo 44KHz AAC)";

fmt_str[13] = "(3GP, 176 x 144, Stereo 8KHz)";    // delete ?
fmt_str[17] = "(3GP, 176 x 144, Stereo 44KHz AAC)";
fmt_str[36] = "(3GP, 320 x 240, Stereo 44KHz AAC)";

fmt_str[18] = "(MP4(H.264), 640 x 360, Stereo 44KHz AAC)";
fmt_str[22] = "(MP4(H.264), 1280 x 720, Stereo 44KHz AAC)";
fmt_str[37] = "(MP4(H.264), 1920 x 1080, Stereo 44KHz AAC)";
fmt_str[38] = "(MP4(H.264), 4096 x 3072, Stereo 44KHz AAC)";
fmt_str[83] = "(MP4(H.264), 854 x 240, Stereo 44KHz AAC)";
fmt_str[82] = "(MP4(H.264), 640 x 360, Stereo 44KHz AAC)";
fmt_str[85] = "(MP4(H.264), 1920 x 520, Stereo 44KHz AAC)";
fmt_str[84] = "(MP4(H.264), 1280 x 720, Stereo 44KHz AAC)";

fmt_str[43] = "(WebM(VP8), 640 x 360, Stereo 44KHz Vorbis)";
fmt_str[44] = "(WebM(VP8), 854 x 480, Stereo 44KHz Vorbis)";
fmt_str[45] = "(WebM(VP8), 1280 x 720, Stereo 44KHz Vorbis)";
fmt_str[100] = "(WebM(VP8), 640 x 360, Stereo 44KHz Vorbis)";
fmt_str[101] = "(WebM(VP8), 854 x 480, Stereo 44KHz Vorbis)";
fmt_str[46] = "(WebM(VP8), 1920 x 540, Stereo 44KHz Vorbis)";
fmt_str[102] = "(WebM(VP8), 1280 x 720, Stereo 44KHz Vorbis)";

String[] ft_str = new String[103];
ft_str[0]  = "flv";//"(FLV, 320 x 240, Mono 22KHz MP3)";
ft_str[5]  = "flv";//"(FLV, 400 x 240, Mono 44KHz MP3)";
ft_str[6]  = "flv";//"(FLV, 480 x 360, Mono 44KHz MP3)";
ft_str[34] = "flv";//"(FLV, 640 x 360, Stereo 44KHz AAC)";
ft_str[35] = "flv";//"(FLV, 854 x 480, Stereo 44KHz AAC)";

ft_str[13] = "3gp";//"(3GP, 176 x 144, Stereo 8KHz)";    // delete ?
ft_str[17] = "3gp";//"(3GP, 176 x 144, Stereo 44KHz AAC)";
ft_str[36] = "3gp";//"(3GP, 320 x 240, Stereo 44KHz AAC)";

ft_str[18] = "mp4";//"(MP4(H.264), 640 x 360, Stereo 44KHz AAC)";
ft_str[22] = "mp4";//"(MP4(H.264), 1280 x 720, Stereo 44KHz AAC)";
ft_str[37] = "mp4";//"(MP4(H.264), 1920 x 1080, Stereo 44KHz AAC)";
ft_str[38] = "mp4";//"(MP4(H.264), 4096 x 3072, Stereo 44KHz AAC)";
ft_str[83] = "mp4";//"(MP4(H.264), 854 x 240, Stereo 44KHz AAC)";
ft_str[82] = "mp4";//"(MP4(H.264), 640 x 360, Stereo 44KHz AAC)";
ft_str[85] = "mp4";//"(MP4(H.264), 1920 x 520, Stereo 44KHz AAC)";
ft_str[84] = "mp4";//"(MP4(H.264), 1280 x 720, Stereo 44KHz AAC)";

ft_str[43] = "webm";//"(WebM(VP8), 640 x 360, Stereo 44KHz Vorbis)";
ft_str[44] = "webm";//"(WebM(VP8), 854 x 480, Stereo 44KHz Vorbis)";
ft_str[45] = "webm";//"(WebM(VP8), 1280 x 720, Stereo 44KHz Vorbis)";
ft_str[100] = "webm";//"(WebM(VP8), 640 x 360, Stereo 44KHz Vorbis)";
ft_str[101] = "webm";//"(WebM(VP8), 854 x 480, Stereo 44KHz Vorbis)";
ft_str[46] = "webm";//"(WebM(VP8), 1920 x 540, Stereo 44KHz Vorbis)";
ft_str[102] = "webm";//"(WebM(VP8), 1280 x 720, Stereo 44KHz Vorbis)";

List<VideoInfoObj> list=new ArrayList<VideoInfoObj>();
try{
int succ = 0;
//String vid="jd2-Nf86jvA";
String url="http://www.youtube.com/get_video_info?video_id="+vid;//+"&eurl=http://10.1.2.104";
//String rdata= org.apache.commons.io.FileUtils.readFileToString(new File("d:\\get_video_info.php"));
String rdata=getMessageFromUrl(url);
Log.w("***************************",rdata);
URLDecoder dec = new URLDecoder();
//String tmp_result = java.net.URLDecoder.decode(content, "UTF-8");
String[] rdataArray = rdata.split("&");

for(int i=0; i< rdataArray.length; i++){
if(rdataArray[i].length()>26){
String r0 = rdataArray[i].substring(0, 26);
if(r0.equals("url_encoded_fmt_stream_map")){
     String r1 = dec.decode(rdataArray[i].substring(27),"UTF-8");
     String[] temp1 = r1.split(",");
     ArrayList<Integer> fmt = new ArrayList<Integer>();
     ArrayList fmt_url = new ArrayList();
     ArrayList fmt_sig = new ArrayList();
     for(int j = 0; j < temp1.length; j++){
     String[] temp2 = temp1[j].split("&");
     for(int jj = 0; jj < temp2.length; jj++){
     Integer temp_itag = -1;
             String temp_type = "";
             System.err.println(temp2[jj]);
             if(temp2[jj].substring(0, 5).equals("itag=")){
               temp_itag = new Integer(Integer.parseInt(temp2[jj].substring(5), 10));
               fmt.add(temp_itag);
             }else if(temp2[jj].substring(0, 4).equals("url=")){
               fmt_url.add(temp2[jj].substring(4));
             }else if(temp2[jj].substring(0, 4).equals("sig=")){
               fmt_sig.add(temp2[jj].substring(4));
             }else if(temp2[jj].substring(0, 5).equals("type=")){
               temp_type = '(' + dec.decode(temp2[jj].substring(5),"UTF-8") + ')';
             }
             System.err.println("temp_itag="+temp_itag);
             System.err.println(fmt_str[44]);
             if(temp_itag>-1){
             if(fmt_str[temp_itag].equals("undefined")){
               fmt_str[temp_itag] = temp_type;
             }
             }
         }
     }
     String dllinks = "";
     String webmlinks = "";
     System.err.println("fmt.size()="+fmt.size());
     for(int k=0; k< fmt.size(); k++){
     System.err.println(k);
       if(fmt.get(k) == 43 || fmt.get(k) == 44 || fmt.get(k) == 45 || fmt.get(k) == 46 || fmt.get(k) == 100 || fmt.get(k) == 101 || fmt.get(k) == 102){
//          if(webmlinks.length() > 0){
//            webmlinks += "<br />";
//          }        
         //webmlinks += "<a href=" + dec.decode(fmt_url.get(k).toString(),"UTF-8") + "&signature=" + fmt_sig.get(k) + " target=_blank><b>Watch online&nbsp;&nbsp;&nbsp;" + fmt_str[fmt.get(k)]+ "</b></a>";
         //System.err.println("webmlinks="+webmlinks);
       }else{
//          if(dllinks.length() > 0){
//            dllinks += "<br />";
//          }
        // dllinks += "<a href=" + dec.decode(fmt_url.get(k).toString(),"UTF-8") + "&signature=" + fmt_sig.get(k) + " target=_blank><b>Download&nbsp;&nbsp;&nbsp;" + fmt_str[fmt.get(k)] + "</b></a>";
        Log.w("***************",dec.decode(fmt_url.get(k).toString(),"UTF-8") + "&signature=" + fmt_sig.get(k));
        //I just need mp4 file
         if(fmt.get(k) ==18 ||fmt.get(k) ==22 ||fmt.get(k) ==37 ||fmt.get(k) ==38 ||fmt.get(k) ==82 ||fmt.get(k) ==83  ||fmt.get(k) ==84  ||fmt.get(k) ==85 ){
         String dl=dec.decode(fmt_url.get(k).toString(),"UTF-8") + "&signature=" + fmt_sig.get(k);
         String fileName="d:\\video"+System.currentTimeMillis()+"."+ft_str[fmt.get(k)];
//          File f=new File(fileName);
//          org.apache.commons.io.FileUtils.copyURLToFile(new URL(dl),f);
//          System.err.println("dllinks="+dl);
         VideoInfoObj vi= new VideoInfoObj();
         vi.setDwName(fileName);
         vi.setUrl(dl);
         vi.setVideoType(fmt_str[fmt.get(k)]);
         list.add(vi);
         }
       }
     }
     System.err.println(r1);
}
//System.err.println(r0);
}
}


}catch(Exception e){
e.printStackTrace();
}
return list;
}
public static String getMessageFromUrl(String msgUrl) throws IOException {
URL url = new URL(msgUrl);
BufferedReader in = new BufferedReader(new InputStreamReader(
url.openStream()));
String inputLine;
StringBuffer sb = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
in.close();
return sb.toString();
}

}

public class VideoInfoObj{
private String url="";
private String dwName="";
private String videoType="";
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDwName() {
return dwName;
}
public void setDwName(String dwName) {
this.dwName = dwName;
}
public String getVideoType() {
return videoType;
}
public void setVideoType(String videoType) {
this.videoType = videoType;
}
}

2012年8月7日 星期二

修改過 Mobclix 的結果.


經過調整 Mobclix 裡的廣告商後, 果然馬上就有點效果, 雖然離高峰時每天超過100美金的還差很多, 再繼續努力吧.



DayTotal Earnings

2012年8月4日 星期六

調整 Mobclix

剛剛調整了一下 Mobclix 的廣告, 把一些收入太低/無效的廣告商去掉, 
只留下了
AdTini
inmobi
mdotm
mojiva
saymedia
smatto


Mdotm     21,589 $0.51 283 1.31% $0.04 $10.97
Smaato       2,583         $1.92 12 0.47% $0.41 $4.96
Mojiva       7,933 $0.33 84 1.06% $0.03 $2.60
AdTini     29,634 $0.40 200 0.68% $0.06 $11.83
Jumptap       1,339 $0.31 12 0.90% $0.03 $0.42
InMobi       2,618 $0.15 25 0.96% $0.02 $0.39
Zestadz          333  $0.45 6 1.80% $0.03 $0.15
Tapsense     2,085         $0.04 8 0.38% $0.01 $0.08
Lifestreet  524          $0.13 25 4.77% $0.00 $0.07
Saymedia  129          $0.37 0 0.00% $0.00 $0.05
Yoc                    34          $0.53 1 2.94% $0.02 $0.02
AdTiniplus      3          $3.27 0 0.00% $0.00 $0.01
AdFonic          452          $0.00 3 0.66% $0.00 $0.00
Radium              12 $0.00 0 0.00% $0.00 $0.00
Vdopia              7          $0.00 0 0.00% $0.00 $0.00

再觀察一星期再做調整

2012年7月27日 星期五

How to play sound file in Objective C


NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:@"t5"  ofType:@"wav"];
    NSError *error;
    
    AVAudioPlayer  player=  [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:&error];
    
    [player setDelegate:self];
    
    [player prepareToPlay];
    
    [player play];

2012年7月25日 星期三

LeadBolt mobile advertising

Recently I try to use this mobile advertising networks, good CPM.

it provide banner ad, ad wall, notification ad, short ad in one sdk.

but it just work on English language country/area.

http://leadbolt.com/developers_signup.php?ref=10027093

Android app --- Call to SpongeBob

My First Semi-Game app "Call to SpongeBob"


It turn your mobile phone into a child's toy phone, they can use this app to call SpongeBob, Patrick, Squidward, Krabs, Plankton and Sandy.

Like a toy phone, it provide beautiful key tone for your children,
Piano tones, and amazing Bird tones.

* this is just a game, don't worry, it will not make a real phone call.


https://play.google.com/store/apps/details?id=com.vimeok.spongebob