mirror of
https://github.com/ovosimpatico/CLI-TikTok.git
synced 2026-01-15 11:52:52 -03:00
PEP-8 Compliance
Signed-off-by: nanometer5088 <code.deleo@simplelogin.com>
This commit is contained in:
5
main.py
5
main.py
@@ -92,7 +92,6 @@ def main():
|
||||
|
||||
## Stream
|
||||
if question == 2:
|
||||
|
||||
watchquestion = int(
|
||||
input(
|
||||
"""Do you want to watch your liked videos, a creator or trending videos?
|
||||
@@ -107,7 +106,6 @@ def main():
|
||||
|
||||
## Stream liked videos
|
||||
if watchquestion == 1:
|
||||
|
||||
randomquestion = int(
|
||||
input(
|
||||
"""Do you want to watch the tiktoks in randomized order?
|
||||
@@ -188,6 +186,7 @@ def main():
|
||||
# Warning, this section is experimental and will only run if you use any launch arguments
|
||||
# GUI Code:
|
||||
|
||||
|
||||
def arguments(args):
|
||||
log("Running using launch arguments")
|
||||
|
||||
@@ -224,6 +223,8 @@ def arguments(args):
|
||||
videos = int(args.streamtrending)
|
||||
if videos >= 1:
|
||||
streamtrending(videos)
|
||||
|
||||
|
||||
if silent:
|
||||
arguments(args)
|
||||
else:
|
||||
|
||||
@@ -6,6 +6,7 @@ from bs4 import BeautifulSoup
|
||||
from log import logtofile as log
|
||||
from src.streaming import getVideoInfo, mpv
|
||||
|
||||
|
||||
def streamuser(username):
|
||||
links = proxitok_scraper(username)
|
||||
|
||||
@@ -20,6 +21,7 @@ def streamuser(username):
|
||||
|
||||
def proxitok_scraper(username: str) -> list[str]:
|
||||
from src.constants import OPTIONS
|
||||
|
||||
log("Scraper started")
|
||||
print("\nObtaining URLs - this can take a while with users with many posts.")
|
||||
session = requests.Session()
|
||||
|
||||
@@ -5,14 +5,15 @@ from yt_dlp import YoutubeDL
|
||||
from yt_dlp.utils import DownloadError
|
||||
|
||||
from log import logtofile as log
|
||||
from src.functions import url_redirection
|
||||
from src.constants import OPTIONS
|
||||
from src.functions import url_redirection
|
||||
|
||||
|
||||
def downloader(url):
|
||||
ydl_opts = {
|
||||
"format": "bestvideo*+bestaudio/best",
|
||||
"outtmpl": os.getcwd() + "/video/%(creator)s/%(id)s.%(ext)s",
|
||||
"download_archive": os.getcwd() + "/video/.video_archive"
|
||||
"download_archive": os.getcwd() + "/video/.video_archive",
|
||||
}
|
||||
YoutubeDL(ydl_opts).download(url)
|
||||
|
||||
|
||||
@@ -2,19 +2,22 @@ import os
|
||||
import random
|
||||
|
||||
import requests
|
||||
|
||||
from log import logtofile as log
|
||||
|
||||
|
||||
def listas():
|
||||
# Retrieves tiktok likes and dates from user_data.json
|
||||
import json
|
||||
f = open('user_data.json')
|
||||
|
||||
f = open("user_data.json")
|
||||
linklist = []
|
||||
datelist = []
|
||||
data = json.load(f)
|
||||
|
||||
for i in data['Activity']["Like List"]['ItemFavoriteList']:
|
||||
linklist.append(i['Link'])
|
||||
datelist.append(i['Date'])
|
||||
for i in data["Activity"]["Like List"]["ItemFavoriteList"]:
|
||||
linklist.append(i["Link"])
|
||||
datelist.append(i["Date"])
|
||||
f.close()
|
||||
log("user_data.json file was processed sucessfully")
|
||||
return linklist, datelist
|
||||
|
||||
59
src/init.py
59
src/init.py
@@ -12,6 +12,7 @@
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
|
||||
import requests
|
||||
|
||||
from log import logtofile as log
|
||||
@@ -25,17 +26,23 @@ def init(silent):
|
||||
clear_screen()
|
||||
|
||||
if not silent:
|
||||
|
||||
print("Welcome to CLI TikTok, an open-source TikTok archiver and viewer!")
|
||||
input("Press ENTER to proceed")
|
||||
|
||||
log("Started dependency test")
|
||||
required_libraries = ["requests", "yt_dlp", "distro", "bs4"]
|
||||
missing_libraries = [library for library in required_libraries if not _library_exists(library)]
|
||||
missing_libraries = [
|
||||
library for library in required_libraries if not _library_exists(library)
|
||||
]
|
||||
if missing_libraries:
|
||||
log("Dependency test failed - Missing libraries: " + ", ".join(missing_libraries))
|
||||
log(
|
||||
"Dependency test failed - Missing libraries: "
|
||||
+ ", ".join(missing_libraries)
|
||||
)
|
||||
clear_screen()
|
||||
input("The program detected dependencies are not installed.\nPress ENTER to install the necessary libraries.\n(You will need to open the program again afterwards)")
|
||||
input(
|
||||
"The program detected dependencies are not installed.\nPress ENTER to install the necessary libraries.\n(You will need to open the program again afterwards)"
|
||||
)
|
||||
log("User accepted automatic installation, running it.\n")
|
||||
os.system("pip install -r requirements.txt --user")
|
||||
clear_screen()
|
||||
@@ -50,36 +57,56 @@ def init(silent):
|
||||
|
||||
log("Started update / networking test")
|
||||
try:
|
||||
link = requests.get("https://raw.githubusercontent.com/nanometer5088/CLI-TikTok/main/src/constants.py").text.strip()
|
||||
link = requests.get(
|
||||
"https://raw.githubusercontent.com/nanometer5088/CLI-TikTok/main/src/constants.py"
|
||||
).text.strip()
|
||||
|
||||
userversion = _read_user_version()
|
||||
|
||||
version_line = next(line for line in link.split('\n')
|
||||
if line.startswith(' "version": '))
|
||||
data = version_line.split(': ')[1]
|
||||
version_line = next(
|
||||
line for line in link.split("\n") if line.startswith(' "version": ')
|
||||
)
|
||||
data = version_line.split(": ")[1]
|
||||
|
||||
if userversion < data:
|
||||
log(f"New version detected! User version is {userversion}, but {data} was found on Github.")
|
||||
log(
|
||||
f"New version detected! User version is {userversion}, but {data} was found on Github."
|
||||
)
|
||||
clear_screen()
|
||||
input("\tThere's a new version available!\n\tUpdates bring performance and feature improvements!\n\tDownload the new version here:\n\thttps://github.com/nanometer5088/CLI-TikTok/archive/refs/heads/main.zip\n\n\tPress ENTER to proceed")
|
||||
input(
|
||||
"\tThere's a new version available!\n\tUpdates bring performance and feature improvements!\n\tDownload the new version here:\n\thttps://github.com/nanometer5088/CLI-TikTok/archive/refs/heads/main.zip\n\n\tPress ENTER to proceed"
|
||||
)
|
||||
clear_screen()
|
||||
else:
|
||||
log("The user has internet access and the software is up-to-date.\n")
|
||||
clear_screen()
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
log("A connection error was detected when trying to connect to https://raw.githubusercontent.com/ to check for updates.")
|
||||
log(
|
||||
"A connection error was detected when trying to connect to https://raw.githubusercontent.com/ to check for updates."
|
||||
)
|
||||
try:
|
||||
for site in ["https://www.eff.org", "https://freedom.press", "https://www.torproject.org", "https://www.privacyguides.org"]:
|
||||
for site in [
|
||||
"https://www.eff.org",
|
||||
"https://freedom.press",
|
||||
"https://www.torproject.org",
|
||||
"https://www.privacyguides.org",
|
||||
]:
|
||||
requests.get(site)
|
||||
log("The user seems to be connected to the internet, but Github is not accessible. Dazed and confused, but trying to continue.")
|
||||
log(
|
||||
"The user seems to be connected to the internet, but Github is not accessible. Dazed and confused, but trying to continue."
|
||||
)
|
||||
clear_screen()
|
||||
except requests.exceptions.ConnectionError:
|
||||
clear_screen()
|
||||
print("CLI-TikTok detected your device isn't connected to the internet.")
|
||||
print("This software requires a reliable and uncensored internet connection to properly work.")
|
||||
print(
|
||||
"This software requires a reliable and uncensored internet connection to properly work."
|
||||
)
|
||||
print("Please try again with an internet connection.")
|
||||
log("The software exited, and the user was notified of the connection problem.")
|
||||
log(
|
||||
"The software exited, and the user was notified of the connection problem."
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
|
||||
@@ -99,6 +126,7 @@ def _get_os_info():
|
||||
return f"Mac OS {platform.mac_ver()}"
|
||||
elif system == "Linux":
|
||||
import distro
|
||||
|
||||
return f"{distro.name()} {distro.version()} - {os.uname().release}"
|
||||
else:
|
||||
return f"{system} - {platform.machine()}"
|
||||
@@ -110,4 +138,5 @@ def _get_python_version():
|
||||
|
||||
def _read_user_version():
|
||||
from src.constants import APP
|
||||
|
||||
return str(APP["version"])
|
||||
10
src/logs.py
10
src/logs.py
@@ -2,6 +2,7 @@ import glob
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
class Logging:
|
||||
# logFileOpened is a variable that keeps track of the log file status.
|
||||
# It is initialized as False to represent the log file wasn't open.
|
||||
@@ -27,9 +28,12 @@ class Logging:
|
||||
|
||||
log_file_name = f"logs/log-{max(log_file_numbers) + 1 if not self.logFileOpened else max(log_file_numbers)}.txt"
|
||||
|
||||
|
||||
with open(log_file_name, "a" if self.logFileOpened else "w") as log_file:
|
||||
self.logFileOpened = True
|
||||
|
||||
current_time = time.strftime("%Y.%m.%d-%H.%M.%S", time.localtime(time.time()))
|
||||
log_file.write(f"[{current_time}] {log_string.encode('ascii', 'replace').decode()}\n")
|
||||
current_time = time.strftime(
|
||||
"%Y.%m.%d-%H.%M.%S", time.localtime(time.time())
|
||||
)
|
||||
log_file.write(
|
||||
f"[{current_time}] {log_string.encode('ascii', 'replace').decode()}\n"
|
||||
)
|
||||
|
||||
@@ -5,8 +5,8 @@ from yt_dlp import YoutubeDL
|
||||
from yt_dlp.utils import DownloadError
|
||||
|
||||
from log import logtofile as log
|
||||
from src.functions import url_redirection
|
||||
from src.constants import OPTIONS
|
||||
from src.functions import url_redirection
|
||||
|
||||
|
||||
def getVideoInfo(url):
|
||||
@@ -16,7 +16,9 @@ def getVideoInfo(url):
|
||||
|
||||
|
||||
def mpv(url):
|
||||
subprocess.check_output(f'{OPTIONS["player_command"]} "{getVideoInfo(url)}"', shell=True)
|
||||
subprocess.check_output(
|
||||
f'{OPTIONS["player_command"]} "{getVideoInfo(url)}"', shell=True
|
||||
)
|
||||
|
||||
|
||||
def playbackrandom(urls, datas):
|
||||
|
||||
@@ -6,7 +6,8 @@ from bs4 import BeautifulSoup
|
||||
from log import logtofile as log
|
||||
from src.constants import OPTIONS
|
||||
|
||||
def streamtrending(amount:int = 24):
|
||||
|
||||
def streamtrending(amount: int = 24):
|
||||
links = proxitok_trending(amount)
|
||||
|
||||
if len(links) == 0:
|
||||
@@ -23,6 +24,7 @@ def streamtrending(amount:int = 24):
|
||||
|
||||
def proxitok_trending(amount: int = 24) -> list[str]:
|
||||
from src.constants import OPTIONS
|
||||
|
||||
log("Scraper started")
|
||||
print("\nObtaining URLs - this can take a while when requesting many posts.")
|
||||
session = requests.Session()
|
||||
|
||||
Reference in New Issue
Block a user