Skip to content

Commit

Permalink
update readme and add service example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu1845 committed Nov 12, 2021
1 parent 029f24d commit e2646d4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,51 @@ You can use the following identifiers for the formatting
%(url)s
```
Example: `[%(creator_screen_name)s]-%(title)s|%(start_date)s`

## Service
There's an example service file [there](../blob/master/[email protected])
You'll have to modify different stuff depending on how you installed or not the script.
I'd be very grateful if someone made a PR with a bash script automating those ;)

### Cloned Repository
In that case, you'll have to modify the `WorkingDirectory` to where you cloned the repo.

### Pip
1. Change `WorkingDirectory` to where you want the spaces to be downloaded.
2. Find where your executable is by running `which twspace_dl` in your terminal.
3. Change the `/usr/bin/python twspace_dl` part to the path of your executable.


Now to install the service, you can either install it as a user service(recommended if on your personal desktop), or as a normal service.

### User
1. Copy the file you modified earlier to `~/.config/systemd/user`(create the systemd directory if it doesn't exist).
2. run

``` bash
systemctl --user daemon-reload
systemctl --user start twspace-dl@USER_ID.service
```
`USER_ID` is the part after `https://twitter.com/` in the url of a twitter profile (i.e `https://twitter.com/USER_ID`)

To keep it working after restarts run:

``` bash
systemctl --user enable twspace-dl@USER_ID.service
```

### System
1. Copy the file you modified earlier to `/etc/systemd/system`.
2. run

``` bash
sudo systemctl daemon-reload
sudo systemctl start twspace-dl@USER_ID.service
```
`USER_ID` is the part after `https://twitter.com/` in the url of a twitter profile (i.e `https://twitter.com/USER_ID`)

To keep it working after restarts run:

``` bash
sudo systemctl enable twspace-dl@USER_ID.service
```
9 changes: 9 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Automated download for twitter space by %i
After=network-online.target

[Service]
WorkingDirectory=/path/to/twspace-dl
ExecStart=/usr/bin/python twspace_dl -U https://twitter.com/%i
Restart=always
RestartSec=15
4 changes: 2 additions & 2 deletions twspace_dl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def from_user_url(cls, url: str, threads, format_str):
try:
space_id = re.findall(r"(?<=https://twitter.com/i/spaces/)\w*", tweets)[0]
except (IndexError, json.JSONDecodeError) as err:
raise RuntimeError("User is not live", response.text) from err
raise RuntimeError("User is not live") from err
format_str = format_str or FormatInfo.DEFAULT_FNAME_FORMAT
return cls(space_id, threads, format_str)

Expand Down Expand Up @@ -270,7 +270,7 @@ def write_playlist(self, save_dir: str = "./") -> None:
filename = os.path.join(save_dir, shlex.quote(self.filename) + ".m3u8")
with open(filename, "w", encoding="utf-8") as stream_io:
stream_io.write(self.playlist_text)
logging.info(f"{filename}.m3u8 written to disk")
logging.info(f"{filename} written to disk")

def download(self) -> None:
"""Download a twitter space"""
Expand Down

0 comments on commit e2646d4

Please sign in to comment.