From c0f0c40d8f15d3786d0d21981b53dca92b47061e Mon Sep 17 00:00:00 2001 From: Harshith Goka Date: Tue, 28 Aug 2018 04:40:26 +0530 Subject: [PATCH] redesign with material design 2 --- .project | 17 + .settings/org.eclipse.buildship.core.prefs | 8 + app/.classpath | 6 + app/.project | 23 + .../org.eclipse.buildship.core.prefs | 2 + app/src/main/AndroidManifest.xml | 2 +- .../me/harshithgoka/youtubedl/Extractor.java | 9 +- .../me/harshithgoka/youtubedl/Format.java | 30 +- .../harshithgoka/youtubedl/FormatAdapter.java | 37 +- .../youtubedl/FormatsActivity.java | 4 +- .../harshithgoka/youtubedl/MainActivity.java | 85 +- .../harshithgoka/youtubedl/Utils/Utils.java | 19 +- .../me/harshithgoka/youtubedl/VideoInfo.java | 20 + .../main/res/drawable/ic_send_black_24dp.xml | 5 + .../res/drawable/ic_videocam_black_24dp.xml | 5 + .../drawable/ic_videocam_off_black_24dp.xml | 5 + .../res/drawable/ic_volume_off_black_24dp.xml | 5 + .../res/drawable/ic_volume_up_black_24dp.xml | 5 + app/src/main/res/layout/activity_formats.xml | 2 +- app/src/main/res/layout/activity_main.xml | 55 +- app/src/main/res/layout/formats_layout.xml | 17 +- app/src/main/res/layout/list_item.xml | 49 +- app/src/main/res/values/dimens.xml | 1 + watch?v=AzDfnHVfEdA | 1475 +++++++++++++++++ 24 files changed, 1784 insertions(+), 102 deletions(-) create mode 100644 .project create mode 100644 .settings/org.eclipse.buildship.core.prefs create mode 100644 app/.classpath create mode 100644 app/.project create mode 100644 app/.settings/org.eclipse.buildship.core.prefs create mode 100644 app/src/main/java/me/harshithgoka/youtubedl/VideoInfo.java create mode 100644 app/src/main/res/drawable/ic_send_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_videocam_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_videocam_off_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_volume_off_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_volume_up_black_24dp.xml create mode 100644 watch?v=AzDfnHVfEdA diff --git a/.project b/.project new file mode 100644 index 0000000..e06dcf6 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + youtube-dl-android + Project youtube-dl-android created by Buildship. + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..22b1843 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,8 @@ +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) +connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home= +offline.mode=false +override.workspace.settings=true diff --git a/app/.classpath b/app/.classpath new file mode 100644 index 0000000..eb19361 --- /dev/null +++ b/app/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/.project b/app/.project new file mode 100644 index 0000000..ac485d7 --- /dev/null +++ b/app/.project @@ -0,0 +1,23 @@ + + + app + Project app created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/app/.settings/org.eclipse.buildship.core.prefs b/app/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..b1886ad --- /dev/null +++ b/app/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir=.. +eclipse.preferences.version=1 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e06b0cf..75bf399 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.MaterialComponents.Light"> + android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"> diff --git a/app/src/main/java/me/harshithgoka/youtubedl/Extractor.java b/app/src/main/java/me/harshithgoka/youtubedl/Extractor.java index 7674543..3453371 100644 --- a/app/src/main/java/me/harshithgoka/youtubedl/Extractor.java +++ b/app/src/main/java/me/harshithgoka/youtubedl/Extractor.java @@ -196,8 +196,10 @@ public String getID (String url) { return m.group(2); } - public List getFormats(String you_url) { + public VideoInfo getFormats(String you_url) { String response; + String video_id = ""; + String thumbnail_url = ""; JSONObject ret = new JSONObject(); try { @@ -262,7 +264,7 @@ else if (params.contains("s")) { for (String param: params) { if (param.equals("itag")) { - f.itag = Integer.parseInt(query_pairs.get(param)); + f.setItag(Integer.parseInt(query_pairs.get(param))); } if (param.equals("type")) { @@ -277,7 +279,8 @@ else if (params.contains("s")) { formats.add(f); } - return formats; + VideoInfo videoInfo = new VideoInfo(video_id, thumbnail_url, formats); + return videoInfo; } catch (IOException e) { diff --git a/app/src/main/java/me/harshithgoka/youtubedl/Format.java b/app/src/main/java/me/harshithgoka/youtubedl/Format.java index 211a1d0..b0abb13 100644 --- a/app/src/main/java/me/harshithgoka/youtubedl/Format.java +++ b/app/src/main/java/me/harshithgoka/youtubedl/Format.java @@ -23,9 +23,11 @@ public class Format implements Parcelable { public String url; public String quality; public String type; - public String extension; public String description; + public String content; + + public boolean audio, video; public Format (String title) { this.title = title; @@ -38,10 +40,24 @@ protected Format(Parcel in) { type = in.readString(); extension = Utils.getExtension(this); - title = Utils.getTitle(this); + content = Utils.getTitle(this); description = Utils.getDescription(this); } + public void setFormat(Format fmt) { + title = fmt.title; + itag = fmt.itag; + url = fmt.url; + quality = fmt.quality; + type = fmt.type; + extension = fmt.extension; + description = fmt.description; + content = fmt.content; + + audio = fmt.audio; + video = fmt.video; + } + public static final Creator CREATOR = new Creator() { @Override public Format createFromParcel(Parcel in) { @@ -54,13 +70,21 @@ public Format[] newArray(int size) { } }; + public void setItag(int itag) { + this.itag = itag; + + extension = Utils.getExtension(this); + content = Utils.getTitle(this); + description = Utils.getDescription(this); + } + @Override public int describeContents() { return 0; } @Override - public void writeToParcel(Parcel parcel, int i) { + public void writeToParcel(Parcel parcel, int flags) { parcel.writeInt(itag); parcel.writeString(url); parcel.writeString(quality); diff --git a/app/src/main/java/me/harshithgoka/youtubedl/FormatAdapter.java b/app/src/main/java/me/harshithgoka/youtubedl/FormatAdapter.java index ecd9763..d4c0a20 100644 --- a/app/src/main/java/me/harshithgoka/youtubedl/FormatAdapter.java +++ b/app/src/main/java/me/harshithgoka/youtubedl/FormatAdapter.java @@ -5,14 +5,16 @@ import android.content.Context; import android.net.Uri; import androidx.recyclerview.widget.RecyclerView; +import me.harshithgoka.youtubedl.Utils.Utils; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; -import java.util.ArrayList; import java.util.List; +import java.util.Locale; /** * Created by harshithgoka on 12/16/2017 AD. @@ -24,19 +26,25 @@ public class FormatAdapter extends RecyclerView.Adapter formats; @@ -58,6 +59,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe LinearLayoutManager linearLayoutManager; BottomSheetBehavior bottomSheetBehavior; + List progressBars; + + SharedPreferences mPrefs; + ArrayList history; @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { @@ -90,11 +95,9 @@ protected void onCreate(Bundle savedInstanceState) { } - this.btnAllFormats = findViewById(R.id.btnAllFormats); - this.btnCopy = findViewById(R.id.fab); + this.btnCopy = findViewById(R.id.paste); this.btnDownload = findViewById(R.id.btnDownload); - this.btnAllFormats.setOnClickListener(this); this.btnCopy.setOnClickListener(this); this.btnDownload.setOnClickListener(this); @@ -103,6 +106,10 @@ protected void onCreate(Bundle savedInstanceState) { urlEdit = (EditText) findViewById(R.id.url); + progressBars = new ArrayList<>(); + progressBars.add((ProgressBar) findViewById(R.id.progressBar)); + progressBars.add((ProgressBar) findViewById(R.id.progressBar2)); + formats = new ArrayList<>(); extractor = new Extractor(); @@ -126,6 +133,16 @@ public void onClick(View v) { } }); + mPrefs = getPreferences(MODE_PRIVATE); + Gson gson = new Gson(); + String json = mPrefs.getString(HISTORY, ""); + + Type type = new TypeToken< List < VideoInfo >>() {}.getType(); + history = gson.fromJson(json, type); + if (history == null) { + history = new ArrayList<>(); + } + // ATTENTION: This was auto-generated to handle app links. Intent appLinkIntent = getIntent(); String appLinkAction = appLinkIntent.getAction(); @@ -146,6 +163,16 @@ else if (clipData != null) { } } + @Override + protected void onPause() { + super.onPause(); + SharedPreferences.Editor editor = mPrefs.edit(); + + String connectionsJSONString = new Gson().toJson(history); + editor.putString(HISTORY, connectionsJSONString); + editor.apply(); + } + private void println (String s) { log.append(s + "\n"); } @@ -175,7 +202,7 @@ public void startDownload(String url) { return; } - AsyncTask> asyncTask = new YoutubeDLAsyncTask(getApplicationContext(), extractor); + AsyncTask asyncTask = new YoutubeDLAsyncTask(getApplicationContext(), extractor); asyncTask.execute(url); } @@ -202,22 +229,22 @@ else if ((url = clipData.getItemAt(0).getText()) != null ) { } } - public void showAllFormats(View view) { - if (formats.size() > 0) { - Intent intent = new Intent(getApplicationContext(), FormatsActivity.class); - intent.putParcelableArrayListExtra(FormatsActivity.FORMATS, (ArrayList) formats); - startActivity(intent); + public void showLoading () { + for (ProgressBar bar : progressBars) { + bar.setVisibility(View.VISIBLE); + } + } + + public void hideLoading() { + for (ProgressBar bar: progressBars) { + bar.setVisibility(View.GONE); } } @Override public void onClick(View v) { switch (v.getId()){ - case R.id.btnAllFormats: - showAllFormats(v); - break; - - case R.id.fab: + case R.id.paste: pasteFromClipboard(v); break; @@ -227,7 +254,7 @@ public void onClick(View v) { } } - class YoutubeDLAsyncTask extends AsyncTask> { + class YoutubeDLAsyncTask extends AsyncTask { Context context; Extractor ytextractor; @@ -236,16 +263,24 @@ public YoutubeDLAsyncTask(Context context, Extractor extractor) { ytextractor = extractor; } + @Override + protected void onPreExecute() { + super.onPreExecute(); + showLoading(); + } @Override - protected List doInBackground(String... strings) { + protected VideoInfo doInBackground(String... strings) { String you_url = strings[0]; return ytextractor.getFormats(you_url); } @Override - protected void onPostExecute(List formats) { - if (formats != null) { + protected void onPostExecute(VideoInfo videoInfo) { + hideLoading(); + if (videoInfo != null) { + List formats = videoInfo.formats; + history.add(0, videoInfo); if (formats.size() > 0) { MainActivity.this.formats.clear(); MainActivity.this.formats.addAll(formats); diff --git a/app/src/main/java/me/harshithgoka/youtubedl/Utils/Utils.java b/app/src/main/java/me/harshithgoka/youtubedl/Utils/Utils.java index 9ab672c..a99f186 100644 --- a/app/src/main/java/me/harshithgoka/youtubedl/Utils/Utils.java +++ b/app/src/main/java/me/harshithgoka/youtubedl/Utils/Utils.java @@ -3,6 +3,8 @@ import org.json.JSONException; import org.json.JSONObject; +import java.util.Locale; + import me.harshithgoka.youtubedl.Format; /** @@ -614,27 +616,30 @@ public static String getTitle (Format format) { boolean audio = fmt.has("acodec"); boolean video = fmt.has("vcodec"); + format.audio = audio; + format.video = video; + if ( audio && video) { - ret = "Video + Audio "; + ret = "Video + Audio"; if (fmt.has("height")) { - ret += fmt.getInt("height") + "p"; + ret += String.format(Locale.UK, " %dp",fmt.getInt("height")); } if (fmt.has("abr")) { - ret += fmt.getInt("abr") + "kbps audio"; + ret += String.format(Locale.UK, " %dkbps audio",fmt.getInt("abr")); } } else if (video) { - ret = "Video Only "; + ret = "Video Only"; if (fmt.has("height")) { - ret += fmt.getInt("height") + "p"; + ret += String.format(Locale.UK, " %dp",fmt.getInt("height")); } } else if (audio) { - ret = "Audio Only "; + ret = "Audio Only"; if (fmt.has("abr")) { - ret += fmt.getInt("abr") + "kbps"; + ret += String.format(Locale.UK, " %dkbps",fmt.getInt("abr")); } } } catch (JSONException e) { diff --git a/app/src/main/java/me/harshithgoka/youtubedl/VideoInfo.java b/app/src/main/java/me/harshithgoka/youtubedl/VideoInfo.java new file mode 100644 index 0000000..f143acf --- /dev/null +++ b/app/src/main/java/me/harshithgoka/youtubedl/VideoInfo.java @@ -0,0 +1,20 @@ +package me.harshithgoka.youtubedl; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.List; + +public class VideoInfo { + public String video_id; + public String thumbnail_url; + public List formats; + + VideoInfo(String id, String thumbnail_url, List formats) { + this.video_id = id; + this.thumbnail_url = thumbnail_url; + this.formats = new ArrayList<>(); + this.formats.addAll(formats); + } +} diff --git a/app/src/main/res/drawable/ic_send_black_24dp.xml b/app/src/main/res/drawable/ic_send_black_24dp.xml new file mode 100644 index 0000000..33efc5c --- /dev/null +++ b/app/src/main/res/drawable/ic_send_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_videocam_black_24dp.xml b/app/src/main/res/drawable/ic_videocam_black_24dp.xml new file mode 100644 index 0000000..5242710 --- /dev/null +++ b/app/src/main/res/drawable/ic_videocam_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_videocam_off_black_24dp.xml b/app/src/main/res/drawable/ic_videocam_off_black_24dp.xml new file mode 100644 index 0000000..510df3e --- /dev/null +++ b/app/src/main/res/drawable/ic_videocam_off_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_volume_off_black_24dp.xml b/app/src/main/res/drawable/ic_volume_off_black_24dp.xml new file mode 100644 index 0000000..5f114d5 --- /dev/null +++ b/app/src/main/res/drawable/ic_volume_off_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_volume_up_black_24dp.xml b/app/src/main/res/drawable/ic_volume_up_black_24dp.xml new file mode 100644 index 0000000..9a9f988 --- /dev/null +++ b/app/src/main/res/drawable/ic_volume_up_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_formats.xml b/app/src/main/res/layout/activity_formats.xml index 0a39db0..e5d3002 100644 --- a/app/src/main/res/layout/activity_formats.xml +++ b/app/src/main/res/layout/activity_formats.xml @@ -36,7 +36,7 @@ + app:layout_constraintTop_toBottomOf="@+id/progressBar2" /> @@ -54,29 +55,19 @@ android:text="@string/example_url" /> - - - + @@ -86,10 +77,11 @@ android:layout_height="wrap_content" android:layout_gravity="bottom" app:backgroundTint="@color/colorPrimary" - app:navigationIcon="@drawable/ic_menu_24"/> + app:navigationIcon="@drawable/ic_menu_24" /> + + + + + diff --git a/app/src/main/res/layout/formats_layout.xml b/app/src/main/res/layout/formats_layout.xml index a470abe..c3a57c2 100644 --- a/app/src/main/res/layout/formats_layout.xml +++ b/app/src/main/res/layout/formats_layout.xml @@ -36,7 +36,7 @@ app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@+id/progressBar"> + + diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml index 8e6b716..e455d03 100644 --- a/app/src/main/res/layout/list_item.xml +++ b/app/src/main/res/layout/list_item.xml @@ -14,47 +14,60 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + app:layout_constraintTop_toTopOf="@+id/format_quality" /> + + + android:textAppearance="@style/TextAppearance.AppCompat.Headline" + app:layout_constraintEnd_toStartOf="@+id/format_itag" + app:layout_constraintStart_toEndOf="@+id/audio" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@+id/format_quality" /> + app:layout_constraintEnd_toEndOf="parent" /> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index da62b5f..a46457f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -2,4 +2,5 @@ 180dp 16dp 16dp + 24dp diff --git a/watch?v=AzDfnHVfEdA b/watch?v=AzDfnHVfEdA new file mode 100644 index 0000000..5093824 --- /dev/null +++ b/watch?v=AzDfnHVfEdA @@ -0,0 +1,1475 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ULTIMATE 100" Bedroom Gaming Battlestation! - YouTube + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ IN +
+
+
+ +
+
+
+

+ + + +Loading... + +

+ +
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+ + + +
+
+
+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+

+ + + + + ULTIMATE 100" Bedroom Gaming Battlestation! + + +

+
+
+ + +
+ + + + + +
+
2,044,467 views
+
+
+
+
+
+ + + + + +
+
+ + + + +
+
+
+
+

+ + + +Loading... + +

+ +
+
+
+ +
+ +
+
+
+

+ + + +Loading... + +

+ +
+
+
+

+Transcript +

+
+ +
+ + + +
+
+The interactive transcript could not be loaded. +
+ + +
+
+ +
+ +
+
+

+ + + +Loading... + +

+ +
+
+ +
+
+

+ + + +Loading... + +

+ +
+
+ + +
+
+ Rating is available when the video has been rented. +
+ +
+ +
+
+ This feature is not available right now. Please try again later. +
+
+ + +
+ + +
+ + +
Published on Jan 31, 2018

Thanks to ORIGIN PC for sponsoring this video! Check out their new GENESIS desktop and other awesome deals at http://www.originpc.com/?aid=2455

We built a $15,000 battle station with a custom DIY desk to house our new Origin Genesis gaming PC. I'm never leaving the office.

Buy Origin PCs on Amazon: http://geni.us/6Vbk29

Discuss on the forum: https://linustechtips.com/main/topic/...

Our Affiliates, Referral Programs, and Sponsors: https://linustechtips.com/main/topic/...

Linus Tech Tips merchandise at http://www.designbyhumans.com/shop/Li...
Linus Tech Tips posters at http://crowdmade.com/linustechtips
Our production gear: http://geni.us/cvOS

Twitter - https://twitter.com/linustech
Facebook - http://www.facebook.com/LinusTech
Instagram - https://www.instagram.com/linustech
Twitch - https://www.twitch.tv/linustech

Intro Screen Music Credit:
Title: Laszlo - Supernova
Video Link: https://www.youtube.com/watch?v=PKfxm...
iTunes Download Link: https://itunes.apple.com/us/album/sup...
Artist Link: https://soundcloud.com/laszlomusic

Outro Screen Music Credit: Approaching Nirvana - Sugar High http://www.youtube.com/approachingnir...

Sound effects provided by http://www.freesfx.co.uk/sfx/

+ +
+
+ +
+ + + +
+
+

+ + + +Loading... + +

+ +
+ +
+ + +
+
+
+ + + +
+
+ +
+ +
+
+
+Advertisement +
+
+
+
+ + +
+
+
+
+
+ + + +When autoplay is enabled, a suggested video will automatically play next. + + + +
+

+ Up next +

+ + +
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+ +
+ +
+
+ + +
+
+ + +
+ to add this to Watch Later + +
+
+

+Add to +

+
+
+

+ + + + Loading playlists... + +

+ +
+
+ + + + + + + \ No newline at end of file