Esempio n. 1
0
def upload(files, token, assume_yes):
    """Uploads a file(s) to YouTube using the YouTube service API

    This function uploads a list of videos and/or directories of videos to YouTube.

    Args:
        token            - location of an oauth2 token
        files            - list of files and directories to upload
        assume_yes       - if True, assume yes to all interaction (default: False)
    """
    # check if token exists
    if not os.path.exists(token):
        print("{} does not exist, please specify a valid token file".format(token))
    else:
        # Gather videos specified and vids from folders specified into list
        videos = gather_videos(files)
        # Now begin upload process
        if not videos:
            print("Nothing to upload")
        # Prompt for confirmation
        elif prompt_user(videos, confirmation=assume_yes):
            youtube_service = YoutubeService()
            # Authorize with OAuth2 token
            youtube_service.authorize(token)
            for video in videos:
                response_code, response = youtube_service.upload_video(video)
                handle_response(response_code, response)
        # Response was no, so do nothing
        else:
            print("Exiting...")
Esempio n. 2
0
def upload(files, token, assume_yes):
    """Uploads a file(s) to YouTube using the YouTube service API

    This function uploads a list of videos and/or directories of videos to YouTube.

    Args:
        token            - location of an oauth2 token
        files            - list of files and directories to upload
        assume_yes       - if True, assume yes to all interaction (default: False)
    """
    # check if token exists
    if not os.path.exists(token):
        print("{} does not exist, please specify a valid token file".format(
            token))
    else:
        # Gather videos specified and vids from folders specified into list
        videos = gather_videos(files)
        # Now begin upload process
        if not videos:
            print("Nothing to upload")
        # Prompt for confirmation
        elif prompt_user(videos, confirmation=assume_yes):
            youtube_service = YoutubeService()
            # Authorize with OAuth2 token
            youtube_service.authorize(token)
            for video in videos:
                response_code, response = youtube_service.upload_video(video)
                handle_response(response_code, response)
        # Response was no, so do nothing
        else:
            print("Exiting...")
Esempio n. 3
0
 def test_upload_video(self):
     """Test uploading a video file using mocks"""
     youtube = YoutubeService()
     youtube.upload_video = Mock(return_value=(Response.SUCCESS, None))
     response_code, response = youtube.upload_video(self.SAMPLE_VIDEO)
     youtube.upload_video.assert_called_with(self.SAMPLE_VIDEO)
     self.assertEqual(Response.SUCCESS, response_code)
Esempio n. 4
0
def gather_videos(files):
    """Gather all valid videos into a set for upload"""
    # Because we are using a set, no duplicates will be present
    videos = set()
    for item in files:
        # Crawl subfolders
        if os.path.isdir(item):
            for root, _, filenames in os.walk(item):
                for filename in filenames:
                    filepath = os.path.join(root, filename)
                    # Check if its a video
                    if YoutubeService.valid_video_file(filepath):
                        videos.add(filepath)
        # If it exists it is a single file, check if its a video
        elif os.path.exists(item) and YoutubeService.valid_video_file(item):
            videos.add(item)
    return videos
Esempio n. 5
0
def gather_videos(files):
    """Gather all valid videos into a set for upload"""
    # Because we are using a set, no duplicates will be present
    videos = set()
    for item in files:
        # Crawl subfolders
        if os.path.isdir(item):
            for root, _, filenames in os.walk(item):
                for filename in filenames:
                    filepath = os.path.join(root, filename)
                    # Check if its a video
                    if YoutubeService.valid_video_file(filepath):
                        videos.add(filepath)
        # If it exists it is a single file, check if its a video
        elif os.path.exists(item) and YoutubeService.valid_video_file(item):
            videos.add(item)
    return videos
Esempio n. 6
0
    def upload(self, files, token, yes):
        """Uploads a file(s) to YouTube using the YouTube service API

        This function uploads a list of videos and/or directories of videos to YouTube.

        Args:
            token            - location of an oauth2 token
            files            - list of files and directories to upload
            yes              - if True, assume yes to all interaction (default: False)
        """
        # check if token exists
        if not os.path.exists(token):
            print(
                "{} does not exist, please specify a valid token file".format(
                    token))
            return
        # gather videos specified and vids from folders specified into list
        videos = []
        for item in files:
            # crawl subfolders
            if os.path.isdir(item):
                for root, dirs, files_ in os.walk(item):
                    for f in files_:
                        filepath = os.path.join(root, f)
                        # check if its a video and make sure its not a duplicate
                        if YoutubeService.valid_video_file(
                                filepath) and filepath not in videos:
                            videos.append(filepath)
            # if it exists it is a single file, check if its a video, and make sure its not a duplicate
            elif os.path.exists(item) and YoutubeService.valid_video_file(
                    item) and item not in videos:
                videos.append(item)
        # now begin upload process
        if not videos:
            print("Nothing to upload")
        else:
            youtube_service = YoutubeService()
            # authorize with OAuth2 token
            youtube_service.authorize(token)
            if not yes:
                print("Found videos:")
                print("\n".join(videos))
            question = "Are you sure you would like to upload these videos? [Y/n] "
            if yes or raw_input(question).lower() in ('', 'y', 'yes'):
                for video in videos:
                    self.handle_response(youtube_service.upload_video(video))
Esempio n. 7
0
    def upload(self, files, token, yes):
        """Uploads a file(s) to YouTube using the YouTube service API

        This function uploads a list of videos and/or directories of videos to YouTube.

        Args:
            token            - location of an oauth2 token
            files            - list of files and directories to upload
            yes              - if True, assume yes to all interaction (default: False)
        """
        # check if token exists
        if not os.path.exists(token):
            print("{} does not exist, please specify a valid token file".format(token))
            return
        # gather videos specified and vids from folders specified into list
        videos = []
        for item in files:
            # crawl subfolders
            if os.path.isdir(item):
                for root, dirs, files_ in os.walk(item):
                    for f in files_:
                        filepath = os.path.join(root, f)
                        # check if its a video and make sure its not a duplicate
                        if YoutubeService.valid_video_file(filepath) and filepath not in videos:
                            videos.append(filepath)
            # if it exists it is a single file, check if its a video, and make sure its not a duplicate
            elif os.path.exists(item) and YoutubeService.valid_video_file(item) and item not in videos:
                videos.append(item)
        # now begin upload process
        if not videos:
            print("Nothing to upload")
        else:
            youtube_service = YoutubeService()
            # authorize with OAuth2 token
            youtube_service.authorize(token)
            if not yes:
                print("Found videos:")
                print("\n".join(videos))
            question = "Are you sure you would like to upload these videos? [Y/n] "
            if yes or raw_input(question).lower() in ('', 'y', 'yes'):
                for video in videos:
                    self.handle_response(youtube_service.upload_video(video))
Esempio n. 8
0
    def cmd_line(self, argv):
        """Initializes command line interface

        Args:
            argv: command line arguments to parse
        """
        self.parser.add_argument("-c", "--client_secrets",
                                 help="Path to client secrets file", default=self.client_secrets)
        self.parser.add_argument("-t", "--token",
                                 help="Path to OAuth2 token", default=self.oauth2_token)
        self.parser.add_argument("-f", "--files",
                                 help="Path to file or filefolder for upload", default=self.video_directory)
        self.parser.add_argument("-y", "--yes",
                                 help="Assume yes", action="store_true")
        flags = self.parser.parse_args(argv[1:])
        youtube_service = YoutubeService()
        # command line arguments neede for Google Python Client need to always be passed in for authentication
        youtube_service.authenticate(flags.client_secrets, flags.token, flags)
        # path doesn't exist, print an error message
        if not os.path.exists(flags.files):
            print "{} does not exit".format(flags.files)
        # path is a folder, upload all videos in the folder
        elif os.path.isdir(flags.files):
            self.upload_folder_cmd_line(youtube_service, flags.files, flags.yes)
        # single file check if it is an uploadable video file
        elif youtube_service.valid_video_file(flags.files):
            if flags.yes:
                self.handle_response(youtube_service.upload_video(flags.files))
            else:
                response = raw_input(
                    "Are you sure you would like to upload the following file? [Y/n]\n" + flags.files + "\n")
                if response.lower() in ('', 'y', 'yes'):
                    self.handle_response(youtube_service.upload_video(flags.files))
        # if this case is reached it means there is nothing to upload
        else:
            print "Nothing to upload"
Esempio n. 9
0
def parse_args(parser, parse_args=None):
    if len(sys.argv) == 1:  # No arguments passed
        launch_recordapp()

    args = parser.parse_args(parse_args)

    if args.app == 'record':
        if len(sys.argv) == 2:  # No 'record' arguments passed
            launch_recordapp()

        import gobject
        # Must declare after argparse otherwise GStreamer will take over the cli help
        from freeseer.frontend.record.RecordingController import RecordingController

        # TODO: Abstract the database stuff away from here as it's only
        #       used in conjunction with talks.
        if args.profile is None:  # Profile is an optional parameter
            args.profile = 'default'
        profile = settings.profile_manager.get(args.profile)
        config = profile.get_config('freeseer.conf', settings.FreeseerConfig,
                                    storage_args=['Global'], read_only=False)
        # XXX: There should only be 1 database per user. Workaround for this
        #      is to put it in the 'default' profile.
        db = settings.profile_manager.get().get_database()

        app = RecordingController(profile, db, config, cli=True)

        if args.talk:
            if app.record_talk_id(args.talk):
                sys.exit(gobject.MainLoop().run())
        elif args.filename:
            if app.record_filename(args.filename):
                sys.exit(gobject.MainLoop().run())
        elif args.show_talks:
            app.print_talks()

    elif args.app == 'config':
        if len(sys.argv) == 2:  # No 'config' arguments passed
            launch_configtool()

        from freeseer.settings import configdir
        from freeseer.framework.util import reset
        from freeseer.framework.util import reset_configuration
        from freeseer.framework.util import reset_database
        from freeseer.framework.youtube import YoutubeService

        if args.config_service == "reset":
            if args.reset == "all":
                reset(configdir)
            elif args.reset == "configuration":
                reset_configuration(configdir, args.profile)
            elif args.reset == "database":
                reset_database(configdir, args.profile)
            else:
                print("Invalid reset option.")

        elif args.config_service == "youtube":
            YoutubeService.acquire_token(args.client_secrets, args.token, args)

    elif args.app == 'talk':
        if len(sys.argv) == 2:  # No 'talk' arguments passed
            launch_talkeditor()

        from freeseer.framework.presentation import Presentation

        profile = settings.profile_manager.get()
        db = profile.get_database()

        if args.action == "add":
            presentation = Presentation(args.title,
                                        speaker=args.speaker,
                                        room=args.room,
                                        event=args.event)
            db.insert_presentation(presentation)

        elif args.action == "remove":
            db.delete_presentation(args.talk_id)

        elif args.action == "clear":
            db.clear_database()

        elif args.action == "list":
            talks_query = db.get_talks()
            talks_table = []
            while talks_query.next():
                record = talks_query.record()
                talks_table.append([
                    talks_query.value(record.indexOf('id')).toString(),
                    talks_query.value(record.indexOf('title')).toString(),
                    talks_query.value(record.indexOf('speaker')).toString(),
                    talks_query.value(record.indexOf('event')).toString(),
                ])
            if talks_table:
                print(tabulate(talks_table, headers=["ID", "Title", "Speaker", "Event"]))
            else:
                print("No talks present.")

        else:
            print("Invalid option.")

    elif args.app == 'report':
        if len(sys.argv) == 2:  # No 'report' arguments passed
            launch_reporteditor()

    elif args.app == 'upload':
        if args.upload_service == 'youtube':
            youtube.upload(args.files, args.token, args.yes)

    elif args.app == 'server':
        if args.filename:
            launch_server(args.filename)
        else:
            launch_server()
Esempio n. 10
0
def parse_args(parser, parse_args=None):
    if len(sys.argv) == 1:  # No arguments passed
        launch_recordapp()

    args = parser.parse_args(parse_args)

    if args.app == 'record':
        if len(sys.argv) == 2:  # No 'record' arguments passed
            launch_recordapp()

        import gobject
        # Must declare after argparse otherwise GStreamer will take over the cli help
        from freeseer.frontend.record.RecordingController import RecordingController

        # TODO: Abstract the database stuff away from here as it's only
        #       used in conjunction with talks.
        if args.profile is None:  # Profile is an optional parameter
            args.profile = 'default'
        profile = settings.profile_manager.get(args.profile)
        config = profile.get_config('freeseer.conf',
                                    settings.FreeseerConfig,
                                    storage_args=['Global'],
                                    read_only=False)
        # XXX: There should only be 1 database per user. Workaround for this
        #      is to put it in the 'default' profile.
        db = settings.profile_manager.get().get_database()

        app = RecordingController(profile, db, config, cli=True)

        if args.talk:
            if app.record_talk_id(args.talk):
                sys.exit(gobject.MainLoop().run())
        elif args.filename:
            if app.record_filename(args.filename):
                sys.exit(gobject.MainLoop().run())
        elif args.show_talks:
            app.print_talks()

    elif args.app == 'config':
        if len(sys.argv) == 2:  # No 'config' arguments passed
            launch_configtool()

        from freeseer.settings import configdir
        from freeseer.framework.util import reset
        from freeseer.framework.util import reset_configuration
        from freeseer.framework.util import reset_database
        from freeseer.framework.youtube import YoutubeService

        if args.reset:
            reset(configdir)
        elif args.reset_configuration:
            reset_configuration(configdir)
        elif args.reset_database:
            reset_database(configdir)
        elif args.config_service == "youtube":
            YoutubeService.acquire_token(args.client_secrets, args.token, args)

    elif args.app == 'talk':
        if len(sys.argv) == 2:  # No 'talk' arguments passed
            launch_talkeditor()

        from freeseer.framework.presentation import Presentation

        profile = settings.profile_manager.get()
        db = profile.get_database()

        if args.action == "add":
            presentation = Presentation(args.title,
                                        speaker=args.speaker,
                                        room=args.room,
                                        event=args.event)
            db.insert_presentation(presentation)

        elif args.action == "remove":
            db.delete_presentation(args.talk_id)

        elif args.action == "clear":
            db.clear_database()

        else:
            print("Invalid option.")

    elif args.app == 'report':
        if len(sys.argv) == 2:  # No 'report' arguments passed
            launch_reporteditor()

    elif args.app == 'upload':
        if args.upload_service == 'youtube':
            youtube = YoutubeFrontend()
            youtube.upload(args.files, args.token, args.yes)
Esempio n. 11
0
def test_valid_video_file(video, expected):
    """Tests valid_video_file function for all test cases."""
    assert YoutubeService.valid_video_file(video) == expected
Esempio n. 12
0
    def test_get_metadata(self):
        """Test retrieval of metadata from video file.

        Case: Returned metadata should be equal to sample video's metadata."""
        metadata = YoutubeService.get_metadata(self.SAMPLE_VIDEO)
        self.assertDictEqual(self.SAMPLE_VIDEO_METADATA, metadata)