From 78236dea8d10882b2d41c84ab7f9465a2baadf1f Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Mon, 7 Jun 2021 09:33:16 +0530 Subject: [PATCH 01/14] =?UTF-8?q?=F0=9F=92=84=20Custom=20font=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/header.html | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/templates/header.html b/app/templates/header.html index 06a89ac..35a82c2 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -7,6 +7,18 @@ + + + + + {% if title %} {{title}} {% else %} Telegram Index {% endif %} @@ -15,9 +27,9 @@ -
+
- Telegram Index + tgindex {% if authenticated %} Logout {% else %} {% endif %}
From 18702721c678e49f37e04c13f6ca06e16a879f6d Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Thu, 10 Jun 2021 14:25:44 +0530 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=90=9B=20improved=20hash=20generati?= =?UTF-8?q?ng=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/__init__.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/views/__init__.py b/app/views/__init__.py index a8ed5c3..3df6137 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -31,24 +31,21 @@ class Views( ): def __init__(self, client): self.client = client - + self.url_len = SHORT_URL_LEN self.chat_ids = {} def generate_alias_id(self, chat): chat_id = chat.id title = chat.title while True: - # alias_id = "".join( - # [ - # random.choice(string.ascii_letters + string.digits) - # for _ in range(len(str(chat_id))) - # ] - # ) orig_id = f"{title}{chat_id}" # the original id - alias_id = base64.urlsafe_b64encode(hashlib.md5(orig_id.encode()).digest())[:SHORT_URL_LEN].decode() - + alias_id = base64.urlsafe_b64encode(hashlib.md5(orig_id.encode()).digest())[:self.url_len].decode() + if alias_id in self.chat_ids: + self.url_len += 1 # increment url_len just incase the hash is already used. continue + elif (self.url_len > SHORT_URL_LEN): # reset url_len to initial if hash was unique. + self.url_len = SHORT_URL_LEN self.chat_ids[alias_id] = { "chat_id": chat_id, From 597bb051c03d394c95c4913815b3aeec245df5b0 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Fri, 11 Jun 2021 23:33:57 +0530 Subject: [PATCH 03/14] =?UTF-8?q?=F0=9F=9A=B8=20=20PORT=20error=20shown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/config.py b/app/config.py index 67e9a76..a513e53 100644 --- a/app/config.py +++ b/app/config.py @@ -8,7 +8,8 @@ import os try: port = int(os.environ.get("PORT", "8080")) -except ValueError: +except Exception as e: + print(e) port = -1 if not 1 <= port <= 65535: print( From 54880ce3399c8da7ce09d9abfe80a455c73810f7 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Fri, 11 Jun 2021 23:34:40 +0530 Subject: [PATCH 04/14] =?UTF-8?q?=F0=9F=9A=B8=20show=20the=20host=20url=20?= =?UTF-8?q?in=20title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/header.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/templates/header.html b/app/templates/header.html index 35a82c2..ead6e53 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -15,7 +15,13 @@ @@ -29,7 +35,7 @@
- tgindex + Telegram index {% if authenticated %} Logout {% else %} {% endif %}
From 6799af0572575f95c127276e380bba3ae40d7400 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Fri, 11 Jun 2021 23:36:14 +0530 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=9A=B8=20=E2=9C=A8=20=F0=9F=92=84?= =?UTF-8?q?=20New=20Search=20bar,=20Download=20button=20for=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/index.html | 148 +++++++++++++++++++++++++-------------- 1 file changed, 96 insertions(+), 52 deletions(-) diff --git a/app/templates/index.html b/app/templates/index.html index d728131..36607a2 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,59 +1,103 @@ {% include 'header.html' %} - -
-
- -

{{name}}

-
- -
-
- -
-
- -
- - {% if item_list %} -
-
- {% for item in item_list %} - - - {% if item.media %} - -
{{item.insight}}
- {% else %} -
{{item.insight}}
- {% endif %} - -
- {% endfor %} +
+
+ +

{{name}}

+
+ +
+
+ +
+
+ +
+ +
+
- -
-

- {{item_list|length}} items -

- -
- {% if prev_page %} - Page {{prev_page.no}} - {% endif %} -

Page {{cur_page}}

- {% if next_page %} - Page {{next_page.no}} - {% endif %} -
- + +
+ +
+ +{% if item_list %} + +
+
+ {% for item in item_list %} + +
+ +
{{item.file_id}}
+ + + {% if item.media %} + + + + +
{{item.insight}}
+ + + + + + + + + + {% else %} - -

- No message to display! -

- + +
{{item.insight}}
+
{% endif %} -{% include 'footer.html' %} +
+ + + {% endfor %} +
+ +
+ +

+ {{item_list|length}} items +

+ +
+ {% if prev_page %} + Page {{prev_page.no}} + {% endif %} +

+ Page {{cur_page}}

+ {% if next_page %} + Page {{next_page.no}} + {% endif %} +
+ +{% else %} + +

+ No message to display! +

+ +{% endif %} + +{% include 'footer.html' %} \ No newline at end of file From d067faed7b4cc05b7c5d312d433ba1d98a935c16 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Fri, 11 Jun 2021 23:37:48 +0530 Subject: [PATCH 06/14] =?UTF-8?q?=F0=9F=A9=B9=20add=20alias=20duplication?= =?UTF-8?q?=20avoiding=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/__init__.py b/app/views/__init__.py index 3df6137..538848e 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -37,12 +37,14 @@ class Views( def generate_alias_id(self, chat): chat_id = chat.id title = chat.title + while True: - orig_id = f"{title}{chat_id}" # the original id - alias_id = base64.urlsafe_b64encode(hashlib.md5(orig_id.encode()).digest())[:self.url_len].decode() + orig_id = f"{chat_id}" # the original id + unique_hash = hashlib.md5(orig_id.encode()).digest() + alias_id = base64.urlsafe_b64encode(unique_hash).decode()[:self.url_len] if alias_id in self.chat_ids: - self.url_len += 1 # increment url_len just incase the hash is already used. + self.url_len += 1 # increment url_len just incase the hash is already used. continue elif (self.url_len > SHORT_URL_LEN): # reset url_len to initial if hash was unique. self.url_len = SHORT_URL_LEN From db5e09d9a592f97c0b7071656fcf04caade0380d Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Fri, 11 Jun 2021 23:39:02 +0530 Subject: [PATCH 07/14] =?UTF-8?q?=E2=99=BF=EF=B8=8F=20download=20url=20inc?= =?UTF-8?q?luded=20for=20item=20result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/index_view.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/index_view.py b/app/views/index_view.py index 0d46e1d..05df79e 100644 --- a/app/views/index_view.py +++ b/app/views/index_view.py @@ -59,6 +59,7 @@ class IndexView: insight=get_file_name(m), human_size=get_human_size(m.file.size), url=f"/{alias_id}/{m.id}/view", + download=f"{alias_id}/{m.id}/download", ) elif m.message: entry = dict( From 0c4f8130f68e48e515756d4b0e038e1e6be8ab03 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Fri, 11 Jun 2021 23:40:08 +0530 Subject: [PATCH 08/14] =?UTF-8?q?=F0=9F=A5=85=20catch=20thumbnail=20out=20?= =?UTF-8?q?of=20bounds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/thumbnail_view.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/thumbnail_view.py b/app/views/thumbnail_view.py index 16f819a..737c9f6 100644 --- a/app/views/thumbnail_view.py +++ b/app/views/thumbnail_view.py @@ -46,7 +46,12 @@ class ThumbnailView: body = temp.getvalue() else: thumb_pos = int(len(thumbnails) / 2) - thumbnail = self.client._get_thumb(thumbnails, thumb_pos) + try: + thumbnail = self.client._get_thumb(thumbnails, thumb_pos) + except Exception as e: + logging.debug(e) + thumbnail = None + if not thumbnail or isinstance(thumbnail, types.PhotoSizeEmpty): return web.Response( status=410, From 23e291318b8e6b4352e07cd5075f7a0647169b6b Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Sat, 12 Jun 2021 21:00:52 +0530 Subject: [PATCH 09/14] =?UTF-8?q?=E2=9C=A8=20Streaming=20enabled=20using?= =?UTF-8?q?=20v.mp4=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/routes.py b/app/routes.py index e0b028d..487fd88 100644 --- a/app/routes.py +++ b/app/routes.py @@ -30,6 +30,8 @@ async def setup_routes(app, handler): web.get(p + r"/{id:\d+}/download", h.download_get), web.head(p + r"/{id:\d+}/download", h.download_head), web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get), + web.get(p + r"/{id:\d+}/v.mp4", h.download_get), + web.head(p + r"/{id:\d+}/v.mp4", h.download_head), ] if index_all: # print(await client.get_dialogs()) From 3e13a35f9e7dc595a5a3ab02338cc4cb45202c6e Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Sat, 12 Jun 2021 21:01:19 +0530 Subject: [PATCH 10/14] =?UTF-8?q?=F0=9F=99=88=20.vscode=20ignored?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 31468fb..4f3eb8b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ tests/ logo/ app.json Procfile -.vscode +.vscode/ .gitignore \ No newline at end of file From 67883eab1977d99ee022be46882b88e6609760d3 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Sat, 12 Jun 2021 21:04:26 +0530 Subject: [PATCH 11/14] =?UTF-8?q?=E2=9E=95=20=E2=9C=A8=20m3u=20Playlist=20?= =?UTF-8?q?export=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/js/filesaver.min.js | 2 ++ app/templates/js/playlist.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 app/templates/js/filesaver.min.js create mode 100644 app/templates/js/playlist.js diff --git a/app/templates/js/filesaver.min.js b/app/templates/js/filesaver.min.js new file mode 100644 index 0000000..a6f0e37 --- /dev/null +++ b/app/templates/js/filesaver.min.js @@ -0,0 +1,2 @@ +//# sourceMappingURL=FileSaver.min.js.map +(function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(a,b,c){var d=new XMLHttpRequest;d.open("GET",a),d.responseType="blob",d.onload=function(){g(d.response,b,c)},d.onerror=function(){console.error("could not download file")},d.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),g=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!a?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(b,d,e,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),"string"==typeof b)return c(b,d,e);var h="application/octet-stream"===b.type,i=/constructor/i.test(f.HTMLElement)||f.safari,j=/CriOS\/[\d]+/.test(navigator.userAgent);if((j||h&&i||a)&&"undefined"!=typeof FileReader){var k=new FileReader;k.onloadend=function(){var a=k.result;a=j?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=a:location=a,g=null},k.readAsDataURL(b)}else{var l=f.URL||f.webkitURL,m=l.createObjectURL(b);g?g.location=m:location.href=m,g=null,setTimeout(function(){l.revokeObjectURL(m)},4E4)}});f.saveAs=g.saveAs=g,"undefined"!=typeof module&&(module.exports=g)}); diff --git a/app/templates/js/playlist.js b/app/templates/js/playlist.js new file mode 100644 index 0000000..ff73986 --- /dev/null +++ b/app/templates/js/playlist.js @@ -0,0 +1,26 @@ +function singleItemPlaylist(file,name){ + let hostUrl = 'http://' + window.location.host + let pd = "" + pd += '#EXTM3U\n' + pd += `#EXTINF: ${name}\n` + pd += `${hostUrl}/${file}\n` + let blob = new Blob([pd], { endings: "native" }); + saveAs(blob, `${name}.m3u`); +} + +// function createPlaylist(indexSite, id, playlistName = "Playlist", duration = 60) { +// let pd = "" +// name = playlistName +// pd += '#EXTM3U\n' +// pd += `#EXTINF: ${duration * 60} | ${name}\n` +// pd += `${indexSite}/${id}/v.mp4\n` +// return pd +// } + +// function playlist(id, name) { +// hostUrl = 'https://' + window.location.host +// playlistData = createPlaylist(hostUrl, id, name); +// let blob = new Blob([playlistData], { endings: "native" }); +// saveAs(blob, `${name}.m3u`); +// } + From 4b40fdf5c613a50554b14a7049f492eb554f2970 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Sat, 12 Jun 2021 21:05:35 +0530 Subject: [PATCH 12/14] =?UTF-8?q?=F0=9F=94=A7=20add=20vlc=20url=20to=20ent?= =?UTF-8?q?ry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/index_view.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/index_view.py b/app/views/index_view.py index 05df79e..faa7fbb 100644 --- a/app/views/index_view.py +++ b/app/views/index_view.py @@ -60,6 +60,7 @@ class IndexView: human_size=get_human_size(m.file.size), url=f"/{alias_id}/{m.id}/view", download=f"{alias_id}/{m.id}/download", + vlc = f"{alias_id}/{m.id}/v.mp4", ) elif m.message: entry = dict( From bcdeb5f2ffdac82ce076c83f61e6dc5913f6bd5f Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Sun, 13 Jun 2021 11:27:57 +0530 Subject: [PATCH 13/14] =?UTF-8?q?=E2=9C=A8=20Add=20download,=20m3u=20,stre?= =?UTF-8?q?am=20buttons=20for=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/index.html | 88 +++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/app/templates/index.html b/app/templates/index.html index 36607a2..56a221e 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,5 +1,13 @@ {% include 'header.html' %} + +{% block javascript %} + +{% endblock %} +
@@ -9,58 +17,90 @@
- -
-
- -
- -
-
-
-
+
+
+ +
+ +
+
+
+ +
{% if item_list %} -
-
+
+
{% for item in item_list %} +
+ class="text-sm flex flex-col items-center justify-center w-full min-h-full md:w-1/5 lg:w-1/6 rounded my-4 md:mx-1 shadow hover:shadow-md border-solid ">
{{item.file_id}}
- {% if item.media %} + - -
{{item.insight}}
+ + - +
{{item.insight}}
+ - - + + + + + + + + + + + + +
+ {% else %} -
{{item.insight}}
+
{{item.insight}}
{% endif %} From fe8a9ba92e9574ac6b5a43de464ef4f35b90b7a4 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Sun, 13 Jun 2021 11:30:45 +0530 Subject: [PATCH 14/14] =?UTF-8?q?=F0=9F=92=AB=20Change=20shadow=20for=20ca?= =?UTF-8?q?rds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/home.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/home.html b/app/templates/home.html index ef5bb33..214831c 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -8,7 +8,7 @@