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

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

Closed
yasoob opened this issue Apr 26, 2013 · 10 comments
Closed

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

yasoob opened this issue Apr 26, 2013 · 10 comments

Comments

@yasoob
Copy link
Contributor

@yasoob yasoob commented 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.

@rg3
Copy link
Collaborator

@rg3 rg3 commented 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
Copy link
Collaborator

@rg3 rg3 commented 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.

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Apr 26, 2013

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

@yasoob
Copy link
Contributor Author

@yasoob yasoob commented 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//issues/806#issuecomment-17087730
.

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented 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.

@yasoob
Copy link
Contributor Author

@yasoob yasoob commented 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

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented 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)

@yasoob
Copy link
Contributor Author

@yasoob yasoob commented 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//issues/806#issuecomment-17134942
.

@yasoob
Copy link
Contributor Author

@yasoob yasoob commented 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 yasoob closed this Apr 29, 2013
@yasoob yasoob reopened this Apr 29, 2013
@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented 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).

@yasoob yasoob closed this May 1, 2013
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
3 participants
You can’t perform that action at this time.