Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fd/external] Fix ffmpeg input from stdin #7655

Merged
merged 1 commit into from Jul 22, 2023

Conversation

bashonly
Copy link
Member

@bashonly bashonly commented Jul 21, 2023

The websockets downloader passes - to ffmpeg as input, and the new external FD cookies code was throwing

class FFmpegSinkFD(FileDownloader):
""" A sink to ffmpeg for downloading fragments in any form """
def real_download(self, filename, info_dict):
info_copy = info_dict.copy()
info_copy['url'] = '-'
async def call_conn(proc, stdin):
try:
await self.real_connection(stdin, info_dict)
except OSError:
pass
finally:
with contextlib.suppress(OSError):
stdin.flush()
stdin.close()
os.kill(os.getpid(), signal.SIGINT)
class FFmpegStdinFD(FFmpegFD):
@classmethod
def get_basename(cls):
return FFmpegFD.get_basename()
def on_process_started(self, proc, stdin):
thread = threading.Thread(target=asyncio.run, daemon=True, args=(call_conn(proc, stdin), ))
thread.start()
return FFmpegStdinFD(self.ydl, self.params or {}).download(filename, info_copy)

thanks to @JC-Chung for discovering the issue and providing this log:

[debug] Command-line config: ['-v', '-S', 'proto:ws', 'https://twitcasting.tv/msbsqn']
[debug] Encodings: locale cp950, fs utf-8, pref cp950, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.07.06 [b532a3481]
[debug] Lazy loading extractors is disabled
[debug] Python 3.9.6 (CPython AMD64 64bit) - Windows-10-10.0.19042-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: ffmpeg 2023-07-13-git-9a2335444b-full_build-www.gyan.dev (setts), ffprobe 2023-07-13-git-9a2335444b-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.12.07, mutagen-1.45.1, secretstorage-3.3.3, sqlite3-2.6.0, websockets-10.2
[debug] Proxy map: {}
[debug] Loaded 1857 extractors
[TwitCastingLive] Extracting URL: https://twitcasting.tv/msbsqn
[TwitCastingLive] msbsqn: Downloading webpage
[TwitCastingLive] msbsqn: Downloading live history
[TwitCasting] Extracting URL: https://twitcasting.tv/msbsqn/movie/772480442
[TwitCasting] 772480442: Downloading webpage
[TwitCasting] 772480442: Downloading live info
[TwitCasting] 772480442: Downloading m3u8 information
[TwitCasting] 772480442: Downloading source quality m3u8
[debug] Sort order given by user: proto:ws
[debug] Sort order given by extractor: source
[debug] Formats sorted by: hasvid, ie_pref, proto:ws(2), source, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, size, br, asr, vext, aext, hasaud, id
[debug] Default format spec: best/bestvideo+bestaudio
[info] 772480442: Downloading 1 format(s): ws-main
[debug] Invoking web_socket_fragment downloader on "wss://115-69-195-19.twitcasting.tv/tc.edge/v1/streams/772480442.1008.96/fmp4/solid"
[download] Destination: 花声天使🌸 2023-07-21 19_08 [772480442].mp4
ERROR: unknown url type: '-'
Traceback (most recent call last):
  File "site-packages\yt_dlp\YoutubeDL.py", line 1576, in wrapper
    return func(self, *args, **kwargs)
  File "site-packages\yt_dlp\YoutubeDL.py", line 1732, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "site-packages\yt_dlp\YoutubeDL.py", line 1791, in process_ie_result
    ie_result = self.process_video_result(ie_result, download=download)
  File "site-packages\yt_dlp\YoutubeDL.py", line 2930, in process_video_result
    self.process_info(new_info)
  File "site-packages\yt_dlp\YoutubeDL.py", line 3396, in process_info
    success, real_download = self.dl(temp_filename, info_dict)
  File "site-packages\yt_dlp\YoutubeDL.py", line 3117, in dl
    return fd.download(name, new_info, subtitle)
  File "site-packages\yt_dlp\downloader\common.py", line 455, in download
    ret = self.real_download(filename, info_dict)
  File "site-packages\yt_dlp\downloader\websocket.py", line 39, in real_download
    return FFmpegStdinFD(self.ydl, self.params or {}).download(filename, info_copy)
  File "site-packages\yt_dlp\downloader\common.py", line 455, in download
    ret = self.real_download(filename, info_dict)
  File "site-packages\yt_dlp\downloader\external.py", line 50, in real_download
    retval = self._call_downloader(tmpfilename, info_dict)
  File "site-packages\yt_dlp\downloader\external.py", line 562, in _call_downloader
    cookies = self.ydl.cookiejar.get_cookies_for_url(fmt['url'])
  File "site-packages\yt_dlp\cookies.py", line 1320, in get_cookies_for_url
    return self._cookies_for_request(urllib.request.Request(escape_url(sanitize_url(url))))
  File "urllib\request.py", line 320, in __init__
    self.full_url = url
  File "urllib\request.py", line 346, in full_url
    self._parse()
  File "urllib\request.py", line 375, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: '-'
Template

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check all of the following options that apply:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

Copilot Summary

🤖 Generated by Copilot at 35ee7b9

Summary

🐛🧪🍪

Fix a bug where yt-dlp would fail to download some websocket streams using ffmpeg. Add a test case for FFmpegFD and modify its _call_downloader method to handle non-http urls correctly.

yt-dlp fixes
websockets and cookies bugs
autumn stream flows well

Walkthrough

  • Fix a bug where yt-dlp would fail to download some websocket streams using ffmpeg (link, link)
    • Add a test case to test_make_cmd in test/test_downloader_external.py to check that non-url inputs are passed directly to ffmpeg (link)
    • Modify _call_downloader in yt_dlp/downloader/external.py to only get and pass cookies for http or https urls (link)

@bashonly bashonly added the bug Bug that is not site-specific label Jul 21, 2023
@bashonly bashonly merged commit e57eb98 into yt-dlp:master Jul 22, 2023
14 checks passed
@bashonly bashonly deleted the fix/ffmpeg-stdin branch December 7, 2023 15:13
aalsuwaidi pushed a commit to aalsuwaidi/yt-dlp that referenced this pull request Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is not site-specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant