diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java index 817dbc4..bef3fcf 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java @@ -17,6 +17,7 @@ class CommandLineDownloadProgress implements DownloadProgressInterface { public void onMediaDownloadedDocument(boolean n) { show(n, 'D'); } public void onMediaDownloadedSticker(boolean n) { show(n, 'S'); } public void onMediaDownloadedOther(boolean n) { show(n, ' '); } + public void onMediaDownloadedAudio(boolean n) { show(n, 'A'); } public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); } private void show(boolean n, char letter) { System.out.print(n ? letter : '.'); i++; if (i % 50 == 0) showNewLine();} diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java index c93c4c4..d3c33a0 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java @@ -96,6 +96,8 @@ class DownloadManager { this.downloadMessageMediaDocument(msg, (TLMessageMediaDocument)media); } else if (media instanceof TLMessageMediaVideo) { this.downloadMessageMediaVideo(msg, (TLMessageMediaVideo)media); + } else if (media instanceof TLMessageMediaAudio) { + this.downloadMessageMediaAudio(msg, (TLMessageMediaAudio)media); } else if (media instanceof TLMessageMediaEmpty || media instanceof TLMessageMediaUnsupported || media instanceof TLMessageMediaGeo || @@ -191,6 +193,16 @@ class DownloadManager { } } + private void downloadMessageMediaAudio(TLMessage msg, TLMessageMediaAudio a) throws RpcErrorException, IOException { + if (a.getAudio() instanceof TLAudio) { + TLAudio audio = (TLAudio)a.getAudio(); + int i = audio.getMimeType().lastIndexOf('/'); + String ext = audio.getMimeType().substring(i+1).toLowerCase(); + boolean res = this.downloadAudio(this.makeFilename(msg.getId(), ext), audio); + prog.onMediaDownloadedAudio(res); + } + } + private ArrayList makeIdList(int start, int end) { if (start > end) throw new RuntimeException("start and end reversed"); ArrayList a = new ArrayList(end - start + 1); @@ -221,6 +233,13 @@ class DownloadManager { return this.downloadFileFromDc(filename, loc, vid.getDcId(), vid.getSize()); } + private boolean downloadAudio(String filename, TLAudio audio) throws RpcErrorException, IOException { + TLInputDocumentFileLocation loc = new TLInputDocumentFileLocation(); + loc.setId(audio.getId()); + loc.setAccessHash(audio.getAccessHash()); + return this.downloadFileFromDc(filename, loc, audio.getDcId(), audio.getSize()); + } + private String makeFilename(int id, String ext) { String path = this.user.getFileBase() + Config.FILE_FILES_BASE + diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java b/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java index 03097da..17746b8 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java @@ -11,5 +11,6 @@ interface DownloadProgressInterface { public void onMediaDownloadedDocument(boolean n); public void onMediaDownloadedSticker(boolean n); public void onMediaDownloadedOther(boolean n); + public void onMediaDownloadedAudio(boolean n); public void onMediaDownloadFinished(); }