summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar Nitzo <nitzo2001@yahoo.com> 2016-07-22 22:01:17 +0200
committerGravatar Nitzo <nitzo2001@yahoo.com> 2016-07-22 22:01:17 +0200
commite6cf876628bbdfacf5f6c60f3b7027d0ba0cb274 (patch)
tree5c44de886b1ab6d28f8107b2d40a33f99363d69c /module
parent[EuroshareEu] fix #2551 (diff)
downloadpyload-e6cf876628bbdfacf5f6c60f3b7027d0ba0cb274.tar.xz
[GoogledriveCom] Use API
Diffstat (limited to 'module')
-rw-r--r--module/plugins/hoster/GoogledriveCom.py63
1 files changed, 43 insertions, 20 deletions
diff --git a/module/plugins/hoster/GoogledriveCom.py b/module/plugins/hoster/GoogledriveCom.py
index afe7f1fb8..d6ead2d65 100644
--- a/module/plugins/hoster/GoogledriveCom.py
+++ b/module/plugins/hoster/GoogledriveCom.py
@@ -4,19 +4,19 @@
# https://drive.google.com/file/d/0B6RNTe4ygItBQm15RnJiTmMyckU/view?pli=1
import re
-import urlparse
-from module.plugins.internal.SimpleHoster import SimpleHoster
-from module.plugins.internal.misc import html_unescape
+from module.network.HTTPRequest import BadHeader
+from module.plugins.internal.Hoster import Hoster
+from module.plugins.internal.misc import json
-class GoogledriveCom(SimpleHoster):
+class GoogledriveCom(Hoster):
__name__ = "GoogledriveCom"
__type__ = "hoster"
- __version__ = "0.21"
+ __version__ = "0.22"
__status__ = "testing"
- __pattern__ = r'https?://(?:www\.)?(drive|docs)\.google\.com/(file/d/\w+|uc\?.*id=)'
+ __pattern__ = r'https?://(?:www\.)?(?:drive|docs)\.google\.com/(?:file/d/|(?:uc|open)\?.*id=)(?P<ID>[-\w]+)'
__config__ = [("activated" , "bool", "Activated" , True),
("use_premium" , "bool", "Use premium account if available" , True),
("fallback" , "bool", "Fallback to free download if premium fails" , True),
@@ -25,11 +25,11 @@ class GoogledriveCom(SimpleHoster):
__description__ = """Drive.google.com hoster plugin"""
__license__ = "GPLv3"
- __authors__ = [("zapp-brannigan", "fuerst.reinje@web.de")]
+ __authors__ = [("zapp-brannigan", "fuerst.reinje@web.de" ),
+ ("GammaC0de" , "nitzo2001[AT]yahoo[DOT]com")]
-
- NAME_PATTERN = r'(?:<title>|class="uc-name-size".*>)(?P<N>.+?)(?: - Google Drive</title>|</a> \()'
- OFFLINE_PATTERN = r'align="center"><p class="errorMessage"'
+ API_URL = "https://www.googleapis.com/drive/v3/"
+ API_KEY = "AIzaSyAcA9c4evtwSY1ifuvzo6HKBkeot5Bk_U4"
def setup(self):
@@ -38,17 +38,40 @@ class GoogledriveCom(SimpleHoster):
self.chunk_limit = 1
- def handle_free(self, pyfile):
- for _i in xrange(2):
- m = re.search(r'"([^"]+uc\?.*?)"', self.data)
+ def api_response(self, cmd, **kwargs):
+ kwargs['key'] = self.API_KEY
+ try:
+ json_data = json.loads(self.load("%s%s/%s" % (self.API_URL, cmd, self.info['pattern']['ID']), get=kwargs))
+ self.log_debug("API response: %s" % json_data)
+ return json_data
+
+ except BadHeader, e:
+ self.log_error("API Error: %s" % cmd, e, "ID: %s" % self.info['pattern']['ID'])
+ return None
+
+
+ def api_download(self):
+ self.download("%s%s/%s" % (self.API_URL, "files", self.info['pattern']['ID']),
+ get={'alt' : "media",
+ # 'acknowledgeAbuse': "true",
+ 'key' : self.API_KEY})
- if m is None:
- return
- link = self.fixurl(m.group(1), "https://docs.google.com/")
+ def process(self, pyfile):
+ json_data = self.api_response("files", fields="md5Checksum,name,size")
+
+ if json_data is None:
+ self.fail("API error")
+
+ if 'error' in json_data:
+ if json_data['error']['code'] == 404:
+ self.offline()
- if re.search(r'/uc\?.*&confirm=', link):
- self.link = link
- return
else:
- self.data = self.load(link)
+ self.fail(json_data['error']['message'])
+
+ pyfile.size = long(json_data['size'])
+ pyfile.name = json_data['name']
+ self.info['md5'] = json_data['md5Checksum']
+
+ self.api_download()