ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.55k stars 10.05k forks source link

cannot download Twitter videos #29239

Open baptx opened 3 years ago

baptx commented 3 years ago

Checklist

Verbose log

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'https://twitter.com/ITA6768/status/1402200008896782339']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2021.06.06
[debug] Python version 2.7.18 (CPython) - Linux-5.4.0-74-generic-x86_64-with-Ubuntu-20.04-focal
[debug] exe versions: avconv 4.2.4, avprobe 4.2.4, ffmpeg 4.2.4, ffprobe 4.2.4, phantomjs 2.1.1, rtmpdump 2.4
[debug] Proxy map: {}
[twitter] 1402200008896782339: Downloading guest token
[twitter] 1402200008896782339: Downloading JSON metadata
[twitter] 1402200008896782339: Downloading m3u8 information
WARNING: Failed to download m3u8 information: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1946)
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on u'https://video.twimg.com/ext_tw_video/1402199786313424898/pu/vid/540x570/zZsUI6Z9S97aW919.mp4?tag=12'
ERROR: unable to open for writing: [Errno 36] File name too long: 'Info Trafic Alsace - \xe2\x9a\xa0\xef\xb8\x8f Rappel  - la vitesse maximale autoris\xc3\xa9e est de 25 km_h pour les trottinettes \xc3\xa9lectriques et celles-ci n\xe2\x80\x99ont pas leur place sur l\xe2\x80\x99autoroute, l\xe2\x80\x99acc\xc3\xa8s leur est strictement interdit !  (Vid\xc3\xa9o TikTok)  @PoliceNat67 @TopmusicAlsace @F3Alsace @ActuStrasbourg @strasbourg-1402200008896782339.mp4.part'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/downloader/http.py", line 260, in download
    ctx.tmpfilename, ctx.open_mode)
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/utils.py", line 2055, in sanitize_open
    stream = open(encodeFilename(filename), open_mode)
IOError: [Errno 36] File name too long: 'Info Trafic Alsace - \xe2\x9a\xa0\xef\xb8\x8f Rappel  - la vitesse maximale autoris\xc3\xa9e est de 25 km_h pour les trottinettes \xc3\xa9lectriques et celles-ci n\xe2\x80\x99ont pas leur place sur l\xe2\x80\x99autoroute, l\xe2\x80\x99acc\xc3\xa8s leur est strictement interdit !  (Vid\xc3\xa9o TikTok)  @PoliceNat67 @TopmusicAlsace @F3Alsace @ActuStrasbourg @strasbourg-1402200008896782339.mp4.part'

Description

It is currently not possible to download Twitter videos, for example with a command like youtube-dl https://twitter.com/ITA6768/status/1402200008896782339. I noticed I cannot download Twitter videos with ffmpeg / avconv also with a command like ffmpeg -i "https://video.twimg.com/ext_tw_video/1402199786313424898/pu/pl/p3a4JwGkun5ruVYR.m3u8?tag=12&container=fmp4" -c copy out.mp4 (using the M3U8 link found with Firefox Developer Tools in the Network tab):

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5649d08784c0] stream 0, offset 0x1290: partial file
https://video.twimg.com/ext_tw_video/1402199786313424898/pu/pl/p3a4JwGkun5ruVYR.m3u8?tag=12&container=fmp4: Invalid data found when processing input

The workaround is to use JavaScript code in the web console to record the video with captureStream and MediaRecorder APIs: https://gist.github.com/baptx/8a1549d91996a37378faca159b3adc17.

liamengland1 commented 3 years ago

First of all you should not be using python 2.7. Second of all, you must be joking with that "workaround", simply tell youtube-dl to name the file something else using the -o flag.

baptx commented 3 years ago

@llacb47 thanks, I switched to Python 3 (with this solution: https://askubuntu.com/questions/1065572/how-to-safely-switch-to-python3-as-default-after-upgrade-to-ubuntu-18-04/1143852#1143852). I did not pay attention to the error message "File name too long" and did not thought it would be that easy since ffmpeg failed too. Would it be possible to improve the user experience of youtube-dl by displaying a warning when the file name is too long and truncating the name instead of failing the download? Do you have an idea idea why ffmpeg fails? Maybe youtube-dl is doing something different than simply using the M3U8 link. I was not joking about the workaround, using captureStream with MediaRecorder has been useful for me when other solutions failed, for example to record a WebRTC stream or video blob (and it can be used for headless recording of DRM protected content also using Selenium WebDriver, like you could do with a screen recorder but closer to the source).

october262 commented 3 years ago

try like this > youtube-dl -o "%(id)s.%(ext)s" https://twitter.com/ITA6768/status/1402200008896782339

didotb commented 3 years ago

I'm not sure if OP meant to dl tw videos for a script or something, but in case it's solely for own entertainment I'll put this here anyway. Twitter has another "version" of it, mainly used by business personnel, it's called Tweetdeck. there all videos are downloadable as long as you know how to get to the tweet that's hosting the video.