make trending fetch a playlists from youtube channel that is addressed in json server

This commit is contained in:
flasker 2024-01-13 23:26:42 +03:00
parent 72e36c2bbb
commit 80348d287d
5 changed files with 101 additions and 12 deletions

View File

@ -39,7 +39,7 @@ android {
// suffix the app id and the app name with git branch name
def workingBranch = getGitWorkingBranch()
def normalizedWorkingBranch = workingBranch.replaceFirst("^[^A-Za-z]+", "").replaceAll("[^0-9A-Za-z]+", "")
if (normalizedWorkingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") {
if (normalizedWorkingBranch.isEmpty() || workingBranch == "master" || workingBranch == "Filter") {
// default values when branch name could not be determined or is master or dev
applicationIdSuffix ".debug"
resValue "string", "app_name", "NewPipe Debug"

View File

@ -221,13 +221,13 @@ public class MainActivity extends AppCompatActivity {
int kioskMenuItemId = 0;
// for (final String ks : service.getKioskList().getAvailableKiosks()) {
// drawerLayoutBinding.navigation.getMenu()
// .add(R.id.menu_tabs_group, kioskMenuItemId, 0, KioskTranslator
// .getTranslatedKioskName(ks, this))
// .setIcon(KioskTranslator.getKioskIcon(ks));
// kioskMenuItemId++;
// }
for (final String ks : service.getKioskList().getAvailableKiosks()) {
drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, kioskMenuItemId, 0, KioskTranslator
.getTranslatedKioskName(ks, this))
.setIcon(KioskTranslator.getKioskIcon(ks));
kioskMenuItemId++;
}
// drawerLayoutBinding.navigation.getMenu()
// .add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER,

View File

@ -16,6 +16,10 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.views.NewPipeRecyclerView;
@ -30,6 +34,17 @@ import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import android.os.AsyncTask;
import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonParser;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInfo<I>>
extends BaseListFragment<L, ListExtractor.InfoItemsPage<I>> {
@State
@ -48,6 +63,70 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
this.errorUserAction = errorUserAction;
}
public class NetworkTask extends AsyncTask<String, Void, String> {
private ChannelTabInfo ChannelPlaylistTabInfo;
private boolean error_happens = false;
@Override
protected String doInBackground(String... urls) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(urls[0]) // Use the URL passed as an argument
.build();
try {
Response response = client.newCall(request).execute();
JsonArray array = new JsonArray();
if (response.isSuccessful() && response.body() != null) {
// this to control also the playlists account
try {
array = JsonParser.array().from(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
// then fectch the channel page then playlists tab
try {
String our_channel_url = array.getObject(0).getString("url");
ChannelInfo ss = ChannelInfo.getInfo(ServiceList.YouTube, our_channel_url);
ChannelPlaylistTabInfo = ChannelTabInfo.getInfo(ServiceList.YouTube, ss.getTabs().get(0));
return "done";
} catch (IOException | ExtractionException e) {
error_happens = true;
Log.d("Filter", "json server not reached");
return "getInfo failed";
}
// return response.body().string();
} else {
error_happens = true;
Log.d("Filter", "json server not reached");
return "Request failed";
}
} catch (IOException e) {
e.printStackTrace();
return "IOException occurred: " + e.getMessage();
}
}
@Override
protected void onPostExecute(String result) {
if ( error_happens ) {
return;
}
Log.d("Filter", result);
qwe(ChannelPlaylistTabInfo);
}
}
protected void qwe(ChannelTabInfo result) {
hideLoading();
isLoading.set(false);
// currentInfo = result;
currentNextPage = result.getNextPage();
// handleResult(result);
infoListAdapter.addInfoItemList(result.getRelatedItems());
}
@Override
protected void initViews(final View rootView, final Bundle savedInstanceState) {
super.initViews(rootView, savedInstanceState);
@ -140,6 +219,14 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
if (currentWorker != null) {
currentWorker.dispose();
}
// I think this is stupid way
if (url.equals("https://www.youtube.com/feed/trending")) {
NetworkTask ss = new NetworkTask();
ss.execute("https://goodkids.freemyip.com/api/videos");
return;
}
currentWorker = loadResult(forceLoad)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())

View File

@ -974,7 +974,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
@Override
public void handleResult(@NonNull final SearchInfo result) {
final List<Throwable> exceptions = result.getErrors();
final List<InfoItem> RelatedItems = FilterUrlsOnline.filterItems(result.getRelatedItems());
final List<InfoItem> RelatedItems = result.getRelatedItems();
loadNextItemsCount = 0;
if (!exceptions.isEmpty()
&& !(exceptions.size() == 1

View File

@ -30,9 +30,10 @@ import com.grack.nanojson.JsonParser;
public final class FilterUrlsOnline {
private FilterUrlsOnline() { }
static String ServerUrl = "https://goodkids.freemyip.com/api/";
private static String getFilterQueryNextPage(final List<? extends InfoItem> items) {
String query = "https://fe0e-149-86-140-44.ngrok-free.app/videos?url=";
String query = "https://goodkids.freemyip.com/api/videos?url=";
boolean skipFirst = true;
for (final InfoItem item : items) {
final String videoUrl = item.getUrl().split("v=")[1];
@ -48,7 +49,7 @@ public final class FilterUrlsOnline {
}
private static String getFilterQuery(final List<InfoItem> items) {
String query = "https://fe0e-149-86-140-44.ngrok-free.app/videos?url=";
String query = ServerUrl.concat("videos?url=");
boolean skipFirst = true;
for (final InfoItem item : items) {
final String videoUrl = item.getUrl().split("v=")[1];
@ -103,7 +104,8 @@ public final class FilterUrlsOnline {
List<InfoItem> RelatedItems = new ArrayList<>();
String query = getFilterQueryNextPage(items);
String response = syncHttpGet(query);
try { JsonArray array = JsonParser.array().from(response);
try {
JsonArray array = JsonParser.array().from(response);
for (final InfoItem item : items) {
for (int i = 0; i < array.size(); i++) {
JsonObject jsonObject = array.getObject(i);