Git Product home page Git Product logo

neet-nestor / telegram-media-downloader Goto Github PK

View Code? Open in Web Editor NEW
1.1K 11.0 104.0 1015 KB

A script allowing you to download images and videos from Telegram web even if the group restricts downloading.

Home Page: https://greasyfork.org/en/scripts/446342-telegram-media-downloader

License: GNU General Public License v3.0

JavaScript 100.00%
greasyfork greasymonkey greasymonkey-userscript javascript telegram userscript

telegram-media-downloader's Introduction

Telegram Media Downloader

Unlock Telegram: Download Anything You Like.

GitHub License Greasy Fork Version Greasy Fork Downloads

Overview

This script unlocks and enables download of images, GIFs, audios, and videos in Telegram webapps from chats, stories, and even private channels where downloading is disabled or restricted.

(Note: some features are only available for specific Telegram webapp version. e.g. Audio message download is only available for the K webapp version.)

Installation

Greasy Fork

  1. Install Tampermonkey or other user script browser extensions.

    (Note, If you are using Tampermonkey extension in a Chrome-based browser, following instructions to enable Developer Mode.)

  2. Install this script by visiting Greasy Fork: https://greasyfork.org/en/scripts/446342-telegram-media-downloader

Manual Installation

  1. Install Tampermonkey or other user script browser extensions.

    (Note, If you are using Tampermonkey extension in a Chrome-based browser, following instructions to enable Developer Mode.)

  2. Open Tampermonkey Dashboard, drag & drop src/tel_download.js into it and clicks the "install" button

How to Use

This script only works on Telegram Webapp.

For channels and chats that allow saving content, this script will have no effect. Please just use the official download button provided by the telegram webapp instead.

For channels and chats that disable downloading and restrict saving content, this script will add the download button back for images, GIFs and videos.

Image Download GIF Download Video Download Story Download

For videos, a progress bar will show on the bottom-right corder after you started downloading. For images and audios, there won't be a progress bar.

Supported Webapp Versions

There are 2 different versions of telegram webapps:

This script should work on both versions of webapp. If you are using another different version of webapp and find this script does not work, please raise an issue to our GitHub repo.

Check Downloading Progress

A progress bar will show on the bottom-right of the screen for videos. You can also check DevTools console for logs.

Support Author

If you like this script, you can support me via Venmo or buy me a coffee :)

telegram-media-downloader's People

Contributors

54m4d avatar europayou avatar hrukalive avatar neet-nestor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telegram-media-downloader's Issues

请问脚本会被限速吗?

我用这个脚本前两天速度突然开始变慢,速度下降一半不止,之前在挂上VPN上速度能有8M每秒,现在速度在几百kb至4MB之间跳跃,速度不稳定。
换上另一个脚本之后速度恢复,所以我比较奇怪。
(我是小白可能不懂这些,如果是我的问题请原谅,无意冒犯)
以下附图:
是我用本脚本和另外换的脚本速度对比图:
1 (1)
1 (2)

New version not working

Hi, sorry to open a new issue as the old one was just closed.

Thanks for the latest update however it does not work. I did not see a download icon after the update in either k or a version, even worse, the download function via the hide icon of the old version is also lost. Actually the download works pretty good before update using the hided icon in version k as long as you know it is there, just can not see it. I just downgraded to the old version and everything is fine. Please look for any conflict in the updated version.

can not download

I ues it in version k ,it show download button.But when i click it,it doesn't work.

下载后有两个文件?/Two files after download?

我的任务下载后有两个文件,无论我下载的什么格式的视频,将会有一个为crswap为后缀名的文件。例如我下载一个mp4文件,下载完成后我的mp4是0字节,但是多出来的crswap文件需要我手动改为mp4才能成为能播放的文件。开发者可以帮助我解决吗?或者是代码的问题,希望开发者能解决。谢谢~

My quest has two files after download, no matter what format video I download, there will be a file with the suffix crswap. For example, I download an mp4 file, after downloading my mp4 is 0 bytes, but the extra crswap file needs me to manually change to mp4 to become a playable file. Can developers help me solve this? Or it's a code problem, and I hope developers can solve it. thank you ~

"Save As" dialog box

hi, sorry for my bad english. The scripts really work with me, thanks. Anyway, can u add "Save As" dialog box? i want to save file in many folder different. Thank you very much, you're the Best!

下载过大的视频会OOM

首先感谢开发人员的辛苦付出!
现在下一些大的视频(大概1g左右)就会出现OOM。我的电脑是DDR4 16G 2666频率,我有什么方法可以避免此情况吗?或者说是无法避免的?希望得到解答,十分感谢。
(应该不需要配图吧,现在在公司无法配图)

No issue

I see you changed the download button placement, so no issues.

404 error when run tel_download_video locally

作者

请求作者的联系方式,我想拜他为师

Opera browser out of memory error

Hello, when I click the download button in the video on screen, Opera page is turned of and getting "Out of memory" error. That's why?

it is not work on firefox

i try to use Edge and it work, but on firefox when i click download it it said Undefined - Aborted

not work

doesn't seem to work anymore no download button on the video

The download prompt box cannot be closed.

When using the latest version 1.101, I found that after the download is complete, the prompt box cannot be closed, which obscures the content I still want to continue downloading. Can the expert solve this issue? The browser is Chrome.

Add support for GIFs

Currently there is no support for GIFs. It will be better if we have support for GIFs.

Edit: Some GIFs wont download while others download for some reason?

Instalação do script

Estou tentando instalar o script e está dando erro. acho que deu algum problema no link de instalação do script

IDM

Hi, i wonder why this code can't be forward the download to idm
thanks

Doesn't work for videos on Firefox

When using Firefox all videos I try to download show 9 bytes for file size and they never download correctly. I can download them just like I would on Chrome, but they end up being 9 byte files with mp4 extension.

I can't download an audio

Hi
I have been downloading audio from the channel couple of weeks ago, but i can not do it now. There is not even any button "download"
2024-01-22_14-40-24

"Syntax error?"

The script's name is crossed with a red line, and there's a little note at the top that says "Syntax error?". I use Firefox.

Edit, here's a screenshot. Also, it works on Chrome fine, but not on Firefox. I use Violentmonkey for both browsers.
image

Stop working with https://web.telegram.org/k

Hi, thanks for your code, it worked perfectly for me during the past week. Unfortunately since yesterday it stopped working when I use https://web.telegram.org/k. The download icons disappeared. I reinstalled both Tampermonkey and your downloader but still not working.

Interestingly, when I switch to https://web.telegram.org/a, the download icons appeared and I could download the videos, but very slow, and I have to wait until the progress to 100% in background then the browser will save the file, like you described. The file name seems to be random as well. However, when it worked well with the telegram K version last week, I could see the download progress in Chrome downloads icon, just like normal downloading, and the file name is the real name from the telegram.

Another thing is when I use Firefox, the download still does not work with https://web.telegram.org/k, no download icons just the same as in Chrome. However the icons will appear in https://web.telegram.org/a, but when I try to download, the file saved is only 9 bytes for every video.

In summary, now the downloader only works on Chrome with https://web.telegram.org/a, and seems to be less effective compared with previous time. I guess it is due to some updates from Telegram? Look forward to your update version to fix these bugs. It is a really good program, thank you guys!

New features?

A few months ago I updated the code and added new features. If you allow me, I think I will move these features here.

Features:

  • - Automatic download Removed due to potential misuse.
  • - Learn image size (I couldn't do it for video)
  • - Open media in a new tab
  • - Download audio files (Will resolve #19)
  • - Download received texts

No icons visible

Currently running Telegram Web A 1.60.10 (web and webz.telegram.org) on chrome Version 112.0.5615.49 (Official Build) (arm64)

Not seeing any buttons available, script shows that it's initialized in the console :/

Doesn't work because of the issue

Hey guys! Can someone help me please? Yesterday when I downloaded the code it actually worked, videos very slowly but downloaded but today stopped. I used your instructions and checked the devpage and it shows this
Знімок екрана 2023-12-03 о 03 51 21
Can someone help please?

SLow Download

After 37 mins its only completed 52% of a 400mb file. Why is the download so slow? Using Chrome browser.

Broken on firefox

The last update made the script stop working in Firefox.

Uncaught DOMException: Document.querySelectorAll: 'audio-element:has(.audio-waveform)' is not a valid selector

A simple alternative script (WebK only)

Hello!

I was inspired by your work and made an alternative script: GreasyFork

Attaching the code here as well.

Telegram Web - Allow Saving Content
// ==UserScript==
// @name         Telegram Web - Allow Saving Content
// @namespace    c0d3r
// @license      MIT
// @version      0.4
// @description  Bypass Telegram's saving content restrictions for media and text; batch download media from selected messages
// @author       c0d3r
// @match        https://web.telegram.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=telegram.org
// @grant        unsafeWindow
// @grant        GM_addStyle
// ==/UserScript==
 
// Extract media from message and download to disc
function downloadMediaFromMessage(msg) {
    var myMedia;
 
    if (msg.media) {
        // Extract the media object; simple alternative to getMediaFromMessage
        myMedia = msg.media.document || msg.media.photo;
    }
 
    if (myMedia) {
        // Download media using the built-in function; auto sets file name and extension
        unsafeWindow.appDownloadManager.downloadToDisc({media: myMedia});
    }
}
 
// Throttle download of multiple medias by 1 second
function slowDown(secs, msg, btnElm, btnTxt, btnIco) {
    setTimeout(function () {
        btnElm.disabled = true;
        btnElm.style.opacity = 0.6;
        btnTxt.textContent = '..' + (secs + 1) + '..';
        btnIco.textContent = '🕔';
 
        downloadMediaFromMessage(msg);
    }, secs * 1000);
}
 
// Get message object then download
async function downloadSingleMedia(pid, mid) {
    // Get the message object based on peer and message ID
    var msg = await unsafeWindow.mtprotoMessagePort.getMessageByPeer(pid, mid);
 
    downloadMediaFromMessage(msg);
}
 
// Download multiple medias from selected messages
async function downloadSelectedMedia() {
    var msgs = await unsafeWindow.appImManager.chat.selection.getSelectedMessages();
    var secs = 0;
 
    var btnElm = document.querySelector('#batch-btn');
    var btnTxt = btnElm.querySelector('.i18n');
    var btnIco = btnElm.querySelector('.mytgico');
 
    msgs.forEach(function (msg, ind) {
        // Only process messages with media
        if (msg.media && (msg.media.document || msg.media.photo)) {
            slowDown(secs, msg, btnElm, btnTxt, btnIco);
            secs++;
        }
 
        // Reset the batch button after last download
        if (ind === msgs.length - 1) {
            setTimeout(function () {
                btnElm.disabled = false;
                btnElm.style.opacity = 1;
                btnTxt.textContent = 'D/L';
                btnIco.textContent = '📥';
            }, secs * 1000);
        }
    });
}
 
(function () {
    'use strict';
 
    if (window.location.pathname.startsWith('/a/')) {
        // Redirect to the WebK version from the WebA version
        window.location.replace(window.location.href.replace('.org/a/', '.org/k/'));
    } else {
        // The root element used for watching and listening
        var colCenter = document.querySelector('#column-center');
 
        // Array of class names for media; we only add Download button if these are right clicked
        var clArray = ['photo', 'audio', 'video', 'voice-message', 'media-round', 'grouped-item', 'document-container', 'sticker'];
 
        // HTML code for the Download button
        var btnHtml = '<div class="btn-menu-item rp-overflow" id="down-btn"><span class="mytgico btn-menu-item-icon" style="font-size: 16px;">📥</span><span class="i18n btn-menu-item-text">Download</span></div>';
 
        // HTML code for the batch D/L button
        var batchBtnHtml = '&nbsp;&nbsp;<button class="btn-primary btn-transparent text-bold" id="batch-btn" title="Download Media"><span class="mytgico" style="padding-bottom: 2px;">📥</span>&nbsp;<span class="i18n">D/L</span></button>';
 
        // A flag for checking if we need to add the Download button
        var needBtn = false;
 
        // Variables for the current message and peer ID
        var curMid, curPid, observer;
 
        // Add CSS styles to allow text selection
        GM_addStyle('.chat.no-forwards .bubbles, .bubble, .bubble-content { -webkit-user-select: text!important; -moz-user-select: text!important; user-select: text!important; }');
 
        colCenter.addEventListener('mouseup', function (e) {
            // Listen to the right mouse button clicks
            if (e.button === 2) {
                needBtn = false;
                // Test if the current chat has restricted content saving
                if (document.querySelector('.chat.no-forwards')) {
                    // Find the closest element containing message and peer IDs
                    var closest = e.target.closest('[data-mid]');
                    if (closest) {
                        // Check if the element actually contains some media classes
                        if (clArray.some(function (clName) {
                            return closest.classList.contains(clName);
                        })) {
                            curMid = closest.dataset.mid;
                            curPid = closest.dataset.peerId;
                            needBtn = true;
                        }
                    }
                }
            }
        });
 
        observer = new MutationObserver(function (mutList) {
            mutList.forEach(function (mut) {
                mut.addedNodes.forEach(function (anod) {
                    // Check if context menu has been added to the DOM
                    if (anod.id === 'bubble-contextmenu' && needBtn) {
                        // Add the custom Download button and assign a click event
                        anod.querySelector('.btn-menu-item').insertAdjacentHTML('beforebegin', btnHtml);
                        anod.querySelector('#down-btn').addEventListener('click', function () {
                            downloadSingleMedia(curPid, curMid);
                        });
                    }
 
                    // Check if selection popup has been added to the DOM
                    if (anod.classList && anod.classList.contains('selection-wrapper')) {
                        anod.querySelector('.selection-container-left').insertAdjacentHTML('beforeend', batchBtnHtml);
                        anod.querySelector('#batch-btn').addEventListener('click', function () {
                            downloadSelectedMedia();
                        });
                    }
                });
            });
        });
 
        // Observe when context menu is added to the DOM
        observer.observe(colCenter, {
            subtree: true, childList: true
        });
    }
})();
It only works on the WebK version (and redirects to it from WebA). Uses some built-in functions I found in the global objects.

Supports any type of media and auto sets file names and extensions.

Feel free to reuse any parts of this code, as well as adapt it for WebA. I don't plan to add WebA support myself.

tg-down-demo

working fine even on mobile but ...

working fine even on mobile but ...in order to be able to see the download arrow I ve got to swith ask desktop site (related to viewport not really to the userAgent ),if possible adapt layout even on telegram and mobile browser like fenix or kiwi thank you very much !

Telegram restricted the Web API: Script stopped working

Hi,

Preasumably Telegram recently changed its API and now, downloading restricted media from web browser is no longer allowed. This is the user facing message:

image

And the GET request triggered by the script download button returns a 404 upon Telegram endpoint call 😢

Is there any chance to make it work on the future?
Thanks

Renaming the script?

I begin to think that maybe "Telegram Media Downloader" is not the best name. Should we rename the script to give it more attentions?

Ideas:

  • Telegram Video Downloader
  • Telegram Private Video Downloader
  • Telegram Downloader
  • Others?

resuming.....

downloader works great but some videos get stuck and just endlessly say resuming.

404 HTTP Response with X-Frame-Options Deny on Firefox with Greasemonkey

Got 404 response in Firefox with Greasemonkey instead of 206. The script works fine if I run the script directly in console but not using Greasemonkey.

Response.haeders:
Array [ "content-length", "153" ]
Array [ "content-type", "text/html" ]
Array [ "date", "Sat, 09 Sep 2023 06:39:00 GMT" ]
Array [ "server", "nginx/1.18.0" ]
Array [ "x-firefox-spdy", "h2" ]
Array [ "x-frame-options", "deny" ]

some suggestions....

1.The script should support downloading via IDM or PikPak, as the browser download speed is too slow.
2.Remove restrictions on forwarding and other limitations."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.