Closed pythonnoob2 closed 4 years ago
You need to assign response
as None
at the beginning of your program, like this: response = None
Then you have to put in the first line of the functions which use the variable: global response
here is the code https://pastebin.com/5wWC1SRs
Thank you for the fix! That corrected the error I was having, but I am not presented with another error.
An error has occurred while trying to use livestreamer package. Is it installed? Do you have Python in your PATH variable? Traceback (most recent call last): File "twitch-viewer.py", line 119, in <module> prepare_processes() File "twitch-viewer.py", line 106, in prepare_processes "url": get_url(), "proxy": { File "twitch-viewer.py", line 69, in get_url url = json.loads(response)['streams']['worst']['url'] File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer
Any ideas? I notice the errors are about livestreamer, which I have installed and can provide screenshot if needed, and the PATH error I'm not to sure about. I googled it but from what I found I think I have that done properly as well.
Is it just not working because livestreamer isn't working?
did you pip2 install livestreamer
or pip3 install livestreamer
?
I did. Here is everything that is installed for the project
I started a fresh project and I only have livestreamer and requests installed. I no longer get the above error, but now I get "An error has occurred while trying to get the stream data. Is the channel online? Is the channel name correct?" the channel is 100% live.
Edit: just to be clear. I am setting the channel name when running the script, not within the code. ex: python twitch-viewer.py CHANNELNAME
Do I need to add a viewer number after the channel name?
which OS are you using? send a screenshot what you do and the log.
There has been more development since my last update. I've switch to windows, was previously using Mac. I've removed livestreamer.exe and started using streamlink, since I found out livestreamer is dead and streamlink was the replacement. I am able to get passed the error I was having, but now when it gets to preparing process it just keeps showing period after period and nothing happens. No views, no errors, nothing. Just gets hung on the periods. See screenshot for more info.
Here is the code: https://pastebin.com/jxpRLYcE
Here is the screenshot: https://imgur.com/a/6uNrISt
how many lines do you have in proxylist.txt?
I wasn't sure what proxies to use (HTTP, Socks4 or Socks5) but I've tested with all 3. Each have over 1,000 lines. HTTP is 1,500. Socks4 is about 1200 and Socks5 is 8,600.
Should I limit those?
I wasn't sure what proxies to use (HTTP, Socks4 or Socks5) but I've tested with all 3. Each have over 1,000 lines. HTTP is 1,500. Socks4 is about 1200 and Socks5 is 8,600.
Should I limit those?
yes, the program will print "." for every line in the txt file Check line 4 in proxylist.txt
Ok, I will limit them to something much much smaller.
Line 4 looks like a normal IP to me. Something wrong with it? I am just using free poxies I've found on the web. Could also be my problem?
Ok, the bot is sending head requests now. I limited the lines to only 50. All the requests sent successfully but no views were added to the channel.
Edit: same results using the first 3 lines only. Maybe I need new proxies?
try only http
Ok, I can try searching for some reliable free http. I will update once I find some and test!
Thank you for all the help
does streamlink have the same arguments of livestreamer?
Honestly, no idea lol. I just saw that livestreamer was no longer supported and that streamlink was the new thing to use. I am a big noob when it comes to this stuff.
try to use "streamerlink.exe" on cmd.
I'm sorry, but how do I do that? I am very new to python. I do appreciate everything you've been helping with.
windows key + r then write cmd and in cmd write streamlink.exe
oh you meant windows cmd, sorry. Nothing runs when i type streamlink.exe. "not recognized"
You need to have the exe file in your twitch-viewer folder. You can create a shortcut
Ok, I will try and add that to the folder. See if it does anything. So installing streamlink with pip in python does nothing?
try https://github.com/streamlink/streamlink here is for windows: https://github.com/streamlink/streamlink/releases/tag/1.3.1
Ok, I have it downloaded now. my twitch viewer folder is only in python. So i have to add the exe in there? or I am stupid and its actually located somewhere in my users folder. So find it in my users folder and add the exe there?
Edit: found the users folder. No idea where the .exe for streamlink is. Found streamlink in C: Program Files, but I don't see an exe in there that i can copy and put in there or make a shortcut.
do you have windows 10?
I do. I made a shortcut to the streamlink folder in my twitch-viewer folder. Try rerunning code now?
I should be the exe. Search streamlink (using windows key)... right click and make shortcut
Ok, exe shortcut placed in the folder.
edit: rerun code in pycharm?
now try the python program. if not working try writing streamlink on cmd
same result. Send head requests but no views are going to channel. :(
but did streamlink work on cmd?
Yeah, it opens up and says this:
usage: streamlink [OPTIONS]
Use -h/--help to see the available options or read the manual at https://streamlink.github.io
ok we probably have only to change arguments in py file :) I hope...
I hope so too! So, how exactly do we change the arguments? I am sorry I am such a noob. Hence the name lol
here https://pastebin.com/eejTTTcH :)
I also might need to find new list of proxies. The ones I have might suck and not work
edit: ill trythat now!
oops I made a mistake.
I tried your updated code you just posted, but for some reason I am getting this error:
An error has occurred while trying to get the stream data. Is the channel online? Is the channel name correct?
Haven't had that happen in a while. The channel is still online
I have to edit more i think
i noticed there is no client ID in your new code following streamlink. Do we not need that? I assumed that is how we were making the connection to twitch.
but with streamlink?
In the old code it looked like this:
response = subprocess.Popen( ["livestreamer.exe", "--http-header", "Client-ID=ewvlchtxgqq88ru9gmfp1gmyt6h2b93", channel_url, "-j"], stdout=subprocess.PIPE).communicate()[0]
When I made edits to that I changed livestreamer.exe to streamlink.exe and changed the client ID to the new Twitch API ID (According to google).
Wasn't sure if that was needed or not and I noticed it's not in the new code you shared. I was just looking for differences lol no idea if its need at all.
I didnt read the whole doc, but it has to be similar to livestreamer https://pastebin.com/xGQemjW8
if not working you will have to add a print but first tell me the error and... yes I did put a print
Ok, so it throws a really big error, BUT the script keeps working and eventually sends the head requests. Doesn't add viewers though. Had to put this error in pastbin because it was massive lol
it wasnt an error, it was just a print() xD
it wasnt an error, it was just a print xD
oh haha ok. Never saw that before! Wasn't sure what it was lol
Any idea on why the views aren't actually being sent? Could it be the proxies or is this way possibly patched by twitch?
Does anyone know a fix for this error? I've tried looking around the web, but can't figure out how to fix it. I am new to python still.
Thanks