0

i wrote this program :

import scrapetube
import hashlib
import telegram
import requests
import json
from pytube import YouTube

from time import sleep
import os

bot_token = 'my token'
bot_chatID = '@PinkPanthersShow'

bot = telegram.Bot(token=f'{bot_token}')
c_videos = scrapetube.get_channel("UC1fIyfhQtm1fSljyKBf2uKA")
videos = list()
for video in c_videos:
   videos.append(f"https://www.youtube.com/watch?v={str(video['videoId'])}")
videos.reverse()
def upload_video(title, desc):
    bot.send_video(chat_id=bot_chatID, video=open(fr'{title}.mp4', 'rb'),caption=f"{desc}", supports_streaming=True)
for i in list(range(len(videos))):
    yt = YouTube(videos[i])
    print(f"{yt.title} : {videos[i]}")
    ys = yt.streams.get_highest_resolution()
    ys.download()
    upload_video(str(yt.title), str(yt.description))
#print (list(videos)[0])
#links.reverse()
#print(links)
#print(title)
#print(videos)
input()

When my program gets to the video The Pink Panther Show Episode 4 - Dial" P "for Pink: https://www.youtube.com/watch?v=tOaakSDwuZE, it gives this error:

Traceback (most recent call last):
  File "g:\yta\bot.py", line 43, in <module>
    upload_video(str(yt.title), str(yt.description))
  File "g:\yta\bot.py", line 37, in upload_video
    bot.send_video(chat_id=bot_chatID, video=open(fr'{title}.mp4', 'rb'),caption=f"{desc}", supports_streaming=True)
OSError: [Errno 22] Invalid argument: 'The Pink Panther Show Episode 4 - Dial "P" for Pink.mp4'

What can I do to avoid this error?

  • Does this answer your question? [OSError \[Errno 22\] invalid argument when use open() in Python](https://stackoverflow.com/questions/25584124/oserror-errno-22-invalid-argument-when-use-open-in-python) – CallMeStag Oct 12 '21 at 11:30

2 Answers2

0

If you want To send All videos Of a Youtube channel to telegram, you can use ytt, which is a module I have written:

https://nimafanniasl.github.io/py_youtube_to_telegram/

If you want to use an app , You can use ytt app, but if you want to use it in python, you can use ytt module, example:

pip install ytt

python app:

from ytt import ytt

ytt.start_all(YouTube_channel_id,telegram_bot_token,bot_chatID,send_channel_or_group_id=None)

# :)

More information: https://github.com/nimafanniasl/py_youtube_to_telegram/tree/main/module

cigien
  • 57,834
  • 11
  • 73
  • 112
  • ok, i want to use module, but i have this error: WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/ytt/ – Abbott Taft Nov 22 '21 at 16:31
  • 2
    Looks like you're the author of the linked modules. Please disclose your affiliation, *in the answer*, in order for your posts not to be considered spam - having the same text in your username as the domain is not considered suitable disclosure under SE policy. – Ollie Nov 22 '21 at 17:00
  • Hello! Yes! I am the developer of this module, but it is not spam or advertising! This library works perfectly and was useful to them as well. – nimafanniasl Nov 22 '21 at 19:29
0
    from pytube import YouTube
    from telebot import TeleBot
    
    yt = YouTube("https://www.youtube.com/watch?v=lOUsz0ggDsk")
    video = yt.streams.filter(file_extension="mp4").get_by_resolution("360p").download("./tmp")
    
    bot = TeleBot("Telegram Token")
    bot.send_video(230967203, open(video, 'rb'))
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 10 '22 at 09:52