From ad487d8ed5a500e46538f9b43b493e4fb168bbea Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 25 May 2020 19:27:18 +0200 Subject: [PATCH] hdmario:supporto conferma con mail --- lib/onesecmail.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ servers/hdmario.json | 2 +- servers/hdmario.py | 14 ++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 lib/onesecmail.py diff --git a/lib/onesecmail.py b/lib/onesecmail.py new file mode 100644 index 00000000..b3dfd335 --- /dev/null +++ b/lib/onesecmail.py @@ -0,0 +1,51 @@ +import random +import string +import time + +from core import httptools + +baseUrl = 'https://www.1secmail.com/api/v1/' +defDomain = '1secmail.com' + +def splitMail(mail): + if '@' in mail: + user, domain = mail.split('@') + else: + user = mail + domain = defDomain + return user, domain + +def getMessages(mail): + """ + :param user: user@1secmail.com + :return: json containing inbox id and subjects + """ + user, domain = splitMail(mail) + apiUrl = baseUrl + '?action=getMessages&login=' + user + '&domain=' + domain + return httptools.downloadpage(apiUrl).json + + +def readLastMessage(mail): + user, domain = splitMail(mail) + try: + id = getMessages(mail)[0]['id'] + except: + return None + apiUrl = baseUrl + '?action=readMessage&login=' + user + '&domain=' + domain + '&id=' + str(id) + return httptools.downloadpage(apiUrl).json + + +def waitForMail(mail, timeout=10): + secs = 0 + while secs < 10: + msg = readLastMessage(mail) + if msg: + return msg + else: + time.sleep(1) + secs += 1 + return None + +def getRandom(len=10): + letters = string.ascii_lowercase + return ''.join(random.choice(letters) for i in range(len)) + '@' + defDomain \ No newline at end of file diff --git a/servers/hdmario.json b/servers/hdmario.json index 8c597436..c2f2c2ad 100644 --- a/servers/hdmario.json +++ b/servers/hdmario.json @@ -5,7 +5,7 @@ "patterns": [ { "pattern": "https?://hdmario.live/embed/([0-9]+)", - "url": "https://hdmario.live/embed/\\1?" + "url": "https://hdmario.live/embed/\\1" } ] }, diff --git a/servers/hdmario.py b/servers/hdmario.py index 1c948bc2..1a837ca9 100644 --- a/servers/hdmario.py +++ b/servers/hdmario.py @@ -8,8 +8,22 @@ baseUrl = 'https://hdmario.live' def test_video_exists(page_url): logger.info("(page_url='%s')" % page_url) global data + page = httptools.downloadpage(page_url) logger.info(page.url) + if 'unconfirmed' in page.url: + from lib import onesecmail + id = page_url.split('/')[-1] + mail = onesecmail.getRandom() + postData = { + 'email': mail, + 'hls_video_id': id + } + httptools.downloadpage(page.url, post=postData) + jsonMail = onesecmail.waitForMail(mail) + logger.info(jsonMail) + code = jsonMail['subject'].split(' - ')[0] + page = httptools.downloadpage(page_url + '?code=' + code) data = page.data if "the page you are looking for could not be found" in data: return False, config.get_localized_string(70449) % "HDmario"