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>
Related
Hello I have a selenium script in python which extract data with login on webpage. It take around 50 sec to execute and I want to deploy that script as an api. But API is getting timeout.
There we can also do one thing that we save that data in some google sheet using that script.
Please anyone can suggest how can i do this or any relevant content ?
Could you provide us a screenshot of API timeout or logs? Showing Python code with requests will be also helpful (sorry for answering instead of commenting because I don't have enough reputation points)
I am trying to get the data correlated with a user's feed tab on Instagram. Every time I google "get user feed" or anything similar, I am presented with how to get the recent photos that a user has posted.
However, I am trying to get the feed tab, or basically the trending posts of other people that I follow. I tried using Lev Pasha's Instagram API module, but the only related function that I could find was getPopularFeed(), which got posts from the explore page.
I know how to connect to the Instagram API and have done it using the code below, but have not managed to collect the feed tab.
from InstagramAPI import InstagramAPI
InstagramAPI = InstagramAPI("myusername", "mypassword")
InstagramAPI.login()
Update (6/2/2021):
I've decided to add a bit of info here regarding the Instagram API. I'd like to say that this answer is slightly "deprecated" in a sense, as the GitHub repo for this project has been taken down, and therefore it will become harder to develop updates and bug fixes for the module. As a result, I'd actually recommend that you don't use this module, as it will get you banned very quickly from the Instagram platform (the last update was in 2018, and therefore any User-Agent fixes and bot-detection workarounds will not be added).
I'd also like to say that as of now, there seem to be no good modules for the task of Instagram automation. As I've just said, the InstagramAPI module written in my post is long gone, and all the other API projects on Github are also archived / have no more moderation or updates.
TLDR: Maintaining an API which is being updated constantly by a huge corporation is not easy, and therefore you will get banned / blocked easily. I'd recommend using Lev Pasha's or ping's Instagram APIs, although they are both deprecated and might get you blocked quickly. The module in the answer below is also pretty good, although I've noticed that it hasn't been updated in almost 2 years. Also, it's built as a wrapper on top of ping's API.
You can use instapi module to solve your problem. Link to repo
Code example:
from instapi import bind, User
bind('myusername', 'mypassword')
user = User.from_username('some username')
for feed in user.iter_feeds():
# do something with feed
To install instapi using pip:
pip install git+https://github.com/uriyyo/instapi
import requests
from sys import exit
url = 'www.videohere.com'
while(True):
try:
requests.get(url)
except KeyboardInterrupt:
exit(0)
*Ok so i'm trying to use requests to view this video on this page but like just basically stay on the page as if it is watching i have no clue on how to go about doing it, so if anyone could give any suggestions or show a little poc please do! thanks guys.
What do you mean by using requests.get() to view video?
If you would like to make to the progress bar (I don't know what it is named, hope you can understand) to move on, you just need to post some data to the server. You don't need to really "get" the video.
For example, on a Chinese video sharing website BILIBILI, it use the heartbeat to record where you were. It will help if you close the webpage and open it again, it will notify you that you could restore to the second where you were watching.
On different websites, the method might be different. On YouTube, the key is encrypted, so it might be a little bit challenging to pretent your cralwer as a real person watching the video.
For the site you mentioned as mixed.com, in Developer Tools, you could find the following:
To give your a brief of posting data on this site, the url of site is
https://browser.events.data.microsoft.com/OneCollector/1.0/?cors=true&content-type=application/x-json-stream&client-id=NO_AUTH&client-version=1DS-Web-JS-2.0.0-rc3&apikey=1918f1672f934c5ca6b2669551351de2-b61c1f8e-4440-4e53-8e38-b46e4c88a7e5-7038&upload-time=1569343709069&w=0
Once you are in someone's websites, you can find out your browser keeps posting data to this target url every several seconds. Personally speaking, I think it is a tool to record the number of users watching in this room.
For https://browser.events.data.microsoft.com/OneCollector/1.0/ this part, we shall have the same url, but the residual should be generated by the contents in your requests headers.
What's more, the apikey and the payload in the following picture tell me that it is really tough for people to use crawler to pretending a real user.
Most part of it could be easily fetched from the website, but it might require delication for not making mistakes.
I have a problem that in theory should be easy, but I have been at this for days and just can't get it to work.
I have a Google account to which a few aliases are connected (The main gmail, a test thing I made a long time ago and a youtube channel). I render my videos on a cloud server and would like to then automatically upload them to this channel. I don't want to have to open the URL because this should work unattended. And by god, I can't figure it out. It's pretty baffling in how bad a state Google's official API docs are (or how dumb I am). I am using Python and Google's official client
So far, I've modified the python upload example from the python examples to incorporate service auth as described here. This alone took me way too long to figure out, I think Google's newer key format is bugged. If I run this as is, I get a "youtubeSignupRequired" error, because the main account doesn't have a youtube channel. After hours of research I found this link that pretty poorly describes the onBehalf parameters, but it seems these require a YouTube CMS account, which I don't have and I don't think I will get.
Am I missing something extremely obvious here? This seems like something that should not be hard to do at all.
I am trying to write an application which can archive your Facebook messages and their attachments, something similar to the amazing tool https://github.com/bnvk/social-archiver, but i have a problem with non-image attachments, say a audio file for example.
According to this View attachments in threads, the solution is the messaging.getattachment api call, with the proper parameters, now it looks like this is working for some people, but when i do it, through a browser direct call as well as with the python code mentioned before the response is always the same:
{"error_code":3,"error_msg":"Unknown method","request_args"
followed by all my parameters.
What am I doing wrong here? Is there something wrong with this api endpoint at this moment? Am I passing the parameters the wrong way? Maybe someone who got this working can put an example of how they passed their parameters(not the access token of course :() but maybe im putting the mid parameter the wrong way.
Any help appreciated.
The messaging.getattachment method is no longer available and only in use with Facebook Native mobile applications. You will need an access_token from one of the applications for example, Facebook Messenger for iPhone to use it.