我对编码还很陌生,我正在开发一个控制台应用程序,该应用程序从用户那里获取关于歌曲名,歌手和专辑的输入。我正在尝试使其从用户处获取的信息进行搜索,然后下载出现在Google图片上的第一张图片!然后,它会在google中搜索这些结果,提取第一个图像,然后将其添加到mp3文件中(我可能会添加一些功能,在该功能中它会自动从选定目录中读取文件并读取名称,然后吐出专辑封面:) )如果不清楚,我可以在需要时进一步说明,非常感谢您的宝贵时间,如果您对我的代码有任何建议,请参加!

我的代码:

package j1media.main;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Scanner;

public class Core {
    public static void main(String[] args) throws IOException {
        String songName;
        String songArtist;
        String songAlbum;
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter the name of the song you'd like a cover to Add a + for a space: ");
        songName = input.nextLine();
        System.out.println("Song name " + songName + " recorded, please enter the artist: ");
        songArtist = input.nextLine();
        System.out.println(songName + " by " + songArtist + " has been recorded, please enter the album(Type Y for n/a): ");
        songAlbum = input.nextLine();
        URL website = new URL("https://www.bing.com/images/search?q=" + songName + "+by+" + songArtist + "&FORM=HDRSC2");
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());
        FileOutputStream getImage = new FileOutputStream(songName + "art");
        getImage.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    }
}

最佳答案

您的问题对这个网站来说太广泛了。

但是这里有一些指向可能解决方案的指针:


使用regular expression在响应中查找IMG标签。
解析HTML响应,然后遍历节点树并查找IMG节点。

10-05 21:27
查看更多