Skip to content

Commit

Permalink
fixed app crashing when using links that have data missing
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscerri committed Oct 22, 2022
1 parent 4a387ea commit 8f533ab
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ImageView thumbnail = card.findViewById(R.id.downloads_image_view);
String imageURL= video.getThumb();

Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
if (!imageURL.isEmpty()){
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}else {
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(R.color.black).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}

// TITLE ----------------------------------
TextView videoTitle = card.findViewById(R.id.downloads_title);
Expand All @@ -92,7 +98,11 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

// Bottom Info ----------------------------------
TextView bottomInfo = card.findViewById(R.id.downloads_info_bottom);
String info = video.getAuthor() + " • " + video.getDuration();
String info = video.getAuthor();
if (!video.getDuration().isEmpty()){
if (!video.getAuthor().isEmpty()) info += " • ";
info += video.getDuration();
}
bottomInfo.setText(info);

// TIME DOWNLOADED ----------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// THUMBNAIL ----------------------------------
ImageView thumbnail = card.findViewById(R.id.result_image_view);
String imageURL= video.getThumb();

Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
if (!imageURL.isEmpty()){
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}else {
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(R.color.black).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}

// TITLE ----------------------------------
TextView videoTitle = card.findViewById(R.id.result_title);
Expand All @@ -84,7 +89,11 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// Bottom Info ----------------------------------

TextView bottomInfo = card.findViewById(R.id.result_info_bottom);
String info = video.getAuthor() + " • " + video.getDuration();
String info = video.getAuthor();
if (!video.getDuration().isEmpty()){
if (!video.getAuthor().isEmpty()) info += " • ";
info += video.getDuration();
}
bottomInfo.setText(info);

// BUTTONS ----------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
try{
new Handler(Looper.getMainLooper()).post(() -> {
// DOWNLOAD ALL BUTTON
if (resultObjects.get(0).getIsPlaylistItem() == 1 || inputQueriesLength > 1) {
if ((resultObjects.size() > 1 && resultObjects.get(1).getIsPlaylistItem() == 1) || inputQueriesLength > 1) {
downloadAllFab.setVisibility(View.VISIBLE);
}
dbManager = new DBManager(context);
Expand Down Expand Up @@ -385,7 +385,7 @@ public boolean onQueryTextSubmit(String query) {
Thread thread = new Thread(() -> {
parseQuery(true);
// DOWNLOAD ALL BUTTON
if (resultObjects.get(0).getIsPlaylistItem() == 1) {
if (resultObjects.size() > 1 && resultObjects.get(1).getIsPlaylistItem() == 1) {
new Handler(Looper.getMainLooper()).post(() -> downloadAllFab.setVisibility(View.VISIBLE));
}
});
Expand Down
27 changes: 22 additions & 5 deletions app/src/main/java/com/deniscerri/ytdlnis/util/InfoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,30 @@ public ArrayList<Video> getFromYTDL(String query){

for (String result : results) {
JSONObject jsonObject = new JSONObject(result);
if (jsonObject.getString("title").equals("[Private video]")) continue;

String title = "";
if (jsonObject.has("title")){
if (jsonObject.getString("title").equals("[Private video]")) continue;
title = jsonObject.getString("title");
}else{
title = jsonObject.getString("webpage_url_basename");
}

String author = "";
if (jsonObject.has("uploader")){
author = jsonObject.getString("uploader");
}

String duration = "";
if (jsonObject.has("duration")){
duration = formatIntegerDuration(jsonObject.getInt("duration"));
}

String url = jsonObject.getString("webpage_url");
String thumb = "";
if (jsonObject.has("thumbnail")){
thumb = jsonObject.getString("thumbnail");
}else {
}else if (jsonObject.has("thumbnails")){
JSONArray thumbs = jsonObject.getJSONArray("thumbnails");
thumb = thumbs.getJSONObject(thumbs.length()-1).getString("url");
}
Expand All @@ -312,9 +329,9 @@ public ArrayList<Video> getFromYTDL(String query){
videos.add(new Video(
jsonObject.getString("id"),
url,
jsonObject.getString("title"),
jsonObject.getString("uploader"),
formatIntegerDuration(jsonObject.getInt("duration")),
title,
author,
duration,
thumb,
dbManager.checkDownloaded(url, "audio"),
dbManager.checkDownloaded(url, "video"),
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ buildscript {
}

def versionMajor = 1
def versionMinor = 3
def versionPatch = 2
def versionMinor = 4
def versionPatch = 1
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

ext {
Expand Down

0 comments on commit 8f533ab

Please sign in to comment.