1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Added support for audio media.

This commit is contained in:
Fabian Schlenz 2016-07-04 09:32:30 +02:00
parent a2d3dadf7b
commit 28965277e7
3 changed files with 21 additions and 0 deletions

View File

@ -17,6 +17,7 @@ class CommandLineDownloadProgress implements DownloadProgressInterface {
public void onMediaDownloadedDocument(boolean n) { show(n, 'D'); } public void onMediaDownloadedDocument(boolean n) { show(n, 'D'); }
public void onMediaDownloadedSticker(boolean n) { show(n, 'S'); } public void onMediaDownloadedSticker(boolean n) { show(n, 'S'); }
public void onMediaDownloadedOther(boolean n) { show(n, ' '); } public void onMediaDownloadedOther(boolean n) { show(n, ' '); }
public void onMediaDownloadedAudio(boolean n) { show(n, 'A'); }
public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); } 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();} private void show(boolean n, char letter) { System.out.print(n ? letter : '.'); i++; if (i % 50 == 0) showNewLine();}

View File

@ -96,6 +96,8 @@ class DownloadManager {
this.downloadMessageMediaDocument(msg, (TLMessageMediaDocument)media); this.downloadMessageMediaDocument(msg, (TLMessageMediaDocument)media);
} else if (media instanceof TLMessageMediaVideo) { } else if (media instanceof TLMessageMediaVideo) {
this.downloadMessageMediaVideo(msg, (TLMessageMediaVideo)media); this.downloadMessageMediaVideo(msg, (TLMessageMediaVideo)media);
} else if (media instanceof TLMessageMediaAudio) {
this.downloadMessageMediaAudio(msg, (TLMessageMediaAudio)media);
} else if (media instanceof TLMessageMediaEmpty || } else if (media instanceof TLMessageMediaEmpty ||
media instanceof TLMessageMediaUnsupported || media instanceof TLMessageMediaUnsupported ||
media instanceof TLMessageMediaGeo || 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<Integer> makeIdList(int start, int end) { private ArrayList<Integer> makeIdList(int start, int end) {
if (start > end) throw new RuntimeException("start and end reversed"); if (start > end) throw new RuntimeException("start and end reversed");
ArrayList<Integer> a = new ArrayList<Integer>(end - start + 1); ArrayList<Integer> a = new ArrayList<Integer>(end - start + 1);
@ -221,6 +233,13 @@ class DownloadManager {
return this.downloadFileFromDc(filename, loc, vid.getDcId(), vid.getSize()); 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) { private String makeFilename(int id, String ext) {
String path = this.user.getFileBase() + String path = this.user.getFileBase() +
Config.FILE_FILES_BASE + Config.FILE_FILES_BASE +

View File

@ -11,5 +11,6 @@ interface DownloadProgressInterface {
public void onMediaDownloadedDocument(boolean n); public void onMediaDownloadedDocument(boolean n);
public void onMediaDownloadedSticker(boolean n); public void onMediaDownloadedSticker(boolean n);
public void onMediaDownloadedOther(boolean n); public void onMediaDownloadedOther(boolean n);
public void onMediaDownloadedAudio(boolean n);
public void onMediaDownloadFinished(); public void onMediaDownloadFinished();
} }