adwisatya / twitterspaces2text Goto Github PK
View Code? Open in Web Editor NEWExtracting Twitter Spaces text/caption easily given Twitter Spaces ID
License: MIT License
Extracting Twitter Spaces text/caption easily given Twitter Spaces ID
License: MIT License
Hello,
So I've tried jumping into a live twitter space that has already started.
Let's say I would like to grab the transcript from the beginning to capture what I have missed.
So I go ahead and grab the spaces id and insert it.
The script does capture from the start of the stream through the timestamp that the script was initialized.
The script works for both 'recorded by host' and 'non-recorded by host' streams.
It completes the output as desired.
As you would expect, there is an error generated eventually since the spaces has not ended yet as follows:
[start]
C:\path>py twitspace07-10-21.py >> test301a.txt
Traceback (most recent call last):
File "C:\Python\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Python\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Python\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\path\twitspace07-10-21.py", line 4, in
extractor.getCaption("1ZkJzbbELoaJv")
File "C:\Python\lib\site-packages\TwitterSpaces2Text\Extractor.py", line 50, in getCaption
raw_data = self.getCurrentCaption(cursor)
File "C:\Python\lib\site-packages\TwitterSpaces2Text\Extractor.py", line 40, in getCurrentCaption
json={"access_token":self.access_token ,"cursor":cursor,"limit":1000,"since":None,"quick_get":True}).json()
File "C:\Python\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[end]
So, I think, no problem, i'll just delete the initial output text file and rerun the script a few minutes later to capture a longer transcript.
However, the problems start if I try to rerun the same script for the same space id subsequently.
The intent is to replace the already downloaded transcript by extending the transcript timeframe beyond the initially downloaded timeframe.
What happens is that the output will keep ending at the same initial timestamped request point (despite the fact that the script is being initialized with a much later timestamp while the space is still live, or for a recorded stream rerunning after the stream has ended)
Thanks in advance.
Hi, it seems that this script is using some Periscope APIs.
This surprised me a bit, since Periscope has been deprecated already.
Is there a way to achieve something similar with only the Twitter API?
KeyError Traceback (most recent call last)
Cell In [118], line 2
1 # %%
----> 2 extractor.getCaption("1YqGopyVqkvJv")
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/TwitterSpaces2Text/Extractor.py:44, in Extractor.getCaption(self, spaces_id)
42 self.spaces_id = spaces_id
43 self.setGuestToken()
---> 44 self.setMediaKey()
45 self.setChatToken()
46 self.setAccessToken()
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/TwitterSpaces2Text/Extractor.py:29, in Extractor.setMediaKey(self)
27 data['variables']["withReplays"] = True
28 data['variables']["withScheduledSpaces"] = True
---> 29 self.media_key = requests.get('https://twitter.com/i/api/graphql/jyQ0_DEMZHeoluCgHJ-U5Q/AudioSpaceById',
30 headers={"x-guest-token":self.guest_token,"Authorization":self.bearer_token,'Content-Type':'application/json'},
31 json=data).json()['data']['audioSpace']['metadata']['media_key']
KeyError: 'metadata'
Hello,
C:\Users\slimjim>pip install TwitterSpaces2Text
Collecting TwitterSpaces2Text
Using cached TwitterSpaces2Text-0.1.tar.gz (2.6 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "", line 2, in
File "", line 34, in
File "C:\Users\slimjim\AppData\Local\Temp\pip-install-t7obqjaz\twitterspaces2text_a152f74be907404ea36a7491c5df9dae\setup.py", line 3, in
subprocess.run(["pandoc","--from=markdown","--to=rst","--output=README","README.md"])
File "C:\Python\lib\subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Python\lib\subprocess.py", line 969, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
(i was able to install another github also stored in same site-packages directory with success
C:\Users\slimjim>pip install pyautogui
...
Successfully installed PyTweening-1.0.4 mouseinfo-0.1.3 pyautogui-0.9.53 pygetwindow-0.0.9 pymsgbox-1.0.9 pyperclip-1.8.2 pyrect-0.2.0 pyscreeze-0.1.28)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.