If I know the URL of an MP3 file, what is the easiest / fastest way to get its length, bit rate, size, etc.?
How to download only part of the ID3 tag to MP3 to get this data?
You will need to look at the ID3 tags in the mp3 file.
If you do not track the metadata you want somewhere else.
To get the track length for a file, you will need to look exactly at the ID3 metadata tag, in particular the TRCK tag frame.
To download only part of the ID3 tag, you must first download part of the ID3 header of the file.
ID3. ID3, , , , ID3. WHOLE, - .
, TRCK .
, ?
import java.io.*; import java.net.*; public class FileSizeFromURL { public static final void main(String[] args) { URL url; URLConnection conn; int size; if(args.length != 1) { System.out.println("Usage: FileSizeFromURL "); return; } try { url = new URL(args[0]); conn = url.openConnection(); size = conn.getContentLength(); if(size < 0) System.out.println("Could not determine file size."); else System.out.println(args[0] + "\nSize: " + size); conn.getInputStream().close(); } catch(Exception e) { e.printStackTrace(); } } }
/ , , ..
, HTTP HEAD. , , . , MP3, , , , , , .
ID3 , ASPI ETCO. .
ID3 MP3, ?
ID3v2 . (, ID3v2 , .) , . , , 512-1024 . , MP3- " ", ; ID3, ID3.
ID3v1 . , . , , , ID3v1, ID3v2, . , ID3v2 .
HTTP, Range. .
, , .
+ , , , . . . URL-:
Curl
ID3 MP3 .
, .
URL.
You will need to download the first few K files and use the mp3 library to decode the header and get the values.
This data is encoded in the id3 tag, so you need to download at least the part of the file that is at the beginning, so you're in luck.
Alternatively, you can look at the value of the content header in the HTTP response header to find out the length if the server tells you that it is not.
Source: https://habr.com/ru/post/1704418/More articles:Which language should be used in conjunction with MySQL? - mysqlSQL Query to find holes between min_numbers and max_number in a table - sqlHow can I create different versions of a project using the Jam make tool? - c ++Do you use AOP to manage database transactions? - javaSpit Bit - bit-manipulationRisks of hosting a public website directly on my network? - windows-xpWhat are the limitations (gotchas and) when using POI to create Excel workbooks? - javaIn the eclipse API, how to get an IFile from a file that defines an external project or workspace - eclipse-3.4.NET эквивалент методов java.util.Arrays.toString(...) в Java - javaLINQ для разных множеств - c#All Articles