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

youtube to stream #7807

Closed
no-paj opened this issue Dec 9, 2015 · 3 comments
Closed

youtube to stream #7807

no-paj opened this issue Dec 9, 2015 · 3 comments

Comments

@no-paj
Copy link

@no-paj no-paj commented Dec 9, 2015

Hello,

I would like to know if it is possible to make a python stream object from a youtube video ? If yes, how ?

Thank you for your responses :)

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Dec 9, 2015

What's a "python stream object"? Can you give some code snippets for what you've tried and what's your expectation?

@no-paj
Copy link
Author

@no-paj no-paj commented Dec 9, 2015

Typically a stream object is file = open("some_file_name.txt", 'r').
There are 3 types of stream object : Text, Binary and Raw.
What I can do is typically download the video with youtuve-dl embedded in my code and then use file = open("the_video", 'r').
But that's generating delay, it's not really what I want.

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Dec 9, 2015

You can use urlopen, either directly from urllib.urlopen or with YoutubeDL.urlopen:

import youtube_dl
ydl = youtube_dl.YoutubeDL({'format': 'best'})

info = ydl.extract_info('http://www.youtube.com/watch?v=BaW_jenozKcj', download=False)

f = ydl.urlopen(info['url'])
try:
    print(f.read(100))
finally:
    f.close()

which produces:

[youtube] BaW_jenozKc: Downloading webpage
[youtube] BaW_jenozKc: Downloading video info webpage
[youtube] BaW_jenozKc: Extracting video information
[youtube] BaW_jenozKc: Downloading DASH manifest
[youtube] BaW_jenozKc: Downloading DASH manifest
b'\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00isommp42\x00\x00\x14Qmoov\x00\x00\x00lmvhd\x00\x00\x00\x00\xce\xde\xfc\xd8\xce\xde\xfc\xd8\x00\x00\x02X\x00\x00\x17\x13\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00'
@jaimeMF jaimeMF closed this Dec 9, 2015
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.