我对编码相当陌生,我正在开发一个控制台应用程序,该应用程序从用户那里获取有关歌曲名、歌曲艺术家和专辑的输入。我试图让它用从用户那里获取的信息来搜索它,然后下载谷歌图像上出现的第一张图像!然后它会在 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);
}
}
最佳答案
关于java - 用java扫描网页并下载出现在上面的第一个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31765269/