Skip to content

Commit

Permalink
Merge pull request #188 from torikulhabib/master
Browse files Browse the repository at this point in the history
Google drive
  • Loading branch information
torikulhabib authored Aug 29, 2022
2 parents 4427cd3 + 42ec6b7 commit 59bcffd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
6 changes: 2 additions & 4 deletions data/com.github.gabutakut.gabutdm.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
<binary>com.github.gabutakut.gabutdm</binary>
</provides>
​ <releases>
<release version="1.9.2" date="2022-8-15">
<release version="1.9.3" date="2022-8-15">
<description>
<p>Servers and Peers</p>
<p>Menu Move to trash</p>
<p>Fix minor</p>
<p>Fix Error download at Google Drive</p>
</description>
</release>
<release version="1.8.9" date="2022-8-1">
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project ('com.github.gabutakut.gabutdm','vala', 'c', version: '1.9.2')
project ('com.github.gabutakut.gabutdm','vala', 'c', version: '1.9.3')

i18n = import ('i18n')

Expand Down
53 changes: 52 additions & 1 deletion src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1467,8 +1467,12 @@ namespace Gabut {
}

private string aria_url (string url, Gee.HashMap<string, string> options, int arpos) {
var nurl = url;
if (url.contains ("docs.googleusercontent.com/docs")) {
nurl = gdrive_pharse (url);
}
var stringbuild = new StringBuilder ();
stringbuild.append (@"{\"jsonrpc\":\"2.0\", \"id\":\"qwer\", \"method\":\"aria2.addUri\", \"params\":[[\"$(url)\"], {");
stringbuild.append (@"{\"jsonrpc\":\"2.0\", \"id\":\"qwer\", \"method\":\"aria2.addUri\", \"params\":[[\"$(nurl)\"], {");
uint hasempty = stringbuild.str.hash ();
options.foreach ((value) => {
if (hasempty != stringbuild.str.hash ()) {
Expand Down Expand Up @@ -2074,6 +2078,53 @@ namespace Gabut {
return "";
}

private string gdrive_pharse (string url) {
var idgd = url.slice (url.last_index_of ("/") + 1, url.index_of ("?"));
var url_gdm = "";
try {
var session = new Soup.Session ();
var cookies = new SList<Soup.Cookie> ();
cookies.append (new Soup.Cookie ("soup-cookie", "my-val", "docs.google.com", "/", -1));
var message = new Soup.Message ("GET", @"https://docs.google.com/uc?export=download&id=$(idgd)");
Soup.cookies_to_response (cookies, message);
var ins = session.send (message);
if (message.response_headers.get_content_type (null) == "text/html") {
DataInputStream dis = new DataInputStream (ins);
string texthtml = "";
string ln;
while ((ln = dis.read_line_utf8 ()) != null) {
texthtml += @"$(ln.strip ()) \n";
}
MatchInfo match_info;
Regex regex = new Regex ("action=\"(.*?)\"");
if (regex.match_full (texthtml, -1, 0, 0, out match_info)) {
var fixchar = match_info.fetch (1).replace ("&amp;", "&").replace ("%3D", "=").replace ("%26", "&");
if (fixchar.has_prefix ("https://")) {
Soup.Message msg = new Soup.Message ("GET", fixchar);
Soup.cookies_to_request (cookies, msg);
session.send (msg);
url_gdm = msg.get_uri ().to_string ();
} else {
Soup.Message msg = new Soup.Message ("GET", url);
Soup.cookies_to_request (cookies, msg);
session.send (msg);
url_gdm = msg.get_uri ().to_string ();
}
} else {
Soup.Message msg = new Soup.Message ("GET", url);
Soup.cookies_to_request (cookies, msg);
session.send (msg);
url_gdm = msg.get_uri ().to_string ();
}
} else {
url_gdm = message.get_uri ().to_string ();
}
} catch (Error e) {
GLib.warning (e.message);
}
return url_gdm;
}

private int get_container (File file) {
int files = 0;
try {
Expand Down

0 comments on commit 59bcffd

Please sign in to comment.