Skip to content

Commit

Permalink
v 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wittyneko committed Jul 18, 2018
1 parent 3450ba3 commit 5855aea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 83 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
![展示](./show_01.webp)

### 功能
- [x] 缓存转换
- [x] 缓存读取转换
- [x] 记录转换历史
- [x] 写入歌曲信息
- [ ] 写入歌词
- [ ] 写入封面
- [ ] 修改文件名

没写存储权限申请😓就不写了

### 参考
[用python从网易云音乐缓存文件中得到MP3](https://blog.csdn.net/marvellousbinary/article/details/79182946)

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
versionName "0.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
Expand Down
83 changes: 2 additions & 81 deletions app/src/main/java/com/wittyneko/neteasemusiccache/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ class MainActivity : AppCompatActivity() {
if (job.isActive) {

binding.btnDecrypt.text = "等待取消"
binding.btnDecrypt.isEnabled = false
Log.e(TAG, "cancel")
job.cancelAndJoin()
Log.e(TAG, "cancel join")
stop().join()
Log.e(TAG, "write join")
binding.btnDecrypt.text = "开始"
binding.btnDecrypt.isEnabled = true
} else {
binding.btnDecrypt.text = "取消"
binding.tvProgress.text = ""
Expand Down Expand Up @@ -356,87 +358,6 @@ class MainActivity : AppCompatActivity() {
binding.lvList.scrollToPosition(adapter.list.size - 1)
}

fun readMetadata(file: File) {

val retriever = MediaMetadataRetriever()
retriever.setDataSource(file.absolutePath)
val title = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)
val album = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)
val artist = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
val duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
val pic = retriever.embeddedPicture
Log.e(TAG, "MediaMetadata: $title, $album, $artist")
}

fun testID3() = launch() {
val musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
Log.e(TAG, "music: ${musicDir.absolutePath}")
val list = musicDir.listFiles()
var flac: File? = null
var mp3: File? = null
Log.e(TAG, "size ${list.size}")
list.forEach {
Log.e(TAG, "name: ${it.name}")
if (it.name.endsWith(".tag.flac")) {
mp3 = it
} else
if (it.name.endsWith(".flac")) {
flac = it
}
}
Log.e(TAG, "${flac?.absolutePath}\n${mp3?.absolutePath}")

val audio = AudioFileIO.read(mp3)
val header = audio.audioHeader
Log.e(TAG, "format: ${header.format}")
val tag = audio.tag as FlacTag
tag.fields.forEach {
Log.e(TAG, "tag: ${it.id}, $it")
}
tag.images.forEach {
Log.e(TAG, "img: $it")
}
tag.setField(FieldKey.TITLE, "可能世界论")
audio.commit()
Unit

}

fun readID3() {
var mp3: File? = null
val id3Bytes = mp3?.inputStream()?.use { input ->
val headBytes = input.readBytes(10)
Log.e(TAG, "head: ${headBytes.joinToString { Integer.toHexString(it.toInt()) }}")
val tag = String(headBytes.sliceArray(0..2))
val ver = headBytes[3]
Log.e(TAG, "tag: $tag, ver: $ver")
val size = headBytes.sliceArray(6..9).let {
((it[0].toInt() and 0xff) shl 24) or
((it[1].toInt() and 0xff) shl 16) or
((it[2].toInt() and 0xff) shl 8) or
(it[3].toInt())
}
size.also {
val hex = byteArrayOf(
(it shr 24).and(0xff).toByte(),
(it shl 16).and(0xff).toByte(),
(it shr 8).and(0xff).toByte(),
it.and(0xff).toByte()
).joinToString { Integer.toHexString(it.toInt()) }
Log.e(TAG, "size: $size, hex: $hex")
}
val labelBypes = input.readBytes(size)
headBytes + labelBypes
}
}

@Suppress("NOTHING_TO_INLINE")
inline fun InputStream.readBytes(estimatedSize: Int = DEFAULT_BUFFER_SIZE): ByteArray {
val buffer = ByteArray(estimatedSize)
read(buffer)
return buffer
}

inline fun uiThread(crossinline block: () -> Unit) {
if (Looper.getMainLooper().thread == Thread.currentThread()) {
block()
Expand Down
Binary file added show_01.webp
Binary file not shown.

0 comments on commit 5855aea

Please sign in to comment.