Browse Source

login is now functional

master
sharky555 4 years ago
parent
commit
2fa0c3c8d9
1 changed files with 26 additions and 28 deletions
  1. +26
    -28
      autoupload.py

+ 26
- 28
autoupload.py View File

@@ -20,17 +20,16 @@ from tqdm import tqdm
from langdetect import detect from langdetect import detect


# JPS-AU files # JPS-AU files
import jpspy
import smpy


def asciiart (): def asciiart ():
print(""" print("""
██╗██████╗ ███████╗ █████╗ ██╗ ██╗
██║██╔══██╗██╔════╝ ██╔══██╗██║ ██║
██║██████╔╝███████╗█████╗███████║██║ ██║
██ ██║██╔═══╝ ╚════██║╚════╝██╔══██║██║ ██║
╚█████╔╝██║ ███████║ ██║ ██║╚██████╔╝
╚════╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝

███████╗███╗ ███╗ █████╗ ██╗ ██╗
██╔════╝████╗ ████║ ██╔══██╗██║ ██║
███████╗██╔████╔██║█████╗███████║██║ ██║
╚════██║██║╚██╔╝██║╚════╝██╔══██║██║ ██║
███████║██║ ╚═╝ ██║ ██║ ██║╚██████╔╝
╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝
""") """)


# Get arguments using argparse # Get arguments using argparse
@@ -46,20 +45,19 @@ def getargs():


# Acquire the authkey used for torrent files from upload.php # Acquire the authkey used for torrent files from upload.php
def getauthkey(): def getauthkey():
# uploadpage = j.retrieveContent("https://sugoimusic.me/upload.php")
# soup = BeautifulSoup(uploadpage.text, 'html5lib')
# rel2 = str(soup.select('#wrapper #content .thin'))
# # Regex returns multiple matches, could be optimized.
# authkey = re.findall("(?<=value=\")(.*)(?=\")", rel2)[0]

# return authkey
smpage = sm.retrieveContent("https://sugoimusic.me/torrents.php?id=118") # Arbitrary page on JPS that has authkey
"""
Get SM session authkey for use by uploadtorrent() data dict.
Uses SM login data

:return: authkey
"""
smpage = sm.retrieveContent("https://sugoimusic.me/torrents.php?id=118") # Arbitrary page on JPS that has authkey
soup = BeautifulSoup(smpage.text, 'html5lib') soup = BeautifulSoup(smpage.text, 'html5lib')
rel2 = str(soup.select('#content .thin .main_column .torrent_table tbody')) rel2 = str(soup.select('#content .thin .main_column .torrent_table tbody'))
authkey = re.findall('authkey=(.*)&amp;torrent_pass=', rel2) authkey = re.findall('authkey=(.*)&amp;torrent_pass=', rel2)
return authkey return authkey
def copytree(src, dst, symlinks=False, ignore=None): def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src): for item in os.listdir(src):
s = os.path.join(src, item) s = os.path.join(src, item)
@@ -75,13 +73,13 @@ def createtorrent(authkey, directory, filename, releasedata):
trackers=[authkey]) # Torf requires we store authkeys in a list object. This makes it easier to add multiple announce urls. trackers=[authkey]) # Torf requires we store authkeys in a list object. This makes it easier to add multiple announce urls.
# Set torrent to private as standard practice for private trackers # Set torrent to private as standard practice for private trackers
t.private = True t.private = True
t.source = "SugoiMusic"
t.source = "SugoiMusic"
t.generate() t.generate()
## Format releasedata to bring a suitable torrent name. ## Format releasedata to bring a suitable torrent name.
# The reason we don't just use the directory name is because of an error in POSTING. # The reason we don't just use the directory name is because of an error in POSTING.
# POSTS do not seem to POST hangul/jp characters alongside files. # POSTS do not seem to POST hangul/jp characters alongside files.
filename = f"{releasedata['artist']} - {releasedata['title']} [{releasedata['media']}-{releasedata['format']}].torrent" filename = f"{releasedata['artist']} - {releasedata['title']} [{releasedata['media']}-{releasedata['format']}].torrent"
#filename = filename.replace("\\","")
#filename = filename.replace("\\","")
try: try:
t.write(filename) t.write(filename)
print("_" * 100) print("_" * 100)
@@ -548,7 +546,7 @@ def detectlanguage(string):


def uploadtorrent(torrent, cover, releasedata): def uploadtorrent(torrent, cover, releasedata):


languages = ('Japanese', 'English', 'Korean', 'Chinese', 'Vietnamese')
languages = ('Japanese', 'English', 'Korean', 'Chinese', 'Vietnamese')
# POST url. # POST url.
uploadurl = "https://sugoimusic.me/upload.php" uploadurl = "https://sugoimusic.me/upload.php"


@@ -572,7 +570,7 @@ def uploadtorrent(torrent, cover, releasedata):


# If dryrun argument has not ben passed we will POST the results to JPopSuki. # If dryrun argument has not ben passed we will POST the results to JPopSuki.
if dryrun != True: if dryrun != True:
JPSres = j.retrieveContent(uploadurl, "post", data, postDataFiles)
JPSres = sm.retrieveContent(uploadurl, "post", data, postDataFiles)
print('\nUpload POSTED') print('\nUpload POSTED')


## TODO Filter through JPSres.text and create error handling based on responses ## TODO Filter through JPSres.text and create error handling based on responses
@@ -664,12 +662,12 @@ if __name__ == "__main__":
with open(f'json_data/config.json') as f: with open(f'json_data/config.json') as f:
cfg = json.load(f) cfg = json.load(f)
loginData = {'username': cfg['credentials']['username'], 'password': cfg['credentials']['password']} loginData = {'username': cfg['credentials']['username'], 'password': cfg['credentials']['password']}
loginUrl = "https://jpopsuki.eu/login.php"
loginTestUrl = "https://jpopsuki.eu"
successStr = "Latest 5 Torrents"
loginUrl = "https://sugoimusic.me/login.php"
loginTestUrl = "https://sugoimusic.me"
successStr = "Enabled users"


# j is an object which can be used to make requests with respect to the loginsession # j is an object which can be used to make requests with respect to the loginsession
j = jpspy.MyLoginSession(loginUrl, loginData, loginTestUrl, successStr, debug=args.debug)
sm = smpy.MyLoginSession(loginUrl, loginData, loginTestUrl, successStr, debug=args.debug)
# Acquire authkey # Acquire authkey
authkey = getauthkey() authkey = getauthkey()
# Gather data of FLAC file # Gather data of FLAC file
@@ -678,13 +676,13 @@ if __name__ == "__main__":
# Folder_name equals the last folder in the path, this is used to rename .torrent files to something relevant. # Folder_name equals the last folder in the path, this is used to rename .torrent files to something relevant.
folder_name = os.path.basename(os.path.normpath(directory)) folder_name = os.path.basename(os.path.normpath(directory))
# Identifying cover.jpg path # Identifying cover.jpg path
cover_path = directory + "/" + cfg['local_prefs']['cover_name']
# cover_path = directory + "/" + cfg['local_prefs']['cover_name']


# Create torrent file. # Create torrent file.
torrentfile = createtorrent(authkey, directory, folder_name, releasedata) torrentfile = createtorrent(authkey, directory, folder_name, releasedata)


# Upload torrent to JPopSuki # Upload torrent to JPopSuki
uploadtorrent(torrentfile, cover_path, releasedata)
# uploadtorrent(torrentfile, cover_path, releasedata)


# Setting variable for watch/download folders # Setting variable for watch/download folders
ftp_watch_folder = cfg['ftp_prefs']['ftp_watch_folder'] ftp_watch_folder = cfg['ftp_prefs']['ftp_watch_folder']


Loading…
Cancel
Save