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

ValueError when downloading a video from YouTube #7468

Closed
lalinsky opened this issue Nov 12, 2015 · 2 comments
Closed

ValueError when downloading a video from YouTube #7468

lalinsky opened this issue Nov 12, 2015 · 2 comments
Labels
bug

Comments

@lalinsky
Copy link
Contributor

@lalinsky lalinsky commented Nov 12, 2015

Downloading this video seems to fail:

$ PYTHONPATH=`pwd`  ./bin/youtube-dl --verbose --list-formats 'https://www.youtube.com/watch?v=Ms7iBXnlUO8'
[debug] System config: []
[debug] User config: []
[debug] Command-line args: [u'--verbose', u'--list-formats', u'https://www.youtube.com/watch?v=Ms7iBXnlUO8']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2015.11.10
[debug] Git HEAD: fcd817a
[debug] Python version 2.7.9 - Linux-3.19.0-33-generic-x86_64-with-Ubuntu-15.04-vivid
[debug] exe versions: ffmpeg 2.5.8-0ubuntu0.15.04.1, ffprobe 2.5.8-0ubuntu0.15.04.1, rtmpdump 2.4
[debug] Proxy map: {}
[youtube] Ms7iBXnlUO8: Downloading webpage
Traceback (most recent call last):
  File "./bin/youtube-dl", line 6, in <module>
    youtube_dl.main()
  File "/home/lukas/work/youtube-dl/youtube_dl/__init__.py", line 410, in main
    _real_main(argv)
  File "/home/lukas/work/youtube-dl/youtube_dl/__init__.py", line 400, in _real_main
    retcode = ydl.download(all_urls)
  File "/home/lukas/work/youtube-dl/youtube_dl/YoutubeDL.py", line 1666, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/home/lukas/work/youtube-dl/youtube_dl/YoutubeDL.py", line 661, in extract_info
    ie_result = ie.extract(url)
  File "/home/lukas/work/youtube-dl/youtube_dl/extractor/common.py", line 290, in extract
    return self._real_extract(url)
  File "/home/lukas/work/youtube-dl/youtube_dl/extractor/youtube.py", line 1080, in _real_extract
    ytplayer_config = json.loads(json_code)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Unterminated string starting at: line 1 column 6498 (char 6497)
@lalinsky
Copy link
Contributor Author

@lalinsky lalinsky commented Nov 12, 2015

The problem is that the video has keywords set to "info: {}});}, n);}};(function(w, startTick" (really) and the current regex cuts it in the middle. One possible fix would be to change the regex:

diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index 687e0b4..2173118 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -1074,7 +1074,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
             age_gate = False
             video_info = None
             # Try looking directly into the video webpage
-            mobj = re.search(r';ytplayer\.config\s*=\s*({.*?});', video_webpage)
+            mobj = re.search(r';ytplayer\.config\s*=\s*({.*?});ytplayer', video_webpage)
             if mobj:
                 json_code = uppercase_escape(mobj.group(1))
                 ytplayer_config = json.loads(json_code)
@yan12125 yan12125 added the bug label Nov 12, 2015
@lalinsky
Copy link
Contributor Author

@lalinsky lalinsky commented Nov 22, 2015

Another video affected by this - https://www.youtube.com/watch?v=lsguqyKfVQg

@dstftw dstftw closed this in 3cfd000 Nov 23, 2015
dstftw added a commit that referenced this issue Nov 23, 2015
[youtube] More explicit player config JSON extraction (fixes #7468)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.