Created
April 26, 2015 08:43
-
-
Save tjoskar/8e32dbd2e2684eccca8f to your computer and use it in GitHub Desktop.
Unrar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import sys | |
download_base_path = sys.argv[1] | |
final_destination = sys.argv[2] | |
""" | |
Start unrar script in a new process. | |
This will cause an exit code of 0, even if unrar.py hangs. | |
""" | |
subprocess.Popen(["python", "unrar.py", download_base_path, final_destination]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import re | |
import shutil | |
import rarfile | |
download_base_path = sys.argv[1] | |
final_destination = sys.argv[2] | |
movie_path = '/media/alpha/movies/' | |
def extract_movie_name(path): | |
name = path.split('/').pop() | |
match = re.match(r'^([^(19|20)\d\d]+)', name) | |
name = match.group(1).strip() | |
name = name.replace('.', ' ').strip() | |
# Remove ending dots | |
# while name[-1] == '.': | |
# name = name[:-1] | |
return name | |
def create_dir(directory): | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
def ucwords(word): | |
return '.'.join([w[0].upper() + w[1:] for w in re.split(r'\s*', word)]) | |
def main(): | |
extract_dir = '' | |
if final_destination.lower() == 'movie': | |
movie_name = ucwords( | |
extract_movie_name( | |
download_base_path | |
)) | |
extract_dir = os.path.join(movie_path, movie_name) | |
else: | |
extract_dir = final_destination | |
create_dir(extract_dir) | |
if os.path.isdir(download_base_path): | |
for rar_file in os.listdir(download_base_path): | |
file_ext = rar_file.split('.').pop() | |
file_path = os.path.join(download_base_path, rar_file) | |
if file_ext in ['mkv', 'mp4', 'avi']: | |
shutil.copy( | |
file_path, | |
extract_dir | |
) | |
elif file_ext in ['rar', 'zip', 'r0', 'r00', 'r000']: | |
rarfile.RarFile(file_path).extractall(extract_dir) | |
elif os.path.isfile(download_base_path): | |
shutil.copy( | |
download_base_path, | |
extract_dir | |
) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installing:
Running:
Configure rtorrent: