ich arbeite derzeit and einem Sprachassistenten namens luna, der zugleich via telepot als bot genutzt werden kann. Ich habe ein Modul mit Hilfe von anderen Forumnutzern entwickelt, was einen Link, der per Telegram geschickt wird, als vollwertige Videodatei zurücksendet.
Dazu habe ich 2 Fragen:
1. Wird immer die beste Qualität genommen? An sich nutze ich dafür ja get_highest_resolution(), allerdings werden manche Videos in 720p heruntergeladen, obwohl der Link auf Youtube auf in 1080p gibt.
2. ich bekomme folgenden Fehler und denke, dass das was mit der Verbindung zu tun hat. wie kann ich diesen beheben?
Code: Alles auswählen
--JAKOB-- (Telegram): schick video
Analyse: {'town': None, 'room': None, 'rooms': [None], 'datetime': datetime.datetime(2020, 7, 14, 12, 39, 55, 999897), 'time': {'day': 14, 'month': 7, 'year': 2020, 'hour': 12, 'minute': 39, 'second': 55}}
False
Traceback (most recent call last):
File "LUNA_server.py", line 187, in query_threaded
if module.isValid(text):
AttributeError: module 'foto_to_telegram' has no attribute 'isValid'
[ERROR] Modul foto_to_telegram konnte nicht abgefragt werden!
--Modul video_to_telegram gestartet--
--LUNA--@Jakob (Telegram): Wie lautet die URL von dem Youtube-Video, das ich dir schicken soll?
--JAKOB-- (Telegram): https://www.youtube.com/watch?v=I2zT_TJfm_s&t=
--LUNA--@Jakob (Telegram): Video wird heruntergeladen. Bitte warte einen Moment.
<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">
Video heruntergeladen.
/home/pi/Desktop/LUNA/server/modules/resources/YouTube.mp4
Abbruch durch Fehler: ('Connection aborted.', OSError("(104, 'ECONNRESET')"))
--LUNA--@Jakob (Telegram): Es gab einen Fehler. Bitte versuche es erneut.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 317, in _send_until_done
return self.connection.send(data)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1737, in send
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1639, in _raise_ssl_error
raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (104, 'ECONNRESET')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.7/http/client.py", line 1244, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/lib/python3.7/http/client.py", line 987, in send
self.sock.sendall(data)
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 328, in sendall
sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 323, in _send_until_done
raise SocketError(str(e))
OSError: (104, 'ECONNRESET')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/LUNA/server/modules/video_to_telegram.py", line 37, in handle
send_video_to_telegram(luna, VIDEO_PATH)
File "/home/pi/Desktop/LUNA/server/modules/video_to_telegram.py", line 54, in send_video_to_telegram
luna.telegram.bot.sendVideo(uid, video=open(VIDEO_PATH, 'rb'), supports_streaming=True)
File "/usr/local/lib/python3.7/dist-packages/telepot/_init_.py", line 588, in sendVideo
return self._api_request_with_file('sendVideo', _rectify(p), 'video', video)
File "/usr/local/lib/python3.7/dist-packages/telepot/_init_.py", line 499, in _api_request_with_file
return self._api_request(method, _rectify(params), files, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/telepot/_init_.py", line 491, in _api_request
return api.request((self._token, method, params, files), **kwargs)
File "/usr/local/lib/python3.7/dist-packages/telepot/api.py", line 154, in request
r = fn(*args, **kwargs) # `fn` must be thread-safe
File "/usr/lib/python3/dist-packages/urllib3/request.py", line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "/usr/lib/python3/dist-packages/urllib3/poolmanager.py", line 323, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 692, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.7/http/client.py", line 1244, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/lib/python3.7/http/client.py", line 987, in send
self.sock.sendall(data)
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 328, in sendall
sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 323, in _send_until_done
raise SocketError(str(e))
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError("(104, 'ECONNRESET')"))
Video gelöscht
--Modul video_to_telegram beendet--
Code: Alles auswählen
#!/usr/bin/pythob
# -*- coding:utf-8 -*-
import pytube
import os
import traceback
def isValid(text):
text = text.lower()
if 'schicke' in text or 'schick' in text or 'sende' in text and 'video' in text:
return True
if 'lade' in text and 'youtubevideo' in text and 'herunter' in text:
return True
def handle(text, luna, profile):
SAVE_PATH = luna.path + '/modules/resources'
VIDEO_PATH = SAVE_PATH + '/YouTube.mp4'
luna.say('Wie lautet die URL von dem Youtube-Video, das ich dir schicken soll?', output='telegram')
response = luna.listen(input='telegram')
try:
luna.say('Video wird heruntergeladen. Bitte warte einen Moment.', output='telegram')
try:
youtube = pytube.YouTube(response)
except:
luna.say('Der Link konnte keinem Video zugeordnet werden.')
video = youtube.streams.get_highest_resolution()
print(video)
video.download(SAVE_PATH, filename="YouTube")
print('Video heruntergeladen.')
send_video_to_telegram(luna, VIDEO_PATH)
except Exception as e:
print(f"Abbruch durch Fehler: {e}")
luna.say('Es gab einen Fehler. Bitte versuche es erneut.')
traceback.print_exc()
try:
os.remove(VIDEO_PATH)
print('Video gelöscht')
except:
print('Video konnte nicht gelöscht werden.')
traceback.print_exc()
print('Klasse abgeschlossen')
def send_video_to_telegram(luna, VIDEO_PATH):
print(VIDEO_PATH)
try:
uid = luna.local_storage['LUNA_telegram_name_to_id_table'][luna.user]
luna.telegram.bot.sendVideo(uid, video=open(VIDEO_PATH, 'rb'), supports_streaming=True)
except KeyError as e:
Log.write('WARNING', 'Der Text "{}" konnte nicht gesendet werden, da für den Nutzer "{}" keine Telegram-ID angegeben wurde'.format(text, user), conv_id=original_command, show=True)
print(f"Abbruch durch Fehler: {e}")
traceback.print_exc()
Liebe Grüße,
Jakob