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
I know how this may read to you but I am seriously out of ideas on this one.
I've written something in Python that can download stuff from Imgur using their API. I have an Authorization clientID and everything, and this thing works.
But sometimes I am getting a 400 HTML response status code with empty text when requesting a direct link so I can save the file. According to the doc this error will come back at you when you're missing a required parameter or if a part of your request is incorrect; this feels like a weird error to come back at me, when other requests get through just fine. The weirder part is that I can send 100 requests in 100 seconds, all will come back with 400 None. But once I open the image in my browser and view it, the request suddently changes to 200, everything works and this link will never throw a 400 ever again.
My friend suggestet that maybe it had something to do with my IP adress (getting flagged as a spam bot or whatever), so I opened the URLs via my phone on cellular, but as soon as the image loaded on my phone, the requests were successful. Also, when I tried finding more links with this strange behaviour, I tested a bunch of images from the imgur front page, and all worked fine. Combining this with the fact that I got the problematic links from very old reddit threads leaves me with the only idea that it has something to do with the age of the files or rather their last view date.
The requests happened via a code similar to:
headers = {'Authorization': f"Client-ID <id>"}
url = f"https://api.imgur.com/3/image/{fileID}"
requests.get(url, headers=headers)
I'm asking this here mainly because the Imgur API page says the best way to get help about the API is to post the problem here on stackoverflow. Maybe one of their engineers sees this and can answer my question or maybe someone else has an idea what may be going on here. In any case, I would be grateful for any useful input ^^
I am working on a project that scrapes multiple YouTube channels display name, creation date, subscriber count, and view count. I need help creating this project because I can't seem to find anything about it. I have a YouTube API Key and I just can't seem to find anything about this.
It's a little hard to work with the sample code that the YouTube api shows. Use the curl section. Then send a request to the link that shows and use the information. for example send http request to this:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=[Channel ID]&key=[Your API]
and this address give you JSON file and you can get what you want!.
for example you can see subscribe count from channel list section in youtube api document. like this image.
you can find other things with this way!. good luck :)
also you can use this.
i'm making sample for you.
def subscribeCount(channel_id):
API = f"https://youtube.googleapis.com/youtube/v3/channels?part=statistics&id={channel_id}&key=[Enter Your Api Key]"
json_data = requests.get(API).json()
subscribeCount = json_data['items'][0]['statistics']['subscriberCount']
return subscribeCount
this sample need channel id(Like all other sections xD). and api key you Which you got from the google developer console.It then shows you the number of subscriptions to a channel. The rest of the sections work the same way.
Read the following article for more information.
How to Use the Python Requests Module With REST APIs
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?
I am working on a telegram bot that displays images from several webcams upon request. I fetch the images from urls and then send to the user (using bot.sendPhoto() ) My problem is that for any given webcam the filename does not change and it seems that the photo is sent from telegram's cache. So it will display the image from the first time that image was requested.
I have thought about downloading the image from the url, saving with a variable name (like a name with a timestamp in it) then sending it to the chat, this seems like an inelegant solution and was hoping for something better. Like forcing the image not to be cached on the telegram server.
I am using the python-telegram-bot wrapper, but I am not sure that it's specific to that.
Any ideas? I have tried searching but so far am turning up little.
Thanks in advance.
I had the same problem too, but i've found the simplest solution.
When you call the image, you have to add a parameter with timestamp to the image link.
Example:
http://www.example.com/img/img.jpg?a=TIMESTAMP
Where TIMESTAMP is the timestamp function based on the language you are using.
Simple but tricky ;)
I think the best way is to do the same as we do in React where also, same URL calls are first checked in the cache.
If you are using Python the best way is:
timestamp = datetime.datetime.now().isoformat()
# Above statement returns like: '2013-11-18T08:18:31.809000'
pic_url = '{0}?a={1}'.format(img_url, timestamp)
Hope that helps!
I had the same problem. I wanted to create a bot which sends an image taken by a webcam of a ski slope (webcam.example.com/image.jpg). Unfortunately, the filename and so the url never updates and telegram always sends the cached image. So I decided to alter the url passed to the api. In order to achieve this, I wrote a simple php site (example.com/photo.php) which redirects to the original url of the photo. After that, I created a folder (example.com/getphoto/) on my webspace with a .htaccess file inside. The .htaccess redirects all request in this folder to the photo.php site which redirects to the image (webcam.example.com/image.jpg). So you could add everything to the url of the folder and still get the picture (e. g. example.com/getphoto/42 or example.com/getphoto/hrte8437g). The telegram api seems to cache photos by url, so if you add always another ending to the url passed to the api, telegram doesnt use the cached version and sends the current image instead. The easiest way to always change the url is by adding the current date to it.
example.com/photo.php
<?php
header("Location: http://webcam.example.com/image.jpg");
die();
?>
example.com/getphoto/.htaccess
RewriteEngine on
RewriteRule ^(.*)$ http://example.com/photo.php
in python:
bot.sendPhoto(chat_id, 'example.com/getphoto/' + strftime("%Y-%m-%d_%H-%M-%S", gmtime()))
This workaround should also work in other languages like java or php. You just need to change the way to get the current date.
I'm trying to upload a video to facebook from an external url. But I got error when I post it. I tried with local videos, and all works fine.
My simple code is :
answer = graph.post(
path="597739293577402/videos",
source='https://d3ldtt2c6t0t08.cloudfront.net/files/rhn4phpt3rh4u/2015/06/17/Z7EO2GVADLFBG6WVMKSD5IBOFI/main_OUTPUT.tmp.mp4',
)
and my error is allways the same :
FacebookError: [6000] There was a problem uploading your video file. Please try again with another file.
I looked into the docs and found the parameter file_url but it still the same issue.
The format of the video is .mp4 so it should work.
Any idea ?
Apparently this error message is very confusing. It's the same message when you've an access_token who doesn't work. For example, I've this error message when I'm trying with my user access token and not if I use the Page access token.
I've never used source, I'm pretty sure that's for reading video data off their API. Instead, I use file_url in my payload when passing video file URLs to Facebook Graph API.
Refer to their API doc for clarity on that...
It's also possible that the tmp.mp4 file extension is causing you problems. I've had issues with valid video URLs with non-typical file extensions similar to that. Is it possible to alter that at the source so that the URL doesn't have the tmp ?
A typical payload pass using Requests module to their API that works for me might look something like this:
fburl = 'https://graph-video.facebook.com/v2.3/156588/videos?access_token='+str(access)
payload = {'name': '%s' %(videoName), 'description': '%s' %(videoDescription), 'file_url': '%s' %(videoUrl)}
flag = requests.post(fburl, data=payload).text
print flag
fb_res = json.loads(flag)
I would also highly recommend that you obtain a permanent page access token. It's the best way to mitigate the complexities of Facebook's oAuth process.
facebook: permanent Page Access Token?