Exemple #1
0
from pony.orm import db_session, select
from core.history import Video, VideoHosts, OldVideo
from core.video import VideoHostManager

vhm = VideoHostManager()

hosts = ["", "RedditVideo", "Streamable", "LinkVideo"]

with db_session:
    for i in select(g for g in OldVideo):
        new = Video(origin_host=VideoHosts[hosts[i.origin_host]],
                    origin_id=i.origin_id,
                    reversed_host=VideoHosts[hosts[i.reversed_host]],
                    reversed_id=i.reversed_id,
                    time=i.time,
                    nsfw=i.nsfw,
                    total_requests=i.total_requests,
                    last_requested_date=i.last_requested_date)
Exemple #2
0
reddit = praw.Reddit(user_agent=consts.user_agent,
                     client_id=credentials['reddit']['client_id'],
                     client_secret=credentials['reddit']['client_secret'],
                     username=credentials['reddit']['username'],
                     password=credentials['reddit']['password'])


def get_date(seconds):
    return datetime.datetime.utcfromtimestamp(seconds).\
        replace(tzinfo=datetime.timezone.utc).astimezone(tz=None)


print("CoffinBot Statistics v{} Ctrl+C to stop".format(consts.version))

ghm = VideoHostManager(reddit)
counter = 0
users = defaultdict(int)
karma = {}
videos = {}

for comment in reddit.user.me().comments.new(limit=None):
    counter += 1
    author = comment.parent().author
    print(counter, comment.id, author, ghm.extract_video(comment.body),
          get_date(comment.created_utc))
    if author:
        users[author.name] += 1
    # pprint(vars(comment))
    karma[comment.id] = comment.ups - comment.downs
Exemple #3
0
from pprint import pprint
from core import constants as consts
from core.credentials import CredentialsLoader
from core.video import VideoHostManager, CANNOT_UPLOAD, UPLOAD_FAILED
from core.history import check_database, add_to_database, delete_from_database, list_by_oldest_access

CUTOFF = datetime.date.today() - datetime.timedelta(weeks=9 * 4)

print(CUTOFF)

credentials = CredentialsLoader().get_credentials()

# Only needed to initialize ghm
reddit = praw.Reddit(user_agent=consts.user_agent,
                     client_id=credentials['reddit']['client_id'],
                     client_secret=credentials['reddit']['client_secret'],
                     username=credentials['reddit']['username'],
                     password=credentials['reddit']['password'])

ghm = VideoHostManager(reddit)
catbox = ghm.host_names['Catbox']

videos = list_by_oldest_access(catbox, CUTOFF)
print(len(videos))
print(videos[0].reversed_id, videos[0].last_requested_date)

for video in videos:
    catbox_video = catbox.get_video(id=video.reversed_id)
    catbox.delete(catbox_video)
    delete_from_database(catbox_video)
Exemple #4
0
def process_comment(reddit, comment=None, queue=None, original_context=None):
    vhm = VideoHostManager(reddit)
    if not original_context:  # If we were not provided context, make our own
        # Check if comment is deleted
        if not comment.author:
            print("Comment doesn't exist????")
            print(vars(comment))
            return USER_FAILURE

        print("New request by " + comment.author.name)

        # Create the comment context object
        context = CommentContext(reddit, comment, vhm)
        if not context.url:  # Did our search return nothing?
            print("Didn't find a URL")
            return USER_FAILURE

        if context.rereverse and not context.reupload:  # Is the user asking to rereverse?
            reply(context, context.url)
            return SUCCESS

    else:  # If we are the client, context is provided to us
        context = original_context

    # Create object to grab video from host
    # print(context.url)
    # video_host = VideoHost.open(context, reddit)

    # new_original_video = ghm.extract_video(context.url, context=context)
    new_original_video = context.url
    print(new_original_video)

    # If the link was not recognized, return
    # if not video_host:
    #     return USER_FAILURE

    if not new_original_video:
        return USER_FAILURE

    # If the video was unable to be acquired, return
    # original_video = video_host.get_video()
    # if not original_video:
    #     return USER_FAILURE

    if not new_original_video.id:
        return USER_FAILURE

    if queue:
        # Add to queue
        print("Adding to queue...")
        queue.add_job(context.to_json(), new_original_video)
        return SUCCESS

    # Check database for video before we reverse it
    video = check_database(new_original_video)

    # Requires new database setup
    # db_video = check_database(new_original_video)

    if video:  # db_video
        # If we were asked to reupload, double check the video
        if context.reupload:
            print("Doing a reupload check...")
            if not is_reupload_needed(reddit, video):
                # No reupload needed, do normal stuff
                reply(context, video)
                print("No reupload needed")
                return SUCCESS
            else:
                # Reupload is needed, delete this from the database
                delete_from_database(video)
                print("Reupload needed")
        # Proceed as normal
        else:
            # If it was in the database, reuse it
            reply(context, video)
            return SUCCESS

    # Analyze how the video should be reversed
    # in_format, out_format = video_host.analyze()

    # If there was some problem analyzing, exit
    # if not in_format or not out_format:
    #     return USER_FAILURE

    if not new_original_video.analyze():
        return USER_FAILURE

    uploaded_video = None

    # This video cannot be uploaded and it is not our fault
    cant_upload = False

    # Try every option we have for reversing a video
    for file in new_original_video.files:
        original_video_file = file
        upload_video_host = vhm.get_upload_host(file)

        if not upload_video_host:
            print("File too large {}s {}MB".format(
                new_original_video.files[0].duration,
                new_original_video.files[0].size))
            cant_upload = True
            continue
        else:
            cant_upload = False

        # Using the provided host, perform the upload
        for i in range(2):
            result = upload_video_host.upload(original_video_file.id,
                                              original_video_file.type,
                                              new_original_video.nsfw,
                                              original_video_file.audio)
            # If the host simply cannot accept this file at all
            if result == CANNOT_UPLOAD:
                cant_upload = True
                break
            # If the host was unable to accept the video at this time
            elif result == UPLOAD_FAILED:
                cant_upload = False
                continue  # Try again?
            # No error and not None, success!
            elif result:
                uploaded_video = result
                break

        # If we have the uploaded video, break out and continue
        if uploaded_video:
            break

    # If there was an error, return it
    if cant_upload:
        return USER_FAILURE
    # It's not that it was an impossible request, there was something else
    elif not uploaded_video:
        return UPLOAD_FAILURE

    if uploaded_video:
        # Add video to database
        # if reversed_video.log:
        add_to_database(new_original_video, uploaded_video)
        # Reply
        print("Replying!", uploaded_video.url)
        reply(context, uploaded_video)
        return SUCCESS
    else:
        return UPLOAD_FAILURE