HoloArchivists / twspace-dl

A python module to download twitter spaces.
GNU General Public License v2.0
473 stars 78 forks source link

local variable 'twspace_dl' referenced before assignment #32

Closed JC-Chung closed 2 years ago

JC-Chung commented 2 years ago

Describe the bug https://github.com/Ryu1845/twspace-dl/blob/1ca12aa975c40c5d9020709e22332b041b2f13ef/twspace_dl/__main__.py#L173-L176

To Reproduce twspace_dl -f https://prod-fastly-ap-northeast-1.video.pscp.tv/Transcoding/v1/hls/YRSsw6_P5xUZHMualK5-ihvePR6o4QmoZVOBGicKvmkL_KB9IQYtxVqm3P_vpZ2HnFkoRfar4_uJOjqC8OCo5A/non_transcode/ap-northeast-1/periscope-replay-direct-prod-ap-northeast-1-public/audio-space/master_playlist.m3u8

Expected behavior use the master url for the processes(useful for ended spaces)

Output If applicable, add the output of the command to help explain your problem.

Traceback (most recent call last):
  File "c:\users\test01\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\test01\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\test01\AppData\Local\Programs\Python\Python39\Scripts\twspace_dl.exe\__main__.py", line 7, in <module>
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\__main__.py", line 116, in main
    args.func(args)
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\__main__.py", line 176, in twspace
    twspace_dl.master_url = args.from_master_url
UnboundLocalError: local variable 'twspace_dl' referenced before assignment

Desktop (please complete the following information):

Additional context Same problem in twspace_dl -d DYN_URL

Ryu1845 commented 2 years ago

Fixed in latest release

JC-Chung commented 2 years ago

twspace_dl -s -i https://twitter.com/i/spaces/1LyxBokRPDaKN -u display the master url

twspace_dl -f https://prod-fastly-ap-northeast-1.video.pscp.tv/Transcoding/v1/hls/yenulOtsWltjshnjilUs9lzZr_kOg0JiHrS1BEouSLNxgxVa6K2tIFJ65xUghGc0BKMho36dEzpIT9n6j57OeQ/non_transcode/ap-northeast-1/periscope-replay-direct-prod-ap-northeast-1-public/audio-space/master_playlist.m3u8 -o "[la_po].mp4" use the master url for the processes(useful for ended spaces)

ERROR:root:{'errors': [{'message': 'BadRequest: invalid broadcast_ids=[no_id]', 'locations': [{'line': 8, 'column': 3}], 'path': ['audioSpace', 'metadata'], 'extensions': {'name': 'BadRequestError', 'source': 'Client', 'code': 214, 'kind': 'Validation', 'tracing': {'trace_id': '38d648479d2456f1'}}, 'code': 214, 'kind': 'Validation', 'name': 'BadRequestError', 'source': 'Client', 'tracing': {'trace_id': '38d648479d2456f1'}}, {'message': 'BadRequest: invalid broadcast_ids=[no_id]', 'locations': [{'line': 28, 'column': 3}], 'path': ['audioSpace', 'sharings'], 'extensions': {'name': 'BadRequestError', 'source': 'Client', 'code': 214, 'kind': 'Validation', 'tracing': {'trace_id': '38d648479d2456f1'}}, 'code': 214, 'kind': 'Validation', 'name': 'BadRequestError', 'source': 'Client', 'tracing': {'trace_id': '38d648479d2456f1'}}], 'data': {'audioSpace': {}}}
Traceback (most recent call last):
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\twspace_dl.py", line 193, in metadata
    media_key = metadata["data"]["audioSpace"]["metadata"]["media_key"]
KeyError: 'metadata'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\__main__.py", line 189, in twspace
    twspace_dl.download()
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\twspace_dl.py", line 280, in download
    metadata = self.metadata
  File "c:\users\test01\appdata\local\programs\python\python39\lib\functools.py", line 969, in __get__
    val = self.func(instance)
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\twspace_dl.py", line 197, in metadata
    raise RuntimeError(metadata) from error
RuntimeError: {'errors': [{'message': 'BadRequest: invalid broadcast_ids=[no_id]', 'locations': [{'line': 8, 'column': 3}], 'path': ['audioSpace', 'metadata'], 'extensions': {'name': 'BadRequestError', 'source': 'Client', 'code': 214, 'kind': 'Validation', 'tracing': {'trace_id': '38d648479d2456f1'}}, 'code': 214, 'kind': 'Validation', 'name': 'BadRequestError', 'source': 'Client', 'tracing': {'trace_id': '38d648479d2456f1'}}, {'message': 'BadRequest: invalid broadcast_ids=[no_id]', 'locations': [{'line': 28, 'column': 3}], 'path': ['audioSpace', 'sharings'], 'extensions': {'name': 'BadRequestError', 'source': 'Client', 'code': 214, 'kind': 'Validation', 'tracing': {'trace_id': '38d648479d2456f1'}}, 'code': 214, 'kind': 'Validation', 'name': 'BadRequestError', 'source': 'Client', 'tracing': {'trace_id': '38d648479d2456f1'}}], 'data': {'audioSpace': {}}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\test01\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\test01\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\test01\AppData\Local\Programs\Python\Python39\Scripts\twspace_dl.exe\__main__.py", line 7, in <module>
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\__main__.py", line 116, in main
    args.func(args)
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\__main__.py", line 193, in twspace
    if not args.keep_files and os.path.exists(twspace_dl._tmpdir):
AttributeError: 'TwspaceDL' object has no attribute '_tmpdir'

Desktop (please complete the following information):

Ryu1845 commented 2 years ago

I know what the problem is and I'm going to fix it. But you can just add -i <space url> to fix it. The error won't happen and you'll get the metadata embedded too

JC-Chung commented 2 years ago

I know what the problem is and I'm going to fix it. But you can just add -i <space url> to fix it. The error won't happen and you'll get the metadata embedded too

But if the space is unarchive, then can't use -i <space url> to download it. ((Although it sounds normal.

Ryu1845 commented 2 years ago

You can't use it to get the master url but you can use it to get metadata. (like the user making the space etc.)

Ryu1845 commented 2 years ago

You can use twspace_dl -f <master url> -i <space url>

JC-Chung commented 2 years ago

If space is online and unarchive, does I can use twspace_dl -f <master url> to download from start? Even just use twspace_dl -i <space url>? (like #31 ?) By the way, is normal that twspace_dl -i <space url> sometimes will missing few frags when space online? Cause it miss more than I use youtube-dl <dyn url> to download, even my computer didn't do other work. Thank you for your help.

Ryu1845 commented 2 years ago

If space is online [...] can I use twspace_dl -f <master url> to download from start?

No

Even just use twspace_dl -i <space url>? (like #31 ?)

I don't understand

By the way, is normal that twspace_dl -i <space url> sometimes will missing few frags when space online?

I knew it could happen but I thought it would only be one max.