Skip to content

Commit

Permalink
v1.3 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
acmo0 committed Feb 20, 2022
1 parent 45a9167 commit 46a2df3
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 49 deletions.
Binary file modified .gradle/7.0.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.0.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.0.2/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/checksums/sha1-checksums.bin
Binary file not shown.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# Android-Youtube-Downloader 8+
An Android Youtube downloader based on youtube-dl, pytube and Chaquopy.
You can download in mp4/m4a youtube videos/playlists. This application work for many other websites ([see youtube-dl supported website](https://ytdl-org.github.io/youtube-dl/supportedsites.html))
An Android Youtube downloader based on yt-dlp, pytube and Chaquopy.
You can download in mp4/m4a youtube videos/playlists. This application work for many other websites ([see yt-dlp supported website](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md))
***
## Compatibility
Compatible with android 8 and newer
Compatible with android 8 and newer.
## Download
[Download from our github repository.](https://github.com/acmo0/Android-Youtube-Downloader/releases/tag/v1.2)
## Lastest release improvememts v1.2
[Download from our github repository.](https://github.com/acmo0/Android-Youtube-Downloader/releases/tag/v1.3)
## Lastest release improvements v1.3

1. **Solve downloading speed issue**
2. Save lastest directory used for video/audio downloading
3. Improve download state on the notification
1. **Solve compatibility issues for android 10 and newer**
2. **Solve Youtube downloading issues**

## Screenshots

<img src="images/screen1.png" width="300" height="auto"/> <img src="images/screen2.jpg" width="300" height="auto"/>
## Privacy
This application does not collect any user information
This application does not collect any user information.
## Credits
1. [Chaquopy](https://chaquo.com/chaquopy/) MIT License
2. [youtube-dl](https://github.com/ytdl-org/youtube-dl) The Unlicense
2. [yt-dlp](https://github.com/yt-dlp/yt-dlp) The Unlicense
3. [pytube](https://github.com/pytube/pytube) The Unlicense
4. [ffmpeg-android-java](https://github.com/WritingMinds/ffmpeg-android-java) GPLv3.0

Expand Down
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdk 26
targetSdk 31
versionCode 1
versionName "1.2"
versionName "1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
sourceSets {
Expand All @@ -25,9 +25,11 @@ android {
python {
buildPython "/usr/bin/python3"
buildPython "python3"

pip{
install "youtube-dl"
install "pytube"
options "--upgrade","--ignore-installed","--force-reinstall"
install "yt-dlp"
install "git+https://github.com/pytube/pytube"
}
}
ndk {
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.2",
"versionName": "1.3",
"outputFile": "app-release.apk"
}
],
Expand Down
58 changes: 44 additions & 14 deletions app/src/main/java/com/acmo0/youtubedownloader/DownloaderWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,65 @@ public Result doWork(){
Python py = Python.getInstance();
PyObject pyf;




notifyDownloading(mNotificationManager, notifBuilder, getApplicationContext().getResources().getString(R.string.text_notif_downloading), activityPendingIntent);
if (videoUrl.contains("youtu.be") || videoUrl.contains("youtube.com")){
pyf= py.getModule("ytb_downloader");
}else{
pyf = py.getModule("downloader");
}
String module = "yt-dlp";
pyf = py.getModule("downloader");
downloader = pyf.callAttr("downloader", videoUrl, format, directory, maxQuality, Environment.getExternalStorageDirectory().getPath()+"/Android/data/com.acmo0.youtubedownloader");
PyObject download = downloader.callAttr("download");
System.out.println("Started downloading");
while (downloader.callAttr("state").toBoolean()!=false){
boolean process_fail = false;
while (downloader.callAttr("state").toBoolean()!=false || process_fail){
notifBuilder.setContentText(downloader.get("status").toString());
mNotificationManager.notify(1,notifBuilder.build());
if(downloader.get("fail").toBoolean() == true){
process_fail = downloader.callAttr("isFail").toBoolean();
System.out.println("State : "+Boolean.toString(process_fail));
if(process_fail){
System.out.println("ERROR");
mNotificationManager.cancelAll();
notifyFail(mNotificationManager, notifBuilder, activityPendingIntent);
return Result.failure();
}
try {
TimeUnit.MILLISECONDS.sleep(1000);
TimeUnit.MILLISECONDS.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}

}
System.out.println("State : "+Boolean.toString(process_fail));
process_fail = downloader.callAttr("isFail").toBoolean();
if(process_fail == false){
notifySuccess(mNotificationManager, notifBuilder, activityPendingIntent);
return Result.success();
}
if ((videoUrl.contains("youtu.be") || videoUrl.contains("youtube.com")) && process_fail && Build.VERSION.SDK_INT < 29) {
pyf = py.getModule("ytb_downloader");
module = "pytube";
downloader = pyf.callAttr("downloader", videoUrl, format, directory, maxQuality, Environment.getExternalStorageDirectory().getPath()+"/Android/data/com.acmo0.youtubedownloader");
download = downloader.callAttr("download");
System.out.println("Started downloading");
while (downloader.callAttr("state").toBoolean()!=false){
notifBuilder.setContentText(downloader.get("status").toString());
mNotificationManager.notify(1,notifBuilder.build());
process_fail = downloader.callAttr("isFail").toBoolean();
if(process_fail){
mNotificationManager.cancelAll();
notifyFail(mNotificationManager, notifBuilder, activityPendingIntent);
return Result.failure();
}
try {
TimeUnit.MILLISECONDS.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
FFmpeg ffmpeg = FFmpeg.getInstance(getApplicationContext());
loadFFmpeg(ffmpeg);
if(downloader.get("fail").toBoolean() == false) {
process_fail = downloader.callAttr("isFail").toBoolean();

if(process_fail == false && module.equals("pytube")){
FFmpeg ffmpeg = FFmpeg.getInstance(getApplicationContext());
loadFFmpeg(ffmpeg);
if (format.equals("m4a")) {
System.out.println("Converting");
ffmpegExecute(ffmpeg,downloader.callAttr("cmd").toJava(String[].class));
Expand Down
30 changes: 19 additions & 11 deletions app/src/main/python/downloader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import unicode_literals
import youtube_dl
import yt_dlp as youtube_dl
import os
import time
from threading import *
Expand Down Expand Up @@ -49,47 +49,55 @@ def download(self):
except Exception as e:
if "not a valid URL" in str(e):
self.writeLog("ERROR :"+str(e), self.log_path)
self.fail = True
return False
time.sleep(10)
self.writeLog("PY WARNING : first exception :"+str(e)+", wait 10s and retry", self.log_path)
self.fail = True
return False

def downloadAction(self,directory,dl_format,max_best_quality,url):

ydl_opts = {}
if directory[-1] != "/":
directory+="/"
if dl_format == "mp4":
ydl_opts = {
'format': 'bestvideo[height<='+max_best_quality+']+bestaudio/best[height<='+max_best_quality+']',
'format': 'best[height<='+max_best_quality+']',
'outtmpl': directory+"%(title)s.%(ext)s",
'progress_hooks': [self.my_hook],
}
elif dl_format == "m4a":
ydl_opts = {
'format': 'bestaudio[ext=m4a]/best[ext=m4a]',
'format': 'bestaudio[ext=m4a]',
'outtmpl': directory+"%(title)s.%(ext)s",
'progress_hooks': [self.my_hook],
}
try:
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
except ValueError:
pass
except Exception as e:
self.fail = True
except Exception as e:
print("error ",str(e))
time.sleep(5)
try:
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
except Exception as e:
print("error ",str(e))
self.fail = True



def my_hook(self,d):
if d['status'] == 'finished':
file_tuple = os.path.split(os.path.abspath(d['filename']))
self.status='convert'
if self.stop==True:
self.process.terminate()
if d['status'] == 'downloading':
self.status=d['_percent_str']
if self.stop==True:
self.status='Stopped'
raise ValueError('Stopping process')

def isFail(self):
return self.fail
def state(self):
return self.process.is_alive()
def stop(self):
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/python/ytb_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import time
from threading import *
import sys
import traceback
import pytube
from pytube import YouTube, Playlist,exceptions

class downloader:
Expand All @@ -16,7 +18,6 @@ def __init__(self,url, dl_format, directory, max_best_quality, log_path):
self.status = 'Stopped'
self.cmd_str = [""]
self.res_list = ['2160p', '1440p', '1080p', '720p', '480p', '360p', '240p', '144p']
print("initialise")

def getTime(self):
time_stamp = time.localtime()
Expand Down Expand Up @@ -48,10 +49,8 @@ def download(self):
os.remove(self.log_path+"/yt.log.txt")
try:
self.process.start()
print('start')
return True
except Exception as e:
print('Erreur')
sys.stdout.write(str(e))
self.fail = True

Expand All @@ -69,7 +68,6 @@ def download_video(self,video,directory,max_best_quality):
if len(self.mp4streams) == 0:
sys.stdout.write("No streams")
raise Exception("No streams")
sys.stdout.write(str(len(self.mp4streams)))
self.download_stream = self.mp4streams.order_by('fps')[-1]
self.downloadfilename = directory+self.download_stream.default_filename
self.download_stream.download(filename=directory+self.download_stream.default_filename)
Expand All @@ -84,10 +82,10 @@ def download_audio(self,video,directory):
sys.stdout.write('downloading')

out = self.streams[-1].download(filename=self.downloadfilename)
sys.stdout.write(out)
self.cmd_str = ['-i',self.downloadfilename,'-map','0','-c','copy',self.downloadfilename.split('.')[0]+'.m4a']


def isFail(self):
return self.fail

def downloadAction(self,directory,dl_format,max_best_quality,url):
sys.stdout.write("process started")
Expand All @@ -110,7 +108,10 @@ def downloadAction(self,directory,dl_format,max_best_quality,url):

elif dl_format == "m4a":
if not 'list' in url:
sys.stdout.write(self.url)
video = YouTube(self.url,on_progress_callback=self.progress_handler)
print(video,type(video))
sys.stdout.write(pytube.__version__)
self.download_audio(video,directory)

elif 'list' in url:
Expand Down Expand Up @@ -140,9 +141,11 @@ def downloadAction(self,directory,dl_format,max_best_quality,url):
sys.stdout.write(' '.join(self.cmd_str))
self.status = 'converting...'
sys.stdout.write("process endeed")
except Exception as e:
except:
e = traceback.format_exc()
self.fail = True
self.writelog(str(e),self.log_path)

self.writeLog(str(e),self.log_path)
def progress_handler(self,stream,chunck,remaining):
size = stream.filesize
downloaded = size-remaining
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<string name="app_name">Video Downloader</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="info">Cette application est basée sur <a href="http://ytdl-org.github.io/youtube-dl/">youtube-dl</a> pour télécherger des vidéos/playlists youtube et sur d\'autres sites comme Facebook, Twitter, TikTok, Twitch,...\n\nVoici la liste entière des <a href="http://ytdl-org.github.io/youtube-dl/supportedsites.html">sites supportés</a>.\n\nCette application utilise aussi <a href="https://chaquo.com/chaquopy/">Chaquopy</a>.\n\nCette application est entièrement open-source et le code est publié sur <a href="https://github.com/acmo0/Android-Youtube-Downloader">Github</a>.N\'hésitez pas à reporter des bugs/suggestions sur github.\n\n\n\nCette application est publiée sous une license <a href="https://github.com/acmo0/Android-Youtube-Downloader/blob/master/LICENSE">GNU General Public License v3.0</a></string>
<string name="info">Cette application est basée sur <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> et <a href="https://github.com/pytube/pytube">pytube</a> pour télécherger des vidéos/playlists youtube et sur d\'autres sites comme Facebook, Twitter, TikTok, Twitch,...\n\nVoici la liste entière des <a href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md">sites supportés</a>.\n\nCette application utilise aussi <a href="https://chaquo.com/chaquopy/">Chaquopy</a>.\n\nCette application est entièrement open-source et le code est publié sur <a href="https://github.com/acmo0/Android-Youtube-Downloader">Github</a>.N\'hésitez pas à reporter des bugs/suggestions sur github.\n\n\n\nCette application est publiée sous une license <a href="https://github.com/acmo0/Android-Youtube-Downloader/blob/master/LICENSE">GNU General Public License v3.0</a></string>

<string name="text_wait">Veuillez patienter, téléchagement...</string>
<string name="text_prepare_download">Veuillez patienter, préparation...</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<string name="app_name">Video Downloader</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="info">This software is based on <a href="http://ytdl-org.github.io/youtube-dl/">youtube-dl</a> to download videos/playlists from youtube and other websites like Facebook, Twitter, TikTok, Twitch,...\n\nHere is the full <a href="http://ytdl-org.github.io/youtube-dl/supportedsites.html">list of supported websites</a>.\n\nThis software is also based on <a href="https://chaquo.com/chaquopy/">Chaquopy</a>.\n\nThis software is fully open source and released on <a href="https://github.com/acmo0/Android-Youtube-Downloader">our Github repository</a>.Please feel free to suggest improvements or bugs on our github.\n\n\nThis software is released under the <a href="https://github.com/acmo0/Android-Youtube-Downloader/blob/master/LICENSE">GNU General Public License v3.0</a></string>
<string name="info">This software is based on <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> and <a href="https://github.com/pytube/pytube">pytube</a> to download videos/playlists from youtube and other websites like Facebook, Twitter, TikTok, Twitch,...\n\nHere is the full <a href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md">list of supported websites</a>.\n\nThis software is also based on <a href="https://chaquo.com/chaquopy/">Chaquopy</a>.\n\nThis software is fully open source and released on <a href="https://github.com/acmo0/Android-Youtube-Downloader">our Github repository</a>.Please feel free to suggest improvements or bugs on our github.\n\n\nThis software is released under the <a href="https://github.com/acmo0/Android-Youtube-Downloader/blob/master/LICENSE">GNU General Public License v3.0</a></string>
<string name="text_wait">Please wait, downloading...</string>
<string name="text_prepare_download">Please wait, preparing downloading...</string>
<string name="text_downloading">Please wait, downloading...</string>
Expand Down

0 comments on commit 46a2df3

Please sign in to comment.