|

10精币
这是接口:https://api.amemv.com/aweme/v1/hot/search/list/?iid=44478516381&device_id=12229011297&os_api=18&app_name=aweme&channel=App%20Store&idfa=5FDF9129-D8F4-4594-96FE-6EC18AD136B9&device_platform=iphone&build_number=26006&vid=AB52ACAA-1E73-44D1-9BC2-BB1D74A6F682&openudid=282a2be914adb26833e880d38ee671e45da49829&device_type=iPhone7,2&app_version=2.6.0&version_code=2.6.0&os_version=12.0&screen_width=750&aid=1128&ac=WIFI&detail_list=0&mas=017c141ec42dace5a30cd06954fe1cbb40142e84eb9df316cf8287&as=a165392a937d1b9e756732&ts=1537580755
这个接口可以获取抖音热门内容,请问怎么用易语言做一个功能一样的
- import java.io.ByteArrayOutputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
-
- import org.apache.http.client.methods.CloseableHttpResponse;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.util.EntityUtils;
-
- import com.google.gson.Gson;
-
-
- //发送http请求,视频下载功能
- public class DouYina {
-
- ///发送http
- public static String sendGet(String url){
- String entity = null;
- try {
- //创建HttpClient
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- //创建请求方法
- HttpGet httpGet = new HttpGet(url);
-
- //设置Header模拟浏览器行为
- httpGet.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
-
-
- //发送请求,收取响应
- CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
-
- if(httpResponse.getStatusLine().getStatusCode() == 200){
- //解析响应
- entity = EntityUtils.toString(httpResponse.getEntity());
- // System.out.println(entity);
- }
-
- EntityUtils.consume(httpResponse.getEntity());
- httpResponse.close();
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- return entity;
- }
-
-
-
- public static byte[] readInputStream(InputStream inputStream) throws IOException {
- byte[] buffer = new byte[1024];
- int len = 0;
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- while ((len = inputStream.read(buffer)) != -1) {
- bos.write(buffer, 0, len);
- }
- bos.close();
- return bos.toByteArray();
- }
-
- //下载视频
- public static void downLoadFromUrl(String urlStr, String fileName, String savePath) throws IOException {
- URL url = new URL(urlStr);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setConnectTimeout(3000);
- conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
- InputStream inputStream = conn.getInputStream();
- byte[] getData = readInputStream(inputStream);
- java.io.File saveDir = new java.io.File(savePath);
- if (!saveDir.exists()) {
- saveDir.mkdir();
- }
- java.io.File file = new java.io.File(saveDir + java.io.File.separator + fileName);
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(getData);
- if (fos != null) {
- fos.close();
- }
- if (inputStream != null) {
- inputStream.close();
- }
- }
- }
复制代码
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.io.IOException;
-
- import javax.swing.ButtonGroup;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JRadioButton;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
-
- import com.google.gson.Gson;
-
-
-
-
-
- public class Douyin {
-
-
- public static void main(String[] args) {
-
- //主题
- JFrame f = new JFrame("抖音批量下载");
-
- //设置大小
- f.setSize(600, 400);
- f.setLocation(200, 200);
- f.setLayout(null);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-
- //按钮
- JButton b = new JButton("开始解析下载");
- b.setBounds(400, 30, 150, 30);
-
-
- //文字
- JLabel l = new JLabel("接口地址:");
- //l.setForeground(Color.black);
- l.setBounds(20, 20, 100, 30);
-
- //文本框
- JTextArea ta = new JTextArea("");
- ta.setBounds(80, 20, 300, 100);
- ta.setLineWrap(true);
- ta.setWrapStyleWord(true);
-
- /* //为JTextArea添加滚动条
-
- JScrollPane jsp = new JScrollPane(ta);
- jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
- jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);*/
-
-
-
- //文字
- JLabel l1 = new JLabel("保存地址:");
- //l.setForeground(Color.black);
- l1.setBounds(20, 80, 100, 130);
-
- JTextField tf = new JTextField("F:\\douyin",30);
- tf.setBounds(80, 135, 400, 25);
-
- JRadioButton jr = new JRadioButton("作品");
- jr.setSelected(false);
- jr.setBounds(420, 60, 55, 30);
-
- JRadioButton jr1 = new JRadioButton("喜欢");
- jr1.setSelected(true);
- jr1.setBounds(480, 60, 80, 30);
-
-
- JTextArea ta1 = new JTextArea("初始化.... \n",20, 43);
- ta1.setBounds(50, 180, 480, 150);
- ta1.setLineWrap(true);
- ta1.setWrapStyleWord(true);
-
- /*//为JTextArea添加滚动条
- JScrollPane jsp1 = new JScrollPane(ta1);
- jsp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
- jsp1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- f.add(jsp1);*/
-
-
- //按钮分组
- ButtonGroup bg = new ButtonGroup();
- bg.add(jr);
- bg.add(jr1);
-
- f.add(ta);
- f.add(ta1);
- f.add(jr);
- f.add(jr1);
- f.add(l);
- f.add(l1);
- f.add(tf);
- f.add(b);
-
- f.setResizable(false);
- f.setVisible(true);
-
-
-
- //按钮解析监听
- b.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
-
-
- if("".equals(ta.getText())){
- JOptionPane.showMessageDialog(f, "请输入接口地址");
- return;
- }
- if(jr.isSelected() == false && jr1.isSelected() == false){
- JOptionPane.showMessageDialog(f, "请选择你要下载的类型");
- return ;
- }
- if("".equals(tf.getText())){
- JOptionPane.showMessageDialog(f, "请输入你要保存的视频地址");
- return;
- }
- //下载操作
-
- DouYina dy = new DouYina();
- Gson g = new Gson();
-
- if(jr.isSelected() == true){
- //JOptionPane.showMessageDialog(f, "作品视频接口由于Token加密,暂时还没有办法解析出来");
- for(int i=0;i<20000;i++){
- System.out.println(i);
- }
- ta1.append("下载完成");
-
-
- return ;
- }else if(jr1.isSelected() == true){ //作品类
-
- try {
- String json = dy.sendGet(ta.getText());
- DouClass dc = g.fromJson(json, DouClass.class);
- System.out.println(dc.getAweme_list());
-
- for(AwemeList al : dc.getAweme_list()){
- Video v = al.getVideo() ;
- PlayAddr pa = v.getPlay_addr();
- System.out.println(pa.getUrl_list().get(0) );
-
- String urlStr = pa.getUrl_list().get(0) ;
-
- long imageTitile = System.currentTimeMillis();
-
- String fileName = null ;
-
- if( !"".equals(al.getDesc() )){
- fileName = al.getDesc() + "." + "mp4";
- }else{
- fileName = imageTitile + "." + "mp4";
- }
- String savePath = tf.getText();
- dy.downLoadFromUrl(urlStr, fileName, savePath);
- }
- } catch (Exception e1) {
- JOptionPane.showMessageDialog(f, "接口地址有误");
- return ;
- }
- ta1.append("下载完成 \n");
- }
-
- }
-
- });
-
-
-
-
-
-
-
-
-
- }
-
-
- }
复制代码
|
最佳答案
查看完整内容
这种需求左转定制区吧,联系我即可{:3_41:}{:3_41:}
|