diff --git a/Dockerfile b/Dockerfile index 70362a2..92026fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,11 +6,12 @@ RUN pip3 install --user -r /tmp/requirements.txt && rm /tmp/requirements.txt FROM python:alpine -RUN apk update && apk add --no-cache ffmpeg +RUN apk update && apk add --no-cache ffmpeg git COPY --from=builder /root/.local /usr/local COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo COPY . /ytdl-bot +RUN cd /ytdl-bot && git submodule update --init --recursive && apk del git WORKDIR /ytdl-bot ENV TZ=Asia/Shanghai diff --git a/README.md b/README.md index fac25c7..2df028b 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,35 @@ Download videos from YouTube and other platforms through a Telegram Bot Send link from YouTube directly to the bot. Any platform [supported by youtube-dl](https://ytdl-org.github.io/youtube-dl/supportedsites.html) will also work. +# Feature +![](assets/1.jpeg) + +1. fast download and upload. Many thanks to [FastTelethon](https://gist.github.com/painor/7e74de80ae0c819d3e9abcf9989a8dd6) and +[JasonKhew96](https://github.com/JasonKhew96)'s contribution on this! +2. ads free - I'll never send ads to you, also I don't even print logs that will identify you. + So feel free to download any type of video from any website. + +3. support progress bar + # How to deploy? ## Normal +1. clone code and update submodule `git submodule update --init --recursive` 1. install Python 3.6+ 2. pip3 install -r requirements.txt 3. set environment variables `TOKEN`, `APP_ID` and `APP_HASH` 4. `python3 bot.py` 5. supervisor on your own preference. + ## docker see [here](https://github.com/tgbot-collection/BotsRunner) +# commdands +``` +start - let's start +about - wanna contribute? +ping - bot running status +help - it's not working? +ytdl - download video in group +``` # License Apache License 2.0 diff --git a/assets/1.jpeg b/assets/1.jpeg new file mode 100644 index 0000000..88334b5 Binary files /dev/null and b/assets/1.jpeg differ diff --git a/ytdl.py b/ytdl.py index 06d9d44..dcc43dd 100644 --- a/ytdl.py +++ b/ytdl.py @@ -18,15 +18,19 @@ import functools import fakeredis import youtube_dl -from FastTelethon.FastTelethon import upload_file + from hachoir.metadata import extractMetadata from hachoir.parser import createParser +from hachoir.metadata.video import MkvMetadata + from telethon import TelegramClient, events from telethon.tl.types import DocumentAttributeFilename, DocumentAttributeVideo from telethon.utils import get_input_media -from hachoir.metadata.video import MkvMetadata + from tgbot_ping import get_runtime +from FastTelethon.FastTelethon import upload_file + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(filename)s [%(levelname)s]: %(message)s') token = os.getenv("TOKEN") or "17Zg" @@ -141,9 +145,14 @@ async def echo_all(event): chat_id = event.message.chat_id url = re.sub(r'/ytdl\s*', '', event.message.text) logging.info("start %s", url) + # if this is in a group/channel + if not event.message.is_private and not event.message.text.lower().startswith("/ytdl"): + logging.info("%s, it's annoying me...🙄️ ", event.message.text) + return if not re.findall(r"^https?://", url.lower()): await event.reply("I think you should send me a link. Don't you agree with me?") return + message = await event.reply("Processing...") temp_dir = tempfile.TemporaryDirectory() @@ -172,7 +181,7 @@ async def echo_all(event): ), DocumentAttributeFilename( os.path.basename(video_path)), - ] + ] input_media.mime_type = mime_type await bot.send_file(chat_id, input_media) await bot.edit_message(chat_id, message, 'Download success!✅') @@ -193,13 +202,13 @@ def get_metadata(video_path): duration=metadata.get('duration').seconds, w=metadata['video[1]'].get('width'), h=metadata['video[1]'].get('height') - ), metadata.get('mime_type') + ), metadata.get('mime_type') else: return dict( duration=metadata.get('duration').seconds, w=metadata.get('width'), h=metadata.get('height') - ), metadata.get('mime_type') + ), metadata.get('mime_type') except Exception as e: logging.error(e) return dict(duration=0, w=0, h=0), 'application/octet-stream'