From c6b4c542b7caa6db51f743333f684b59ceef2ee1 Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Wed, 15 Apr 2020 13:54:24 +0530 Subject: [PATCH] fixup after e0f4c4347c75f557afdd829f3de7047315f9e9d2 - Also fixed copying of netrc file in the container Signed-off-by: lzzy12 --- Dockerfile | 9 +++++---- README.md | 7 +++++++ .../youtube_dl_download_helper.py | 20 ++++++++++++------- bot/modules/watch.py | 5 +++-- netrc | 0 5 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 netrc diff --git a/Dockerfile b/Dockerfile index d34ec7b..5fb7f5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,17 +2,18 @@ FROM ubuntu:18.04 WORKDIR /usr/src/app RUN chmod 777 /usr/src/app -RUN apt -qq update -RUN apt -qq install -y aria2 python3 python3-pip \ +RUN apt-get -qq update +RUN apt-get -qq install -y aria2 python3 python3-pip \ locales python3-lxml \ curl pv jq ffmpeg COPY requirements.txt . RUN pip3 install --no-cache-dir -r requirements.txt -COPY . . -RUN chmod +x aria.sh RUN locale-gen en_US.UTF-8 ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 +COPY . . +COPY netrc /root/.netrc +RUN chmod +x aria.sh CMD ["bash","start.sh"] diff --git a/README.md b/README.md index 8e14f78..9fb45fc 100644 --- a/README.md +++ b/README.md @@ -119,3 +119,10 @@ python3 gen_sa_accounts.py --download-keys project_id ``` python3 add_to_team_drive.py -d SharedTeamDriveSrcID ``` + +# Youtube-dl authentication using .netrc file +For using your premium accounts in youtube-dl, edit the netrc file (in the root directory of this repository) according to following format: +``` +machine host login username password my_youtube_password +``` +where host is the name of extractor (eg. youtube, twitch). Multiple accounts of different hosts can be added each separated by a new line \ No newline at end of file diff --git a/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py b/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py index 08f85c5..24657e9 100644 --- a/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py +++ b/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py @@ -21,12 +21,13 @@ class MyLogger: if match and not self.obj.is_playlist: self.obj.name = match.group(1) - def warning(self, msg): + @staticmethod + def warning(msg): LOGGER.warning(msg) - def error(self, msg): + @staticmethod + def error(msg): LOGGER.error(msg) - #self.obj.onDownloadError(msg) class YoutubeDLHelper(DownloadHelper): @@ -38,8 +39,9 @@ class YoutubeDLHelper(DownloadHelper): self.__gid = "" self.opts = { 'progress_hooks': [self.__onDownloadProgress], + 'logger': MyLogger(self), 'usenetrc': True, - 'format': "best" + 'format': "best/bestvideo+bestaudio" } self.__download_speed = 0 self.download_speed_readable = '' @@ -98,8 +100,12 @@ class YoutubeDLHelper(DownloadHelper): self.opts['geo_bypass_country'] = 'IN' with YoutubeDL(self.opts) as ydl: - result = ydl.extract_info(link, download=False) - name = ydl.prepare_filename(result) + try: + result = ydl.extract_info(link, download=False) + name = ydl.prepare_filename(result) + except DownloadError as e: + self.onDownloadError(str(e)) + return if result.get('direct'): return None if 'entries' in result: @@ -133,9 +139,9 @@ class YoutubeDLHelper(DownloadHelper): self.onDownloadError("Download Cancelled by User!") def add_download(self, link, path): + self.extractMetaData(link) LOGGER.info(f"Downloading with YT-DL: {link}") self.__gid = f"{self.vid_id}{self.__listener.uid}" - self.opts['logger'] = MyLogger(self) if not self.is_playlist: self.opts['outtmpl'] = f"{path}/{self.name}" else: diff --git a/bot/modules/watch.py b/bot/modules/watch.py index 80148b8..9754fc4 100644 --- a/bot/modules/watch.py +++ b/bot/modules/watch.py @@ -1,8 +1,8 @@ from telegram.ext import CommandHandler, run_async from telegram import Bot, Update -from bot import Interval, INDEX_URL, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, dispatcher, LOGGER +from bot import Interval, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, dispatcher, LOGGER from bot.helper.ext_utils.bot_utils import setInterval -from bot.helper.telegram_helper.message_utils import update_all_messages, sendMessage +from bot.helper.telegram_helper.message_utils import update_all_messages, sendMessage, sendStatusMessage from .mirror import MirrorListener from bot.helper.mirror_utils.download_utils.youtube_dl_download_helper import YoutubeDLHelper from bot.helper.telegram_helper.bot_commands import BotCommands @@ -24,6 +24,7 @@ def _watch(bot: Bot, update: Update, args: list, isTar=False): listener = MirrorListener(bot, update, isTar, tag) ydl = YoutubeDLHelper(listener) ydl.add_download(link, f'{DOWNLOAD_DIR}{listener.uid}') + sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) diff --git a/netrc b/netrc new file mode 100644 index 0000000..e69de29