Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Can't read torrent information #19

Open
ghost opened this issue Jul 29, 2022 · 6 comments
Open

Can't read torrent information #19

ghost opened this issue Jul 29, 2022 · 6 comments

Comments

@ghost
Copy link

ghost commented Jul 29, 2022

package com.oasis.streamio;

import android.net.Uri;
import android.view.View;
import android.widget.Toast;
import androidx.fragment.app.FragmentActivity;
import com.github.se_bastiaan.torrentstream.Torrent;
import com.github.se_bastiaan.torrentstream.StreamStatus;
import com.github.se_bastiaan.torrentstream.TorrentOptions;
import com.github.se_bastiaan.torrentstream.TorrentOptions.Builder;
import com.github.se_bastiaan.torrentstreamserver.TorrentServerListener;
import com.github.se_bastiaan.torrentstreamserver.TorrentStreamNotInitializedException;
import com.github.se_bastiaan.torrentstreamserver.TorrentStreamServer;
import com.oasis.streamio.databinding.ActivityMainBinding;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class StreamModel implements TorrentServerListener {
	private String torrentUri;
	private PlayerModel playerModel;
	private MainActivity activity;
	private ActivityMainBinding binding;
	private Uri streamUri;
	private TorrentStreamServer torrentStreamServer;

	public StreamModel(PlayerModel playerModel, String torrentUri) {
		this.playerModel = playerModel;
		this.torrentUri = torrentUri;
		this.binding = playerModel.getBindView();
		this.activity = (MainActivity) playerModel.getActivity();

		String ipAddress = "127.0.0.1";

		try {
			InetAddress inetAddress = Util.getIpAddress(activity);
			if (inetAddress != null)
				ipAddress = inetAddress.getHostAddress();
		} catch (UnknownHostException exception) {
			Toast.makeText(activity, exception.toString(), Toast.LENGTH_LONG).show();
		}
		final TorrentOptions options = new TorrentOptions.Builder().saveLocation(activity.getFilesDir())
				.removeFilesAfterStop(false).build();
		torrentStreamServer = TorrentStreamServer.getInstance();
		torrentStreamServer.setTorrentOptions(options);
		torrentStreamServer.setServerHost(ipAddress);
		torrentStreamServer.setServerPort(9000);
		torrentStreamServer.startTorrentStream();
		try {
			torrentStreamServer.startStream(torrentUri);
		} catch (TorrentStreamNotInitializedException | IOException e) {
			Toast.makeText(activity, e.toString(), Toast.LENGTH_LONG).show();
		}

		torrentStreamServer.addListener(this);
	}

	@Override
	public void onStreamPrepared(Torrent torrent) {
		Toast.makeText(activity, "onStreamPrepared", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onStreamStarted(Torrent torrent) {
		Toast.makeText(activity, "OnStreamStarted", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onStreamError(Torrent torrent, Exception exception) {
		Toast.makeText(activity, torrentUri, Toast.LENGTH_LONG).show();

		((MainActivity) playerModel.getActivity()).showError(exception.toString(), view -> {
			torrentStreamServer.startTorrentStream();
		});
	}

	@Override
	public void onStreamReady(Torrent torrent) {
		binding.loading.setProgress(100);
	}

	@Override
	public void onStreamProgress(Torrent torrent, StreamStatus status) {
		if (status.bufferProgress <= 100 && binding.loading.getProgress() < 100
				&& binding.loading.getProgress() != status.bufferProgress) {
			Toast.makeText(activity, "Progress: " + status.bufferProgress, Toast.LENGTH_LONG).show();
			binding.loading.setProgress(status.bufferProgress);
		}
	}

	@Override
	public void onStreamStopped() {
		Toast.makeText(activity, "OnStreamStopped", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onServerReady(final String streamUrl) {
		streamUri = Uri.parse(streamUrl);
		binding.customContainer.setVisibility(View.GONE);
		playerModel.initializePlayer(streamUri);
		playerModel.addListener();
	}

	public Uri getStreamUri() {
		return streamUri;
	}

	public void stopStream() {
		torrentStreamServer.stopStream();
	}

	public void stopServer() {
		torrentStreamServer.stopTorrentStream();
	}
}

Screenshot_20220729-211103

The magnet URI is
magnet:?xt=urn:btih:3138B17E66FB66C36280D6165395EFAA98EA09D3&dn=Sniper.+The+White+Raven+%282022%29+%5B720p%5D+%5BYTS.MX%5D&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2Fp4p.arenabg.ch%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce

@se-bastiaan
Copy link
Owner

se-bastiaan commented Jul 29, 2022

You should consider this error a way of telling you that your input is wrong.
So I am not completely sure what the problem is here, but your information is very much non-existent and you didn't ask a question.

Could you help me understand your issue a little bit better?

@ghost
Copy link
Author

ghost commented Jul 29, 2022

I discovered that torrent is not downloaded when torrentServerStream.startStream(streamUri); is called , but when I retry maybe reclick retry button many times the torrent start progress

@ghost
Copy link
Author

ghost commented Jul 29, 2022

I'm streaming torrent to exoplayer onServerReady not called even though am using torrent from example app, is files downloaded before streaming?

@ghost
Copy link
Author

ghost commented Jul 29, 2022

I'm using version 2.0.0

@ghost
Copy link
Author

ghost commented Jul 29, 2022

I'm sorry do I have to select video file or is it selected automatically, I think the code select the largest file and download right? Or I have to provide file to download manually?

@se-bastiaan
Copy link
Owner

se-bastiaan commented Jul 29, 2022

You can read how it works here: https://github.com/TorrentStream/TorrentStream-Android/wiki/FAQ#how-does-it-work

I cannot debug for your single case magnet url, if you find a bug that you think we can solve I'd be happy to help. But this error is to be expected and thus you should handle it yourself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant