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:ytabot.py", line 43, in <module>
upload_video(str(yt.title), str(yt.description))
File "g:ytabot.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?
2
Answers
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:
python app:
More information: https://github.com/nimafanniasl/py_youtube_to_telegram/tree/main/module