Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/extra #79

Closed
wants to merge 31 commits into from
Closed

Feature/extra #79

wants to merge 31 commits into from

Conversation

gboudreau
Copy link
Contributor

Rebased on latest master (83aebdb) and fixed login command that didn't work anymore.
Also fixed an issue where it would use the current folder instead of $HOME/.cache/toutv/ folder for cache on Mac.

@gboudreau
Copy link
Contributor Author

Added another fix where using --url wouldn't work, because the episode page does not contain the emission ID any more; we now need to specify two URLs, for the emission and episode, when using --url with either fetch or info.

@gboudreau
Copy link
Contributor Author

And finally, I made a first draft of downloading episodes from the Extra section using toutv fetch --url [emission_url] [episode_url].
We still can't load the episode or emission information for Extras, but I think most people just want fetch to work. They can find the URLs to use by browsing ici.tou.tv, and then download the episodes they want from the command line.

@gboudreau gboudreau mentioned this pull request Dec 6, 2016
@simark
Copy link
Collaborator

simark commented Dec 6, 2016

Woohoo, thanks! I won't have time to look into it tonight, maybe tomorrow night. If somebody else wants to take a look, go ahead.

@gboudreau
Copy link
Contributor Author

gboudreau commented Dec 7, 2016

So I was able to make info|search|list|fetch work with emissions and episodes in Extra.
Hooray!

Code is a little messy, but it works.

Of note: you will need to delete your .toutv-cache for new emissions & episodes to be loaded from the API.

Copy link
Collaborator

@simark simark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at an login conversation from an Android phone with mitmproxy, it matches pretty much what you added. LGTM.

@simark
Copy link
Collaborator

simark commented Dec 8, 2016

Err, I wanted to comment on the first commit. Is there any way to leave a comment on a particular commit?

@simark
Copy link
Collaborator

simark commented Dec 8, 2016

Pushed your xdg/cache folder commit to master, since it's unrelated and helpful in any case.

@simark
Copy link
Collaborator

simark commented Dec 8, 2016

Instead of requiring the user to enter two URLs (which is a bit tedious), could we solve the problem by having our client do a bit more work? For example, the HTML of an episode contains the show name at least:

            <meta name="rc.emission" content="district-31"/>
            <meta name="rc.codeemission" content="district31"/>

Perhaps we could do another request to look up the show/emission id?

@simark
Copy link
Collaborator

simark commented Dec 8, 2016

Actually, given that an episode url looks like this:

http://ici.tou.tv/district-31/S01E02

We could simply deduce the show URL by keeping the first URL component after the domain... or use the info mentioned in the previous comment and append it to http://ici.tou.tv/. What do you think?

@gboudreau
Copy link
Contributor Author

@simark To comment on any commit part of a PR, simply click the commit that appears in the PR, and comment on specific lines there, or you can go in the Files changed tab at the top of the PR, and comment on whatever change was made.

@gboudreau
Copy link
Contributor Author

Could you rebase the current Feature/extra branch on top of the current master, to make this PR easier to read? It should then automatically adjust to only show the changes I made (if not, I'll manually update my branch).

Copy link
Contributor Author

@gboudreau gboudreau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested by @simark, since the episode URLs look like http://ici.tou.tv/[emission-name]/[episode-name], we could allow using a single URL, and deducing the emission URL.

Another suggestion: allow both an episode URL and an emission URL, when using --url.

@simark
Copy link
Collaborator

simark commented Dec 8, 2016

Could you rebase the current Feature/extra branch on top of the current master, to make this PR easier to read? It should then automatically adjust to only show the changes I made (if not, I'll manually update my branch).

Ok, I've rebased feature/extra on master and force-pushed.

@gboudreau
Copy link
Contributor Author

Excellent. Much better now; easier to review.

So I added two commits which allows a user to specify an emission by name or URL for list, info and fetch, and also specify an episode by name or URL for info and fetch.
Also, when specifying an episode URL, there is no need to specify an emission URL too; it's all handled automatically.

@simark
Copy link
Collaborator

simark commented Dec 8, 2016

Ah good idea about not having to use --url. It makes it even easier to use.

This makes argparse handle automatically the case where the
(sub-)command is omitted.  For example, using just "toutv" would show
the help, but using "toutv --verbose" would result in an exception:

Traceback (most recent call last):
  File "/home/simark/src/pytoutv-env/bin/toutv", line 9, in <module>
    load_entry_point('pytoutv==2.3.1', 'console_scripts', 'toutv')()
  File "/home/simark/src/pytoutv/toutvcli/app.py", line 672, in run
    return app.run()
  File "/home/simark/src/pytoutv/toutvcli/app.py", line 91, in run
    if args.build_client:
AttributeError: 'Namespace' object has no attribute 'build_client'

As a result, we don't return the exit code 10 when bad arguments are
given.

Signed-off-by: Simon Marchi <[email protected]>
Rename _toutvclient to _toutv_client.  Also, initialize it in __init__
to silence PyCharms warning.
... to silence PyCharms warning.
PyCharms complains that toutv.exceptions is not imported.  I am not sure
if it's necessary or not, but it doesn't hurt to have it.
@simark
Copy link
Collaborator

simark commented Dec 15, 2016

@gboudreau, is it possible that the command toutv list doesn't work? I get:

Unknown exception: <class 'AttributeError'>: 'NoneType' object has no attribute 'startswith'
Traceback (most recent call last):
  File "/home/simark/src/pytoutv/toutvcli/app.py", line 99, in run
    args.func(args)
  File "/home/simark/src/pytoutv/toutvcli/app.py", line 381, in _command_list
    emission, episode = self._get_emission_episode_from_args(args)
  File "/home/simark/src/pytoutv/toutvcli/app.py", line 315, in _get_emission_episode_from_args
    if args.emission.startswith('http'):
AttributeError: 'NoneType' object has no attribute 'startswith'

@gboudreau
Copy link
Contributor Author

Indeed. Fixed.

@@ -222,6 +222,8 @@ def _build_argparser(self):
pf.add_argument('-q', '--quality', action='store',
default=App.QUALITY_AVG, choices=quality_choices,
help='Video quality (default: {})'.format(App.QUALITY_AVG))
pf.add_argument('-v', '--verbose', action='store_true',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have a --verbose for each command? If we only have one in the top-level parser, it forces the user to put the -v/--verbose between toutv and the subcommand, but is it a problem? It's a flag that affects the whole program, not just the subcommand, so I think it would make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that would work. Will remove all --verbose param handlers I added to pf/pi/pl. Thanks.

simark and others added 19 commits December 18, 2016 16:46
I don't see any reason why we have to handle the NoMatchExceptions in
different places.  It will give the same result if we catch it along
with the other exceptions, at the top-level (the App.run method).
…g both emission and episode URLs; the emission info is not found in the episode HTML any more...
…mmand:

toutv fetch --url [emission_url] [episode_url]

eg. toutv fetch -q MAX --url 'http://ici.tou.tv/le-show-cache-2' 'http://ici.tou.tv/le-show-cache-2/S2014E01'

We still can't load the episode or emission information for Extras, but I think most people just want `fetch` to work. They can find the URLs to use by browsing ici.tou.tv, and then download the episodes they want from the command line.
…rs; it's now possible to `list`, `search`, `info` and `fetch` those emissions/episodes.

Examples:
toutv list --all # Now returns 3,350 emissions; returned 1,525 before
toutv search|info|list "Le show caché 2"
toutv info "Le show caché 2" S2014E01
toutv info "Le show caché 2" 2425154669
toutv info --url 'http://ici.tou.tv/le-show-cache-2' 'http://ici.tou.tv/le-show-cache-2/S2014E01'
toutv fetch "Le show caché 2"
toutv fetch "Le show caché 2" S2014E02
… instead; no need to specify --url anymore.

Also don't need two URLs anymore; only specifying the episode URL is enough.

Examples:
- toutv fetch|info 'Le show caché 2'
- toutv fetch|info http://ici.tou.tv/le-show-cache-2
- toutv fetch|info 'Le show caché 2' 'S2014E02'
- toutv fetch|info http://ici.tou.tv/le-show-cache-2/S2014E02
- toutv list 'Le show caché 2'
- toutv list http://ici.tou.tv/le-show-cache-2
@simark
Copy link
Collaborator

simark commented Dec 19, 2016

@gboudreau, I rebased your branch and added one commit to allow specifying only an URL to the episode (to fetch and info). Basically, doing toutv fetch http://ici.tou.tv/foo/bar is the same as doing toutv fetch foo bar. If you like it, you can reset --hard this PR with this branch.

It is in my repo: https://github.com/simark/pytoutv/tree/feature/extra

This patch makes it possible to fetch, list or show the info simply by
specifying the URL to the resource (show or episode).  Therefore, it
should now be possible to fetch using one of the following forms:

  - toutv fetch <show>
  - toutv fetch <show> <episode>
  - toutv fetch <show-url>
  - toutv fetch <episode> <url>

Same for info.

We suggested some time ago to try to migrate from "emission" to "show",
since it's a bit silly (although cute) to use franglais.  I am
converting the areas I touch to use that name.

I removed the current test, since it's not very useful, and added a test
for the show/episode argument parsing.  It will be stable, since it
doesn't depend on external factors.
@gboudreau
Copy link
Contributor Author

gboudreau commented Dec 25, 2016

Failure: toutv search "LES AVENTURES DU PHARMACHIEN"
This returns 6 emissions, the correct one twice, and the one emission for each episode! Makes no sense...
Also, toutv fetch "LES AVENTURES DU PHARMACHIEN" only tries to download the first episode...

`toutv search` returned episodes as shows because of this!
…n all the information needed to be able to download them (namely, the PID is missing).

This commit adds the notion of 'short_version' for episodes: the short version of an episode is enough to display it to the end-user, but not enough to download it. So we either load the short version (which can be cached) or the full version, when needed; for example, for `toutv fetch`.
…sodes are returned by `GET GetEpisodesForEmission`; using `GET /presentation/[show_url]` first fixed that.
@gboudreau
Copy link
Contributor Author

Above issue fixed with those last few commits.
Side-effect: downloaded files are now always called ShowName.SxxEyy.Épisode.yy.bitratekbps.ts, i.e. Épisode.yy instead of the episode name. This is because the new GET /presentation/search/ endpoint used to load the episodes for a specific show doesn't return the real episode names, for some reason. But using that endpoint is required to ensure we get all the episodes for a show.

simark pushed a commit to simark/pytoutv that referenced this pull request Jan 2, 2017
@simark
Copy link
Collaborator

simark commented Jan 2, 2017

@gboudreau, I have rebased the branch and pushed it as master. At least now that it's in master, we'll be able to do fixes in more targetted PRs, instead of doing everything in this one.

Thanks a lot!

@simark simark closed this Jan 2, 2017
@gboudreau gboudreau deleted the feature/extra branch January 5, 2017 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants