1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-06-05 21:09:11 +02:00
This commit is contained in:
Thomas
2020-12-29 16:53:02 +01:00
parent e475348d39
commit 5c27292543
29 changed files with 1872 additions and 5 deletions

View File

@ -160,6 +160,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.browser:browser:1.3.0'
implementation 'androidx.documentfile:documentfile:1.0.1'
implementation project(path: ':torrentStream')
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
@ -181,7 +182,6 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.github.mancj:MaterialSearchBar:0.8.5'
implementation "com.github.TorrentStream:TorrentStream-Android:2.7.0"
implementation "io.github.kobakei:ratethisapp:1.2.0"
implementation 'com.github.vkay94:DoubleTapPlayerView:1.0.0'

View File

@ -75,6 +75,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.frostwire.jlibtorrent.SessionManager;
import com.github.se_bastiaan.torrentstream.StreamStatus;
import com.github.se_bastiaan.torrentstream.Torrent;
import com.github.se_bastiaan.torrentstream.TorrentOptions;
@ -119,6 +120,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -239,7 +242,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override
public void onStreamStarted(Torrent torrent) {
startStream(peertube, torrent.getVideoFile().getAbsolutePath(), null, autoPlay, -1, null, null, true);
}
@Override
@ -249,11 +253,44 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override
public void onStreamReady(Torrent torrent) {
if (torrent.getVideoFile() != null) {
for (int i = 0; i < torrent.getFileNames().length; i++) {
torrent.getTorrentHandle().renameFile(i, torrent.getFileNames()[0].replaceAll("[^a-zA-Z0-9/.-]", "_"));
}
}
startStream(peertube, torrent.getVideoFile().getAbsolutePath().replaceAll("[^a-zA-Z0-9/.-]", "_"), null, autoPlay, -1, null, null, true);
PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller);
ConstraintLayout torrent_info = controlView.findViewById(R.id.torrent_info);
TextView dowload_rate = controlView.findViewById(R.id.dowload_rate);
TextView upload_rate = controlView.findViewById(R.id.upload_rate);
torrent_info.setVisibility(View.VISIBLE);
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
SessionManager sessionManager = torrentStream.getSessionManager();
if (sessionManager != null) {
long upload = sessionManager.uploadRate();
long download = sessionManager.downloadRate();
int seeds = sessionManager.maxActiveSeeds();
runOnUiThread(() -> {
dowload_rate.setText(String.format("▼ %s", Helper.rateSize(PeertubeActivity.this, download)));
upload_rate.setText(String.format("▲ %s", Helper.rateSize(PeertubeActivity.this, upload)));
});
}
}
}, 0, 1000);
}
@Override
public void onStreamProgress(Torrent torrent, StreamStatus status) {
if (binding != null) {
PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller);
TextView peers_number = controlView.findViewById(R.id.peers_number);
peers_number.setText(getString(R.string.peers, status.peers));
}
}
@Override
@ -278,7 +315,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
isRemote = false;
TorrentOptions torrentOptions = new TorrentOptions.Builder()
.saveLocation(getCacheDir())
.saveLocation(getCacheDir() + "/torrent/")
.autoDownload(true)
.removeFilesAfterStop(true)
.build();
@ -1344,14 +1381,16 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
SingleSampleMediaSource subtitleSource = null;
DataSource.Factory dataSourceFactory = null;
if (localTorrentUrl != null) {
java.io.File localFile = new java.io.File(localTorrentUrl);
DataSpec dataSpec = new DataSpec(Uri.fromFile(new java.io.File(localTorrentUrl)));
FileDataSource fileDataSource = new FileDataSource();
try {
fileDataSource.open(dataSpec);
dataSourceFactory = () -> fileDataSource;
} catch (FileDataSource.FileDataSourceException e) {
e.printStackTrace();
}
dataSourceFactory = () -> fileDataSource;
}
if (video_cache == 0 || dataSourceFactory != null) {
if (dataSourceFactory == null) {

View File

@ -628,4 +628,25 @@ public class Helper {
return String.format(Locale.getDefault(), "%s%s", df.format(rounded), context.getString(R.string.mb));
}
}
public static String rateSize(Context context, long size) {
if (size > 1000000000) {
float rounded = (float) size / 1000000000;
DecimalFormat df = new DecimalFormat("#.#");
return String.format(Locale.getDefault(), "%s%s", df.format(rounded), context.getString(R.string.gb));
} else if (size > 1000000) {
float rounded = (float) size / 1000000;
DecimalFormat df = new DecimalFormat("#.#");
return String.format(Locale.getDefault(), "%s%s", df.format(rounded), context.getString(R.string.mb));
} else if (size > 1000) {
float rounded = (float) size / 1000000;
DecimalFormat df = new DecimalFormat("#.#");
return String.format(Locale.getDefault(), "%s%s", df.format(rounded), context.getString(R.string.kb));
} else {
float rounded = (float) size / 1000000;
DecimalFormat df = new DecimalFormat("#.#");
return String.format(Locale.getDefault(), "%s%s", df.format(rounded), context.getString(R.string.b));
}
}
}

View File

@ -55,6 +55,44 @@
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/torrent_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/seekbar_controller"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:id="@+id/dowload_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:textColor="#FFBEBEBE"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/upload_rate"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/upload_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:textColor="#FFBEBEBE"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/peers_number"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/peers_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="#FFBEBEBE"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/seekbar_controller"
app:layout_constraintBottom_toBottomOf="parent"

View File

@ -170,6 +170,10 @@
<string name="action_mute">Mute</string>
<string name="unlimited">Unlimited</string>
<string name="peers">%1$d Peers</string>
<string name="b">B</string>
<string name="kb">KB</string>
<string name="mb">MB</string>
<string name="gb">GB</string>
<string name="total_video_quota">Total video quota</string>
@ -449,4 +453,5 @@
<string name="instance_not_availabe">Instance is not available!</string>
<string name="max_tag_size">The video should not have more than 5 tags!</string>
<string name="watermark">Watermark</string>
</resources>