Ejemplo n.º 1
0
    def upload(
        self,
        video_path: str,
        title: str,
        description: str,
        tags: List[str],
        _timeout: Optional[int] = 60 * 3,  # 3 min
        extra_sleep_after_upload: Optional[int] = None,
        extra_sleep_before_publish: Optional[int] = None
    ) -> (bool, Optional[str]):
        if _timeout is not None:
            try:
                with timeout.timeout(_timeout):
                    return self.__upload(
                        video_path,
                        title,
                        description,
                        tags,
                        extra_sleep_after_upload=extra_sleep_after_upload,
                        extra_sleep_before_publish=extra_sleep_before_publish)
            except Exception as e:
                print('Upload', e)
                # self.browser.get(YT_URL)

                return False, None
        else:
            return self.__upload(
                video_path,
                title,
                description,
                tags,
                extra_sleep_after_upload=extra_sleep_after_upload,
                extra_sleep_before_publish=extra_sleep_before_publish)
Ejemplo n.º 2
0
    def __login_auto(self, email: str, password: str) -> bool:
        self.browser.get(YT_LOGIN_URL)
        time.sleep(0.5)

        try:
            with timeout.timeout(30):
                email_field = self.browser.find_by('input', {
                    'id': 'identifierId',
                    'type': 'email'
                })
                email_field.click()
                self.browser.send_keys_delay_random(email_field, email)
                time.sleep(1)
                self.browser.find_by('div', {
                    'jscontroller': 'VXdfxd',
                    'role': 'button'
                }).click()
                time.sleep(1)

                from selenium.webdriver.common.action_chains import ActionChains
                action = ActionChains(self.browser.driver)

                pass_container = self.browser.find_by('div', {
                    'id': 'password',
                    'jscontroller': 'pxq3x'
                })
                pass_field = self.browser.find_by('input',
                                                  {'type': 'password'},
                                                  in_element=pass_container)
                action.move_to_element(pass_field).perform()
                pass_field.click()
                self.browser.send_keys_delay_random(pass_field, password)
                time.sleep(1)
                self.browser.find_by('div', {
                    'jscontroller': 'VXdfxd',
                    'role': 'button'
                }).click()
                time.sleep(1)
        except Exception as e:
            print('__login_auto', e)

        self.browser.get(YT_URL)
        time.sleep(0.5)

        return self.is_logged_in
Ejemplo n.º 3
0
    def comment_on_video(self,
                         video_id: str,
                         comment: str,
                         pinned: bool = False,
                         _timeout: Optional[int] = 15) -> (bool, bool):
        if _timeout is not None:
            try:
                with timeout.timeout(_timeout):
                    return self.__comment_on_video(video_id,
                                                   comment,
                                                   pinned=pinned)
            except Exception as e:
                print('Comment', e)
                # self.browser.get(YT_URL)

                return False, False
        else:
            return self.__comment_on_video(video_id, comment, pinned=pinned)
Ejemplo n.º 4
0
    def upload(
        self,
        video_path: str,
        title: str,
        description: str,
        tags: List[str],
        made_for_kids: bool = False,
        visibility: Visibility = Visibility.PUBLIC,
        thumbnail_image_path: Optional[str] = None,
        _timeout: Optional[int] = 60 * 3,  # 3 min
        extra_sleep_after_upload: Optional[int] = None,
        extra_sleep_before_publish: Optional[int] = None
    ) -> (bool, Optional[str]):

        if _timeout is not None:
            try:
                with timeout.timeout(_timeout):
                    return self.__upload(
                        video_path,
                        title,
                        description,
                        tags,
                        made_for_kids=made_for_kids,
                        visibility=visibility,
                        thumbnail_image_path=thumbnail_image_path,
                        extra_sleep_after_upload=extra_sleep_after_upload,
                        extra_sleep_before_publish=extra_sleep_before_publish)
            except Exception as e:
                print('Upload', e)
                # self.browser.get(YT_URL)

                return False, None
        else:
            return self.__upload(
                video_path,
                title,
                description,
                tags,
                made_for_kids=made_for_kids,
                visibility=visibility,
                thumbnail_image_path=thumbnail_image_path,
                extra_sleep_after_upload=extra_sleep_after_upload,
                extra_sleep_before_publish=extra_sleep_before_publish)
Ejemplo n.º 5
0
def func_with_return():
    time.sleep(0.25)

    return 'return_val'


try:
    timeout.run(func, 1)
except Exception as e:
    print(e)

try:
    timeout.run(
        timeout.partial(func_with_arguments, 0.25, extra_print='extra'), 1)
except Exception as e:
    print(e)

try:
    print(timeout.run(func_with_return, 1))
except Exception as e:
    print(e)

try:
    with timeout.timeout(1):
        while True:
            sleep_time = 0.25
            time.sleep(sleep_time)

            print('Sleeping', sleep_time, 'sec')
except Exception as e:
    print(e)