use of youtube-dl in my own python script #622

Closed
opened 2026-02-20 21:18:39 -05:00 by deekerman · 10 comments
Owner

Originally created by @yasoob on GitHub (Apr 26, 2013).

I am trying to make a youtube downloading website and was going to use youtube-dl in my site. I wanted to know that how can i just get the variables with the results instead of results being printed on the screen.
for example if i run the main.py file with the url i get the printed output but i want that if i import Infoextractors file and then pass it a url it can give me back a variable possibly a list with the result which i can access for further use. Can anyone illustrate this with an example. I would be really grateful to you guys.

Originally created by @yasoob on GitHub (Apr 26, 2013). I am trying to make a youtube downloading website and was going to use youtube-dl in my site. I wanted to know that how can i just get the variables with the results instead of results being printed on the screen. for example if i run the **main**.py file with the url i get the printed output but i want that if i import Infoextractors file and then pass it a url it can give me back a variable possibly a list with the result which i can access for further use. Can anyone illustrate this with an example. I would be really grateful to you guys.
Author
Owner

@rg3 commented on GitHub (Apr 26, 2013):

On Fri, Apr 26, 2013, at 12:58, yasoob wrote:

I am trying to make a youtube downloading website and was going to use
youtube-dl in my site. I wanted to know that how can i just get the
variables with the results instead of results being printed on the
screen.
for example if i run the main.py file with the url i get the printed
output but i want that if i import Infoextractors file and then pass it a
url it can give me back a variable possibly a list with the result which
i can access for further use. Can anyone illustrate this with an example.
I would be really grateful to you guys.

Side note: I should have separated the output methods to a different
class instead of including them in the downloader class when I rewrote
the program long ago. That could be a welcome change if the current
maintainers decide to do it, IMHO.

@rg3 commented on GitHub (Apr 26, 2013): On Fri, Apr 26, 2013, at 12:58, yasoob wrote: > I am trying to make a youtube downloading website and was going to use > youtube-dl in my site. I wanted to know that how can i just get the > variables with the results instead of results being printed on the > screen. > for example if i run the **main**.py file with the url i get the printed > output but i want that if i import Infoextractors file and then pass it a > url it can give me back a variable possibly a list with the result which > i can access for further use. Can anyone illustrate this with an example. > I would be really grateful to you guys. Side note: I should have separated the output methods to a different class instead of including them in the downloader class when I rewrote the program long ago. That could be a welcome change if the current maintainers decide to do it, IMHO.
Author
Owner

@rg3 commented on GitHub (Apr 26, 2013):

Ouch, I shouldn't have quoted the original message while replying by
mail. I'll repeat my comment below.

Side note: I should have separated the output methods to a different
class instead of including them in the downloader class when I rewrote
the program long ago. That could be a welcome change if the current
maintainers decide to do it, IMHO.

@rg3 commented on GitHub (Apr 26, 2013): Ouch, I shouldn't have quoted the original message while replying by mail. I'll repeat my comment below. Side note: I should have separated the output methods to a different class instead of including them in the downloader class when I rewrote the program long ago. That could be a welcome change if the current maintainers decide to do it, IMHO.
Author
Owner

@jaimeMF commented on GitHub (Apr 26, 2013):

You should look at the method extract_info in FileDownloader, it returns a list of info dictionaries for each element founded.

@jaimeMF commented on GitHub (Apr 26, 2013): You should look at the method `extract_info` in FileDownloader, it returns a list of info dictionaries for each element founded.
Author
Owner

@yasoob commented on GitHub (Apr 27, 2013):

it is not working. It is throwing exceptions........ like the params does
not have a get method. Perhaps you can explaina bit more with an example?

On Fri, Apr 26, 2013 at 10:21 PM, Jaime Marquínez Ferrándiz <
notifications@github.com> wrote:

You should look at the method extract_info in FileDownloader, it returns
a list of info dictionaries for each element founded.


Reply to this email directly or view it on GitHubhttps://github.com/rg3/youtube-dl/issues/806#issuecomment-17087730
.

@yasoob commented on GitHub (Apr 27, 2013): it is not working. It is throwing exceptions........ like the params does not have a get method. Perhaps you can explaina bit more with an example? On Fri, Apr 26, 2013 at 10:21 PM, Jaime Marquínez Ferrándiz < notifications@github.com> wrote: > You should look at the method extract_info in FileDownloader, it returns > a list of info dictionaries for each element founded. > > — > Reply to this email directly or view it on GitHubhttps://github.com/rg3/youtube-dl/issues/806#issuecomment-17087730 > .
Author
Owner

@jaimeMF commented on GitHub (Apr 27, 2013):

What are the errors you get?
For example this is what I use:

class NoneFile(object):
    '''
    A file-like object that does nothing
    '''
    def write(self,msg):
        pass
    def flush(self,*args,**kaargs):
        pass
    def isatty(self):
        return False

class ScreenFile(NoneFile):
    def write(self,msg):
        logging.debug(msg)

class SimpleFileDownloader(youtube_dl.FileDownloader):
    def __init__(self,*args,**kargs):
        super(SimpleFileDownloader,self).__init__(*args,**kargs)
        self._screen_file=ScreenFile()
        self._ies = youtube_dl.gen_extractors()
        for ie in self._ies:
            ie.set_downloader(self)

Then I can do:

fd = SimpleFileDownloader({'outtmpl':'%(title)s'})
results = fd.extract_info(url, download = False)

This will get the videos information.

@jaimeMF commented on GitHub (Apr 27, 2013): What are the errors you get? For example this is what I use: ``` python class NoneFile(object): ''' A file-like object that does nothing ''' def write(self,msg): pass def flush(self,*args,**kaargs): pass def isatty(self): return False class ScreenFile(NoneFile): def write(self,msg): logging.debug(msg) class SimpleFileDownloader(youtube_dl.FileDownloader): def __init__(self,*args,**kargs): super(SimpleFileDownloader,self).__init__(*args,**kargs) self._screen_file=ScreenFile() self._ies = youtube_dl.gen_extractors() for ie in self._ies: ie.set_downloader(self) ``` Then I can do: ``` python fd = SimpleFileDownloader({'outtmpl':'%(title)s'}) results = fd.extract_info(url, download = False) ``` This will get the videos information.
Author
Owner

@yasoob commented on GitHub (Apr 28, 2013):

this is the whole input and the error which i get after following your method

import youtube_dl
class NoneFile(object):
... '''
... A file-like object that does nothing
... '''
... def write(self,msg):
... pass
... def flush(self,_args,__kaargs):
... pass
... def isatty(self):
... return False
...
class ScreenFile(NoneFile):
... def write(self,msg):
... logging.debug(msg)
...
class SimpleFileDownloader(youtube_dl.FileDownloader):
... def init(self,_args,**kargs):
... super(SimpleFileDownloader,self).init(*args,**kargs)
... self._screen_file=ScreenFile()
... self._ies = youtube_dl.gen_extractors()
... for ie in self._ies:
... ie.set_downloader(self)
...
fd = SimpleFileDownloader({'outtmpl':'%(title)s'})
results = fd.extract_info("http://www.dailymotion.com/video/xy8ddj_zindagi-gulzar-hai-by-hum-tv-episode-16-part-1-3_shortfilms", download = False)
Traceback (most recent call last):
File "", line 1, in
File "youtube_dl/FileDownloader.py", line 466, in extract_info
ie_results = ie.extract(url)
File "youtube_dl/InfoExtractors.py", line 96, in extract
return self._real_extract(url)
File "youtube_dl/InfoExtractors.py", line 803, in _real_extract
webpage = self._download_webpage(request, video_id)
File "youtube_dl/InfoExtractors.py", line 129, in _download_webpage
urlh = self._request_webpage(url_or_request, video_id, note, errnote)
File "youtube_dl/InfoExtractors.py", line 117, in _request_webpage
self.report_download_webpage(video_id)
File "youtube_dl/InfoExtractors.py", line 157, in report_download_webpage
self.to_screen(u'%s: Downloading webpage' % video_id)
File "youtube_dl/InfoExtractors.py", line 149, in to_screen
self._downloader.to_screen(u'[%s] %s' % (self.IE_NAME, msg))
File "youtube_dl/FileDownloader.py", line 197, in to_screen
self._screen_file.write(output)
File "", line 3, in write
NameError: global name 'logging' is not defined

@yasoob commented on GitHub (Apr 28, 2013): this is the whole input and the error which i get after following your method # > > > import youtube_dl > > > class NoneFile(object): > > > ... ''' > > > ... A file-like object that does nothing > > > ... ''' > > > ... def write(self,msg): > > > ... pass > > > ... def flush(self,_args,__kaargs): > > > ... pass > > > ... def isatty(self): > > > ... return False > > > ... > > > class ScreenFile(NoneFile): > > > ... def write(self,msg): > > > ... logging.debug(msg) > > > ... > > > class SimpleFileDownloader(youtube_dl.FileDownloader): > > > ... def **init**(self,_args,**kargs): > > > ... super(SimpleFileDownloader,self).**init**(*args,**kargs) > > > ... self._screen_file=ScreenFile() > > > ... self._ies = youtube_dl.gen_extractors() > > > ... for ie in self._ies: > > > ... ie.set_downloader(self) > > > ... > > > fd = SimpleFileDownloader({'outtmpl':'%(title)s'}) > > > results = fd.extract_info("http://www.dailymotion.com/video/xy8ddj_zindagi-gulzar-hai-by-hum-tv-episode-16-part-1-3_shortfilms", download = False) > > > Traceback (most recent call last): > > > File "<stdin>", line 1, in <module> > > > File "youtube_dl/FileDownloader.py", line 466, in extract_info > > > ie_results = ie.extract(url) > > > File "youtube_dl/InfoExtractors.py", line 96, in extract > > > return self._real_extract(url) > > > File "youtube_dl/InfoExtractors.py", line 803, in _real_extract > > > webpage = self._download_webpage(request, video_id) > > > File "youtube_dl/InfoExtractors.py", line 129, in _download_webpage > > > urlh = self._request_webpage(url_or_request, video_id, note, errnote) > > > File "youtube_dl/InfoExtractors.py", line 117, in _request_webpage > > > self.report_download_webpage(video_id) > > > File "youtube_dl/InfoExtractors.py", line 157, in report_download_webpage > > > self.to_screen(u'%s: Downloading webpage' % video_id) > > > File "youtube_dl/InfoExtractors.py", line 149, in to_screen > > > self._downloader.to_screen(u'[%s] %s' % (self.IE_NAME, msg)) > > > File "youtube_dl/FileDownloader.py", line 197, in to_screen > > > self._screen_file.write(output) > > > File "<stdin>", line 3, in write > > > NameError: global name 'logging' is not defined > > > > > > #
Author
Owner

@jaimeMF commented on GitHub (Apr 28, 2013):

Sorry, I forgot to mention that you needed to include the logging module, add import logging at the start of the file. (I use it because I didn't want to get the messages in the screen)

@jaimeMF commented on GitHub (Apr 28, 2013): Sorry, I forgot to mention that you needed to include the logging module, add `import logging` at the start of the file. (I use it because I didn't want to get the messages in the screen)
Author
Owner

@yasoob commented on GitHub (Apr 28, 2013):

Thanx it worked.........:).........now i realize how much effort you guys
have put into making this.......you guys rock.......<3

On Sun, Apr 28, 2013 at 7:34 PM, Jaime Marquínez Ferrándiz <
notifications@github.com> wrote:

Sorry, I forgot to mention that you needed to include the logging module,
add import logging at the start of the file. (I use it because I didn't
want to get the messages in the screen)


Reply to this email directly or view it on GitHubhttps://github.com/rg3/youtube-dl/issues/806#issuecomment-17134942
.

@yasoob commented on GitHub (Apr 28, 2013): Thanx it worked.........:).........now i realize how much effort you guys have put into making this.......you guys rock.......<3 On Sun, Apr 28, 2013 at 7:34 PM, Jaime Marquínez Ferrándiz < notifications@github.com> wrote: > Sorry, I forgot to mention that you needed to include the logging module, > add import logging at the start of the file. (I use it because I didn't > want to get the messages in the screen) > > — > Reply to this email directly or view it on GitHubhttps://github.com/rg3/youtube-dl/issues/806#issuecomment-17134942 > .
Author
Owner

@yasoob commented on GitHub (Apr 29, 2013):

hey sorry for bothering you again . Now the problem is that my script is working great and is producing the download links........you can visit it on yasoobcode.appspot.com but now the problem is that when i click on download button the download page gives me a 403 forbidden header......Is there some problem with my header.......does youtube and other websites require some different header and if so how can i accomplish this that when the user clicks on download button the video starts to download.......Btw i am making this in flask.

I hope to hear from you guys soon. Thanx for your previous help as well

@yasoob commented on GitHub (Apr 29, 2013): hey sorry for bothering you again . Now the problem is that my script is working great and is producing the download links........you can visit it on yasoobcode.appspot.com but now the problem is that when i click on download button the download page gives me a 403 forbidden header......Is there some problem with my header.......does youtube and other websites require some different header and if so how can i accomplish this that when the user clicks on download button the video starts to download.......Btw i am making this in flask. I hope to hear from you guys soon. Thanx for your previous help as well
Author
Owner

@jaimeMF commented on GitHub (Apr 29, 2013):

I'm not sure this issues should be discussed here, so if you don't mind you can email me (see my profile).

@jaimeMF commented on GitHub (Apr 29, 2013): I'm not sure this issues should be discussed here, so if you don't mind you can email me (see my profile).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/youtube-dl#622
No description provided.