| @@ -40,7 +40,7 @@ def getargs(): | |||||
| parser.add_argument("-t", "--tags", help="Add additional tags to the upload", nargs='?') | parser.add_argument("-t", "--tags", help="Add additional tags to the upload", nargs='?') | ||||
| parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true') | parser.add_argument('-d', '--debug', help='Enable debug mode', action='store_true') | ||||
| parser.add_argument("-dry", "--dryrun", help="Dryrun will carry out all actions other than the actual upload to JPS.", action="store_true") | parser.add_argument("-dry", "--dryrun", help="Dryrun will carry out all actions other than the actual upload to JPS.", action="store_true") | ||||
| parser.add_argument("-i", "--imageURL", help='Set the torrent cover URL', nargs='?') | |||||
| return parser.parse_args() | return parser.parse_args() | ||||
| # Acquire the authkey used for torrent files from upload.php | # Acquire the authkey used for torrent files from upload.php | ||||
| @@ -55,7 +55,6 @@ def getauthkey(): | |||||
| 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=(.*)&torrent_pass=', rel2) | authkey = re.findall('authkey=(.*)&torrent_pass=', rel2) | ||||
| print(authkey) | |||||
| return authkey | return authkey | ||||
| @@ -79,7 +78,7 @@ def createtorrent(authkey, directory, filename, releasedata): | |||||
| ## 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['idols[]']} - {releasedata['title']} [{releasedata['media']}-{releasedata['audioformat']}].torrent" | |||||
| #filename = filename.replace("\\","") | #filename = filename.replace("\\","") | ||||
| try: | try: | ||||
| t.write(filename) | t.write(filename) | ||||
| @@ -400,7 +399,7 @@ def gatherdata(directory): | |||||
| if log_available == True: | if log_available == True: | ||||
| media = 'CD' | media = 'CD' | ||||
| else: | else: | ||||
| media = 'WEB' | |||||
| media = 'Web' | |||||
| # Load Dict.json for translations | # Load Dict.json for translations | ||||
| file = "json_data/dictionary.json" | file = "json_data/dictionary.json" | ||||
| @@ -461,32 +460,38 @@ def gatherdata(directory): | |||||
| releasedata['submit'] = 'true' | releasedata['submit'] = 'true' | ||||
| # List of accepted upload types | # List of accepted upload types | ||||
| accepted_types = ['Album', 'Single'] | |||||
| accepted_types = ['Album', 'Single', 'EP'] | |||||
| # If type errors then we ask for user input | # If type errors then we ask for user input | ||||
| try: | try: | ||||
| releasedata['type'] = translate(tags['GROUPING'][0], "release_types")[0] | releasedata['type'] = translate(tags['GROUPING'][0], "release_types")[0] | ||||
| except TypeError: | except TypeError: | ||||
| releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping is empty or has received an error, please enter manually (Album/Single)\n") | |||||
| releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping is empty or has received an error, please enter manually (Album/Single/EP)\n") | |||||
| # If type is still not in accepted_types we ask for user input again and do not break loop until correct | # If type is still not in accepted_types we ask for user input again and do not break loop until correct | ||||
| if releasedata['type'] not in accepted_types: | if releasedata['type'] not in accepted_types: | ||||
| while True: | while True: | ||||
| releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping tag did not return an album type, please enter manually (Album/Single)\n") | |||||
| releasedata['type'] = input("\n" + "_" * 100 + "\nGrouping tag did not return an album type, please enter manually (Album/Single/EP)\n") | |||||
| if releasedata['type'] not in accepted_types: | if releasedata['type'] not in accepted_types: | ||||
| continue | continue | ||||
| else: | else: | ||||
| break | break | ||||
| # SM uses numbers for it's types | |||||
| if releasedata['type'] == "Album": | |||||
| releasedata['type'] = 0 | |||||
| elif releasedata['type'] == "Single": | |||||
| releasedata['type'] = 1 | |||||
| else: # EP type | |||||
| releasedata['type'] = 2 | |||||
| releasedata['title'] = tags['ALBUM'][0] | releasedata['title'] = tags['ALBUM'][0] | ||||
| releasedata['artist'] = unique_album_artists | |||||
| releasedata['idols[]'] = unique_album_artists | |||||
| # If the value of album artist and artist is the same, we don't need to POST original artist. | # If the value of album artist and artist is the same, we don't need to POST original artist. | ||||
| if unique_album_artists != unique_track_artists: | if unique_album_artists != unique_track_artists: | ||||
| releasedata['artistjp'] = unique_track_artists | |||||
| releasedata['artist_jp'] = unique_track_artists | |||||
| #re.sub removes any date separators, jps doesn't accept them | #re.sub removes any date separators, jps doesn't accept them | ||||
| releasedata['releasedate'] = re.sub(r"[^0-9]", "", tags['DATE']) | |||||
| releasedata['format'] = format | |||||
| releasedata['year'] = re.sub(r"[^0-9]", "", tags['DATE']) | |||||
| releasedata['audioformat'] = format | |||||
| releasedata['bitrate'] = bitrate | releasedata['bitrate'] = bitrate | ||||
| releasedata['media'] = media | releasedata['media'] = media | ||||
| releasedata['album_desc'] = album_description | releasedata['album_desc'] = album_description | ||||
| @@ -506,19 +511,19 @@ def gatherdata(directory): | |||||
| print(f"{releasedata['title']} < English = {en}") | print(f"{releasedata['title']} < English = {en}") | ||||
| if en == False: | if en == False: | ||||
| input_english_title = input("\n" + "_" * 100 + "\nKorean/Japanese Detected. Please enter the romaji/english title:\n") | input_english_title = input("\n" + "_" * 100 + "\nKorean/Japanese Detected. Please enter the romaji/english title:\n") | ||||
| # Create new key called titlejp and assign the old title to it | |||||
| releasedata['titlejp'] = releasedata['title'] | |||||
| # Create new key called title_jp and assign the old title to it | |||||
| releasedata['title_jp'] = releasedata['title'] | |||||
| # Replace title with the user input. | # Replace title with the user input. | ||||
| releasedata['title'] = input_english_title | releasedata['title'] = input_english_title | ||||
| en = detectlanguage(releasedata['artist']) | |||||
| en = detectlanguage(releasedata['idols[]']) | |||||
| if debug: | if debug: | ||||
| print(f"{releasedata['artist']} < English = {en}") | |||||
| print(f"{releasedata['idols[]']} < English = {en}") | |||||
| if en == False: | if en == False: | ||||
| input_english_artist = input("\n" + "_" * 100 + "\nKorean/Japanese Detected. Please enter the romaji/english artist name:\n") | input_english_artist = input("\n" + "_" * 100 + "\nKorean/Japanese Detected. Please enter the romaji/english artist name:\n") | ||||
| # Create new key called titlejp and assign the old title to it | # Create new key called titlejp and assign the old title to it | ||||
| # Replace title with the user input. | # Replace title with the user input. | ||||
| releasedata['artist'] = input_english_artist | |||||
| releasedata['idols[]'] = input_english_artist | |||||
| return releasedata | return releasedata | ||||
| @@ -545,14 +550,17 @@ def detectlanguage(string): | |||||
| return en | return en | ||||
| def uploadtorrent(torrent, releasedata): | |||||
| languages = ('Japanese', 'English', 'Korean', 'Chinese', 'Vietnamese') | |||||
| def uploadtorrent(torrent, imageURL, releasedata): | |||||
| # POST url. | # POST url. | ||||
| uploadurl = "https://sugoimusic.me/upload.php" | uploadurl = "https://sugoimusic.me/upload.php" | ||||
| # Dataset containing all of the information obtained from our FLAC files. | # Dataset containing all of the information obtained from our FLAC files. | ||||
| data = releasedata | data = releasedata | ||||
| data['image'] = imageURL | |||||
| if not dryrun: | |||||
| data['auth'] = authkey | |||||
| if debug: | if debug: | ||||
| print('_' * 100) | print('_' * 100) | ||||
| @@ -572,7 +580,7 @@ def uploadtorrent(torrent, 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 = sm.retrieveContent(uploadurl, "post", data, postDataFiles) | JPSres = sm.retrieveContent(uploadurl, "post", data, postDataFiles) | ||||
| print('\nUpload POSTED') | |||||
| print('\nUpload POSTED. It may take a moment for this upload to appear on SugoiMusic.') | |||||
| ## TODO Filter through JPSres.text and create error handling based on responses | ## TODO Filter through JPSres.text and create error handling based on responses | ||||
| #print(JPSres.text) | #print(JPSres.text) | ||||
| @@ -645,11 +653,11 @@ if __name__ == "__main__": | |||||
| args = getargs() | args = getargs() | ||||
| # TODO consider calling args[] directly, we will then not need this line | # TODO consider calling args[] directly, we will then not need this line | ||||
| dryrun = freeleech = tags = directory = debug = None | |||||
| dryrun = freeleech = tags = directory = debug = imageURL = None | |||||
| directory = args.directory | directory = args.directory | ||||
| additional_tags = args.tags | additional_tags = args.tags | ||||
| if args.dryrun: | if args.dryrun: | ||||
| dryrun = True | dryrun = True | ||||
| @@ -659,6 +667,9 @@ if __name__ == "__main__": | |||||
| if args.freeleech: | if args.freeleech: | ||||
| freeleech = True | freeleech = True | ||||
| if args.imageURL: | |||||
| imageURL = args.imageURL | |||||
| # Load login credentials from JSON and use them to create a login session. | # Load login credentials from JSON and use them to create a login session. | ||||
| 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) | ||||
| @@ -668,7 +679,7 @@ if __name__ == "__main__": | |||||
| successStr = "Enabled users" | successStr = "Enabled users" | ||||
| passkey = cfg['credentials']['passkey'] | passkey = cfg['credentials']['passkey'] | ||||
| annouceurl = "https://tracker.sugoimusic.me:24601/"+passkey+"/announce" | annouceurl = "https://tracker.sugoimusic.me:24601/"+passkey+"/announce" | ||||
| print(annouceurl) | |||||
| # 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 | ||||
| sm = smpy.MyLoginSession(loginUrl, loginData, loginTestUrl, successStr, debug=args.debug) | sm = smpy.MyLoginSession(loginUrl, loginData, loginTestUrl, successStr, debug=args.debug) | ||||
| # Acquire authkey | # Acquire authkey | ||||
| @@ -686,7 +697,7 @@ if __name__ == "__main__": | |||||
| torrentfile = createtorrent(annouceurl, directory, folder_name, releasedata) | torrentfile = createtorrent(annouceurl, directory, folder_name, releasedata) | ||||
| # Upload torrent to JPopSuki | # Upload torrent to JPopSuki | ||||
| uploadtorrent(torrentfile, releasedata) | |||||
| uploadtorrent(torrentfile, imageURL, 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'] | ||||
| @@ -694,9 +705,9 @@ if __name__ == "__main__": | |||||
| local_watch_folder = cfg['local_prefs']['local_watch_folder'] | local_watch_folder = cfg['local_prefs']['local_watch_folder'] | ||||
| local_downloads_folder = cfg['local_prefs']['local_downloads_folder'] | local_downloads_folder = cfg['local_prefs']['local_downloads_folder'] | ||||
| if cfg['ftp_prefs']['enable_ftp']: | |||||
| ftp_transfer(fileSource=torrentfile, fileDestination=ftp_downloads_folder, directory=directory, folder_name=folder_name, watch_folder=ftp_watch_folder) | |||||
| if cfg['local_prefs']['add_to_watch_folder'] or cfg['local_prefs']['add_to_downloads_folder']: | |||||
| localfileorganization(torrent=torrentfile, directory=directory, watch_folder=local_watch_folder, downloads_folder=local_downloads_folder) | |||||
| if not dryrun: | |||||
| if cfg['ftp_prefs']['enable_ftp']: | |||||
| ftp_transfer(fileSource=torrentfile, fileDestination=ftp_downloads_folder, directory=directory, folder_name=folder_name, watch_folder=ftp_watch_folder) | |||||
| if cfg['local_prefs']['add_to_watch_folder'] or cfg['local_prefs']['add_to_downloads_folder']: | |||||
| localfileorganization(torrent=torrentfile, directory=directory, watch_folder=local_watch_folder, downloads_folder=local_downloads_folder) | |||||