I'm trying to build a simple web application using PopcornJS in Python. I want to simply mute the volume of a youtube video and autoplay it but it seems to not be working/ there may be a bug in PopcornJS's youtube video player.
Here's my code:
<script>
var popcorn = Popcorn.youtube( "#video" , 'http://www.youtube.com/embed/XMW2lbNVaXY');
popcorn.volume(0);
popcorn.autoplay(true);
</script>
and the html
<div id="video"></div>
Seems like the volume control and the autoplay are not working. If I switch to a non youtube video everything works fine. Also if I look at my console during run time I see the following error
Blocked a frame with origin "http://www.youtube.com" from accessing
a frame with origin "http://127.0.0.1:5000". Protocols, domains,
and ports must match.
Googling the problem revealed that it might be a chrome bug, but I'm not sure. Anyone know what's wrong? Thanks!
Related
I've come across this cool tutorial Simple Augmented Reality With OpenCV, Three.js, And WebSockets. As you can see it is quite dated. I'm getting error OverconstrainedError on JS side while running the circle_detection_with_websocket_server.py using Pycharm IDE and then browsing the file:///C:/Users/MyUser/PycharmProjects/index.html (I'm not using localhost on browser, is this the problem?) at the same time.
/threejs_with_websockets.js
if (navigator.getUserMedia) {
navigator.getUserMedia(constrains, function(stream) {
video.src = window.URL.createObjectURL(stream);
video.oncanplay = function() {
init(video.clientWidth, video.clientHeight);
initEarth();
initMoon();
initLight();
initPlane();
requestAnimationFrame(render);
}
}, function(err) {
console.error(`The following error occurred: ${err.name}`);
});
I'm able to see circle x, y, radius Json data flowing from Python to JS but cannot see the streaming video from Python. I've the suspicion that the JS codes navigator.getUserMedia above is trying to access the same laptop camera that the Pycharm is already using. I was under the assumption from the author that the JS codes are supposed to ONLY wait and accept the video stream via Python Websocket.
Are you able to offer a NEWER Python WebSocket solution to live-stream video to a browser Three.JS HTML5??
I've searched high and low for such required solution on Google and Stackoverflow to no avail.
I do require backend to be in Python + OpenCV and frontend must be Browser + Three.JS.
Thank you so much.
I have been trying to download past broadcasts for a streamer on twitch using python. I found this python code online:
https://gist.github.com/baderj/8340312
However, when I try to call the functions I am getting errors giving me a status 400 message.
Unsure if this is the code I want to download the video (as an mp4) or how to use it properly.
And by video I mean something like this as an example: www(dot)twitch.tv/imaqtpie/v/108909385 //note cant put more than 3 links since I don't have 10 reputation
Any tips on how i should go about doing this?
Here's an example of running it in cmd:
python twitch_past_broadcast_downloader.py 108909385
After running it, it gave me this:
Exception API returned 400
This is where i got the information on running it:
https://www.johannesbader.ch/2014/01/find-video-url-of-twitch-tv-live-streams-or-past-broadcasts/
Huh it's not as easy at it seems ... The code you found on this gist is quite old and Twitch has completely changed its API. Now you will need a Client ID to download videos, in order to limit the amount of video you're downloading.
If you want to correct this gist, here are simple steps you can do :
Register an application : Everything is explained here ! Register you app and keep closely your client id.
Change API route : It is no longer '{base}/api/videos/a{id_}' but {base}/kraken/videos/{id_} (not sure about the last one). You will need to change it inside the python code. The doc is here.
Add the client id to the url : As said in the doc, you need to give a header to the request you make, so add a Client-ID: <client_id> header in the request.
And now I think you will need to start debugging a bit, because it is old code :/
I will try myself to do it and I will edit this answer when I'm finished, but try yourself :)
See ya !
EDIT : Mhhh ... It doesn't seem to be possible anyway to download a video with the API :/ I was thinking only links to API changed, but the chunks section of the response from the video url disappeared and Twitch is no longer giving access to raw videos :/
Really sorry I told you to do that, even with the API I think is no longer possible :/
You can download past broadcasts of Twitch videos with Python library streamlink.
You will need OAuth token which you can generate with the command
streamlink --twitch-oauth-authenticate
Download VODs with:
streamlink --twitch-oauth-token <your-oauth-token> https://www.twitch.tv/videos/<VideoID> best -o <your-output-folder>
I am trying to write a simple kik bot to send videos from youtube.
Started with https://github.com/kikinteractive/kik-bot-python-example
Modified it this way:
messages_to_send.append(
VideoMessage(
to=message.from_user,
chat_id=message.chat_id,
video_url="https://www.youtube.com/watch?v=WHATEVER"
))
But when try, i get an error like:
kik.error.KikError: {"message":"Error sending video message:
text/html; charset=utf-8 is not a supported
Content-Type","error":"BadRequest"}
Dont know from where is taking "text/html; charset=utf-8" because i ve defined is a VideoMessage(
Sorry if it is a silly question, i am noob with kik and python
Thanks in advance
I think the video_url parameter expects an URL that points to a video file. In the example from their docs the URL is "http://example.kik.com/video.mp4", meaning (in my opinion) that it should be a video file. In your example, "https://www.youtube.com/watch?v=WHATEVER" would point to an HTML file (i.e. not a video file).
Maybe you'll have to find (a) if YouTube provides a URL that returns a video mimetype (I bet they don't), or (b) use something as youtube-dl to download the MP4 file, uplaod it somewhere else and use this somewhere-else's URL in yourt code snipet. Or… (c) just send a text message with the YouTube URL : )
Does that make sense?
Full disclosure, I'm fairly new to Python and Selenium Webdriver.
I am expanding a small automation project that I've been working on. I have an in-browser chat window that, when a message is received, a file titled 'chime.mp3' will play to notify the user of a new message.
To verify the success that this audio file has played, I will need to verify that the file was called or requested via HTTP request, i.e. https://usr/bin/webapps/chime.mp3
Is there a module I could import in python, or a webdriver technique to listen for this file being requested?
Or is there a known way to verify audio files play on a certain event?
Any help is much appreciated.
To the best of my knowledge, there is no built-in functionality in Selenium (or Python) that you could use for that.
While you can't easily verify that the sound as actually been played however, you can easily verify whether your site has instructed the browser to play the file. Most likely, your site will use the HTML5 audio tag to actually play the file, and you can check for that:
Example (Java)
WebElement audio = driver.findElement(By.tagName("audio")); // make sure any audio tag is there
// ... or ...
WebElement audio = driver.findElement(By.xpath("//audio/source[contains(#src, 'chime.mp3')]/..")); // make sure an audio tag is there that refers to chime.mp3
assertTrue(Boolean.parseBoolean(audio.getAttribute("ended"))); // make sure the audio tag has played at least once
How can I take a scrennshot of flash website in Python 3.5.1. I trying something like this but I can't see video image.
from selenium import webdriver
def webshot(url, filename):
browser = webdriver.PhantomJS()
browser.get(url)
browser.save_screenshot(filename)
browser.quit()
webshot('https://www.youtube.com/watch?v=YQHsXMglC9A', 'screentest.png')
Short version : With Youtube system, if you didn't press that "play" button (initiate playback) there is no video served. Loading the page via browser is a form of initiating playback too. However using a webshot doesn't fulfill Youtube server's requirements so it wont work.
long version :
How can I take a screenshot of a Flash website... I tried this but I
can't see video image.
webshot('https://www.youtube.com/watch?v=YQHsXMglC9A', 'screentest.png')
You cannot screenshot Youtube's video player content like this. The way Youtube works is that when video page is ready, another PHP file is accessed to determine the video link (eg: the correct file for chosen quality settings, etc). Basically you have to appear to be like a browser making an HTTP request to their servers. Their server gives temporary token to access video link until token expires etc. There's other issues like CORS to deal with. These things are not being done by your tool.
If only Youtube used a normal <video tag> with simple MP4 link then your code would've worked.
The best you can get is like below (see how there is no controls?) using :
webshot('https://www.youtube.com/embed/YQHsXMglC9A', 'screentest.png')