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

Making a search without downloading anything #13436

Closed
mertyildiran opened this issue Jun 19, 2017 · 2 comments
Closed

Making a search without downloading anything #13436

mertyildiran opened this issue Jun 19, 2017 · 2 comments

Comments

@mertyildiran
Copy link

@mertyildiran mertyildiran commented Jun 19, 2017

Hi, I know it's possible to make a search with this command: youtube-dl "ytsearch:dank memes compilation"

I would like to be able to just make a search and get the URLs and Titles but not download anything.

My goal is using youtube-dl as a library or a tool in my project Dragonfire. I know youtube-dl is not a search tool but a downloader. But youtube-dl is maybe the only tool that guarantee to be always up to date with YouTube. So youtube-dl is the best option for such a task even if it's not the main purpose.

When I looked up to the source code, I found this function which is handling the request. So I have imported that part and tried to use it:

>>> from youtube_dl.extractor.youtube import YoutubeSearchIE
>>> a = YoutubeSearchIE()
>>> a._get_n_results('PewDiePie',1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/extractor/youtube.py", line 2497, in _get_n_results
    query={'spf': 'navigate'})
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/extractor/common.py", line 666, in _download_json
    encoding=encoding, data=data, headers=headers, query=query)
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/extractor/common.py", line 634, in _download_webpage
    res = self._download_webpage_handle(url_or_request, video_id, note, errnote, fatal, encoding=encoding, data=data, headers=headers, query=query)
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/extractor/common.py", line 531, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query)
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/extractor/common.py", line 492, in _request_webpage
    self.to_screen('%s: %s' % (video_id, note))
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/extractor/common.py", line 691, in to_screen
    self._downloader.to_screen('[%s] %s' % (self.IE_NAME, msg))
AttributeError: 'NoneType' object has no attribute 'to_screen'

I got an error probably because it's not suppose to be used as the way I tried to use. So if it's not possible to use youtube-dl in such a way then this issue is a feature request 😄

P.S. if the developers guide me then maybe I can implement this feature by myself and send a pull request...

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jun 19, 2017

https://github.com/rg3/youtube-dl#embedding-youtube-dl

info = ydl.extract_info('ytsearch:dank memes compilation', download=False, ie_key='YoutubeSearch')
// process info
@dstftw dstftw closed this Jun 19, 2017
@mertyildiran
Copy link
Author

@mertyildiran mertyildiran commented Jun 19, 2017

@dstftw thank you so much, this solved my problem:

from __future__ import unicode_literals
import youtube_dl

info = youtube_dl.YoutubeDL({}).extract_info('ytsearch:dank memes compilation', download=False, ie_key='YoutubeSearch')
info['entries'][0]['title']
info['entries'][0]['id']
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.