Repository: youtube-dl
Issue: [Request] Add Cablevision (Optimum) to --ap-mso
Labels: tv-provider-account-needed

## Please follow the guide below

- You will be asked some questions and requested to provide some information, please read them **carefully** and answer honestly
- Put an `x` into all the boxes [ ] relevant to your *issue* (like this: `[x]`)
- Use the *Preview* tab to see what your issue will actually look like

---

### Make sure you are using the *latest* version: run `youtube-dl --version` and ensure your version is *2017.12.28*. If it's not, read [this FAQ entry](https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl) and update. Issues with outdated version will be rejected.
- [ x] I've **verified** and **I assure** that I'm running youtube-dl **2017.12.28**

### Before submitting an *issue* make sure you have:
- [ x] At least skimmed through the [README](https://github.com/rg3/youtube-dl/blob/master/README.md), **most notably** the [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x ] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones

### What is the purpose of your *issue*?
- [ ] Bug report (encountered problems with youtube-dl)
- [ ] Site support request (request for adding support for a new site)
- [ x] Feature request (request for a new functionality)
- [x ] Question
- [ ] Other

---

### The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your *issue*

---


---

I have Optimum (Cablevision in NYC) but it is currently not an option in the --ap-mso list.  

Sample url: http://www.wetv.com/shows/mama-june-from-not-to-hot/full-episode/season-01/the-confrontation

Looking at the source code, 'Optimum' is labeled as 'Cablevision'.  I attempted to add the following but i am not able to successfully authenticate.

-- adobepass.py --
,
    'Cablevision': {
        'name': 'Cablevision',
        'username_field': 'IDToken1',
        'password_field': 'IDToken2',
    }


Looking at Optimum's login page, it looks like there is 3 hidden forms and the mso goes for the first one which is for hte username part.  I added the following in an attempt to get it to login


        def post_form_cablevision(form_page_res, note, data={}):
            form_page, urlh = form_page_res
            post_url = self._html_search_regex(r'<form   name[^>]+action=(["\'])(?P<url>.+?)\1', form_page, 'post url', group='url')
			
            if not re.match(r'https?://', post_url):
                post_url = compat_urlparse.urljoin(urlh.geturl(), post_url)
            form_data = self._hidden_inputs(form_page)
            form_data.update(data)
            return self._download_webpage_handle(
                post_url, video_id, note, data=urlencode_postdata(form_data), headers={
                    'Content-Type': 'application/x-www-form-urlencoded',
                })




After the if mso_id == 'Comcast_SSO': section, I added

                	elif mso_id == 'Cablevision':
                	# This will be for Cablevision login 
                	provider_redirect_page, urlh = provider_redirect_page_res
                	provider_refresh_redirect_url = extract_redirect_url( provider_redirect_page, url=urlh.geturl() )
                	if provider_refresh_redirect_url:
                		provider_redirect_page_res = self._download_webpage_handle( provider_refresh_redirect_url, video_id, 'Downloading Provider Redirect Page (meta refresh)')
                	provider_login_page_res = post_form( provider_redirect_page_res, self._DOWNLOADING_LOGIN_PAGE)
                	html_code = provider_login_page_res[0].split('\n')
                	for line in html_code:
               			if 'name="goto" value="' in line:
			   				goto = line.strip().replace('<input type="hidden" name="goto" value="','').replace('">','')
			   			
               			if 'SunQueryParamsString' in line:
			   				sunquery = line.strip().replace('<input type="hidden" name="SunQueryParamsString" value="','').replace('">','')
                	mvpd_confirm_page_res = post_form_cablevision(provider_login_page_res, 'Logging in', {
	                	mso_info.get('username_field', 'username'): username,
	                    mso_info.get('password_field', 'password'): password,
	                    'goto': goto,
	                    'SunQueryParamString': sunquery,
	                    'encoded': 'true',
	                    'gx_charset': 'UTF-8',
	                    'IDButton': '',
	                })



When It tries to log in, i get a 401 - HTTP Error 401: Unauthorized -- Authentication Exception due to incorrect handler.

If i leave it with the original post_form then I get a HTTP Error 500: Internal Server Error


My apologies if I am rambling.

---