Repository: streamlink/streamlink

Issue:
pyCrypto module needed on Windows
Many thanks to all the team for all that's been accomplished so far!

OS is Windows Vista SP2 x86, latest MS updates. Trying to rip the clips from: 
[Watch The 2016 MTV EMA Performances](http://www.mtv.co.uk/ema/videos/watch-the-2016-mtv-ema-performances#lush-lifeaint-my-fault-live-at-the-2016-mtv-emas) (all 14 of them!). 
They are using AppleHLS stream methodology (through Adobe Flash Player plugin), 
Firefox's "Web Console" is being used as a "URL sniffer" to retrieve the URIs 
of the master HLS playlists. 
E.g. the 3rd clip in the list (_Zara Larsson - Lush Life + Ain't My Fault (Live At The 2016 MTV EMAs_)) 
would, in my machine some minutes ago, generate the following "master.m3u8" URI: 

`https://cp450888-vh.akamaihd.net/i/mtviestor/_!/intlod/MTVInternational/MBUS/TACTIC/MVI_dev/INDIE/VIAMTVIPY/C9849AELU0/VIAMTVIPYC9849AELU0_,384x216_150_b30,384x216_400_m30,448x252_450_b30,512x288_750_m30,640x360_1200_m30,960x540_2200_m31,1280x720_3500_h32,.mp4.csmil/master.m3u8?hdnea=st%3D1478827808%7Eexp%3D1478842208%7Eacl%3D%2Fi%2Fmtviestor%2F_*%2Fintlod%2FMTVInternational%2FMBUS%2FTACTIC%2FMVI_dev%2FINDIE%2FVIAMTVIPY%2FC9849AELU0%2FVIAMTVIPYC9849AELU0_%2C384x216_150_b30%2C384x216_400_m30%2C448x252_450_b30%2C512x288_750_m30%2C640x360_1200_m30%2C960x540_2200_m31%2C1280x720_3500_h32%2C.mp4.csmil%2F*%7Ehmac%3D2a2832ab8eaa83616893a8205ab193153af54097d724f98252d7bf2a4d137159&__a__=off&__b__=450&__viacc__=NONE"` 

(If you want to test yourself, generate a fresh one on your machine!)

The version of Streamlink used is the Py3.5.2 based standalone package created by @RosadinTV 
(see https://github.com/streamlink/streamlink/issues/86), but in all probability my reported issue would've also happened had I been using 
the official Win32 installer at [streamlink-0.0.2.exe](https://github.com/streamlink/streamlink/releases/download/0.0.2/streamlink-0.0.2.exe)

Trying to fetch the above clip with streamlink fails, because the pyCrypto module is needed: 
```
F:\Applications\Livestreamer\StreamlinkPortable[byRosadinTV]\Streamlink-0.0.2-wi
n32-v2.0>streamlink -o "03. Zara Larsson - Lush Life + Ain't My Fault (Live At T
he 2016 MTV EMAs).ts" "hlsvariant://https://cp450888-vh.akamaihd.net/i/mtvies
tor/_!/intlod/MTVInternational/MBUS/TACTIC/MVI_dev/INDIE/VIAMTVIPY/C9849AELU0/VI
AMTVIPYC9849AELU0_,384x216_150_b30,384x216_400_m30,448x252_450_b30,512x288_750_m
30,640x360_1200_m30,960x540_2200_m31,1280x720_3500_h32,.mp4.csmil/master.m3u8?hd
nea=st%3D1478827808%7Eexp%3D1478842208%7Eacl%3D%2Fi%2Fmtviestor%2F_*%2Fintlod%2F
MTVInternational%2FMBUS%2FTACTIC%2FMVI_dev%2FINDIE%2FVIAMTVIPY%2FC9849AELU0%2FVI
AMTVIPYC9849AELU0_%2C384x216_150_b30%2C384x216_400_m30%2C448x252_450_b30%2C512x2
88_750_m30%2C640x360_1200_m30%2C960x540_2200_m31%2C1280x720_3500_h32%2C.mp4.csmi
l%2F*%7Ehmac%3D2a2832ab8eaa83616893a8205ab193153af54097d724f98252d7bf2a4d137159&
__a__=off&__b__=450&__viacc__=NONE" best
[cli][info] Found matching plugin stream for URL hlsvariant://https://cp450888-v
h.akamaihd.net/i/mtviestor/_!/intlod/MTVInternational/MBUS/TACTIC/MVI_dev/INDIE/
VIAMTVIPY/C9849AELU0/VIAMTVIPYC9849AELU0_,384x216_150_b30,384x216_400_m30,448x25
2_450_b30,512x288_750_m30,640x360_1200_m30,960x540_2200_m31,1280x720_3500_h32,.m
p4.csmil/master.m3u8?hdnea=st%3D1478827808%7Eexp%3D1478842208%7Eacl%3D%2Fi%2Fmtv
iestor%2F_*%2Fintlod%2FMTVInternational%2FMBUS%2FTACTIC%2FMVI_dev%2FINDIE%2FVIAM
TVIPY%2FC9849AELU0%2FVIAMTVIPYC9849AELU0_%2C384x216_150_b30%2C384x216_400_m30%2C
448x252_450_b30%2C512x288_750_m30%2C640x360_1200_m30%2C960x540_2200_m31%2C1280x7
20_3500_h32%2C.mp4.csmil%2F*%7Ehmac%3D2a2832ab8eaa83616893a8205ab193153af54097d7
24f98252d7bf2a4d137159&__a__=off&__b__=450&__viacc__=NONE
[cli][info] Available streams: 216p (worst), 252p, 288p, 360p, 540p, 720p (best)

[cli][info] Opening stream: 720p (hls)
[cli][error] Could not open stream: Need pyCrypto installed to decrypt this stre
am
```
As far as I can tell, neither the package I am currently using nor the official win32 installer 
has by default the pyCrypto module installed; I am not seeing an easy way to install it 
on my standalone package (probably because of my limited python-fu), 
and I am wondering whether it's at all possible in the case of the standard win installation (?).

In the end, I had to go back to livestreamer, because the last 
windows nightly package published at [Nightly Zip build](http://livestreamer-builds.s3.amazonaws.com/livestreamer-latest-win32.zip) 
apparently has the pyCrypto module integrated, hence: 
```
F:\Applications\Livestreamer\livestreamer-v1.12.2-120-gab80dbd>livestreamer -o "
03. Zara Larsson - Lush Life + Ain't My Fault (Live At The 2016 MTV EMAs).ts"
 "hlsvariant://https://cp450888-vh.akamaihd.net/i/mtviestor/_!/intlod/MTVInterna
tional/MBUS/TACTIC/MVI_dev/INDIE/VIAMTVIPY/C9849AELU0/VIAMTVIPYC9849AELU0_,384x2
16_150_b30,384x216_400_m30,448x252_450_b30,512x288_750_m30,640x360_1200_m30,960x
540_2200_m31,1280x720_3500_h32,.mp4.csmil/master.m3u8?hdnea=st%3D1478827808%7Eex
p%3D1478842208%7Eacl%3D%2Fi%2Fmtviestor%2F_*%2Fintlod%2FMTVInternational%2FMBUS%
2FTACTIC%2FMVI_dev%2FINDIE%2FVIAMTVIPY%2FC9849AELU0%2FVIAMTVIPYC9849AELU0_%2C384
x216_150_b30%2C384x216_400_m30%2C448x252_450_b30%2C512x288_750_m30%2C640x360_120
0_m30%2C960x540_2200_m31%2C1280x720_3500_h32%2C.mp4.csmil%2F*%7Ehmac%3D2a2832ab8
eaa83616893a8205ab193153af54097d724f98252d7bf2a4d137159&__a__=off&__b__=450&__vi
acc__=NONE" best
[cli][info] Found matching plugin stream for URL hlsvariant://https://cp450888-v
h.akamaihd.net/i/mtviestor/_!/intlod/MTVInternational/MBUS/TACTIC/MVI_dev/INDIE/
VIAMTVIPY/C9849AELU0/VIAMTVIPYC9849AELU0_,384x216_150_b30,384x216_400_m30,448x25
2_450_b30,512x288_750_m30,640x360_1200_m30,960x540_2200_m31,1280x720_3500_h32,.m
p4.csmil/master.m3u8?hdnea=st%3D1478827808%7Eexp%3D1478842208%7Eacl%3D%2Fi%2Fmtv
iestor%2F_*%2Fintlod%2FMTVInternational%2FMBUS%2FTACTIC%2FMVI_dev%2FINDIE%2FVIAM
TVIPY%2FC9849AELU0%2FVIAMTVIPYC9849AELU0_%2C384x216_150_b30%2C384x216_400_m30%2C
448x252_450_b30%2C512x288_750_m30%2C640x360_1200_m30%2C960x540_2200_m31%2C1280x7
20_3500_h32%2C.mp4.csmil%2F*%7Ehmac%3D2a2832ab8eaa83616893a8205ab193153af54097d7
24f98252d7bf2a4d137159&__a__=off&__b__=450&__viacc__=NONE
[cli][info] Available streams: 216p (worst), 252p, 288p, 360p, 540p, 720p (best)

[cli][info] Opening stream: 720p (hls)
[download][..he 2016 MTV EMAs).ts.ts] Written 99.1 MB (1m14s @ 1.4 MB/s)       [
cli][info] Stream ended
```
I am aware that Windows always represents a PITA 
for the developers of Open Source apps, however 
any resolution of this issue (marginal as it may be) 
will be highly welcome!

Many regards.


Discussion:
@Vangelis66
Hi, download this and extract inside the Streamlink folder of my release:
https://1drv.ms/u/s!AteNlrENG5PD9WfqTY3jZ2Vg0Qo4
PS: I 've been busy last week, but when i can i will try to release the Automatic Windows Build i have promessed.

I am astonished developing team didn't include pycrypto into streamlink core as chrippa did to livestreamer.

@RosadinTV, you're my hero! 
"Crypto" folder was placed within "Streamlink" directory and now portable Streamlink 
downloads those MTV clips fine: 

```
F:\Applications\Livestreamer\StreamlinkPortable[byRosadinTV]\Streamlink-0.0.2-wi
n32-v2.0>streamlink -o "03. Zara Larsson - Lush Life + Ain't My Fault (Live At T
he 2016 MTV EMAs).ts" "hlsvariant://https://cp450888-vh.akamaihd.net/i/mtviestor
/_!/intlod/MTVInternational/MBUS/TACTIC/MVI_dev/INDIE/VIAMTVIPY/C9849AELU0/VIAMT
VIPYC9849AELU0_,384x216_150_b30,384x216_400_m30,448x252_450_b30,512x288_750_m30,
640x360_1200_m30,960x540_2200_m31,1280x720_3500_h32,.mp4.csmil/master.m3u8?hdnea
=st%3D1478877688%7Eexp%3D1478892088%7Eacl%3D%2Fi%2Fmtviestor%2F_*%2Fintlod%2FMTV
International%2FMBUS%2FTACTIC%2FMVI_dev%2FINDIE%2FVIAMTVIPY%2FC9849AELU0%2FVIAMT
VIPYC9849AELU0_%2C384x216_150_b30%2C384x216_400_m30%2C448x252_450_b30%2C512x288_
750_m30%2C640x360_1200_m30%2C960x540_2200_m31%2C1280x720_3500_h32%2C.mp4.csmil%2
F*%7Ehmac%3Dad2e8b0fe901b2b376e6d187ed32cf5209f6a651657770c197033f9151b50b5c&__a
__=off&__b__=450&__viacc__=NONE" best
[cli][info] Found matching plugin stream for URL hlsvariant://https://cp450888-v
h.akamaihd.net/i/mtviestor/_!/intlod/MTVInternational/MBUS/TACTIC/MVI_dev/INDIE/
VIAMTVIPY/C9849AELU0/VIAMTVIPYC9849AELU0_,384x216_150_b30,384x216_400_m30,448x25
2_450_b30,512x288_750_m30,640x360_1200_m30,960x540_2200_m31,1280x720_3500_h32,.m
p4.csmil/master.m3u8?hdnea=st%3D1478877688%7Eexp%3D1478892088%7Eacl%3D%2Fi%2Fmtv
iestor%2F_*%2Fintlod%2FMTVInternational%2FMBUS%2FTACTIC%2FMVI_dev%2FINDIE%2FVIAM
TVIPY%2FC9849AELU0%2FVIAMTVIPYC9849AELU0_%2C384x216_150_b30%2C384x216_400_m30%2C
448x252_450_b30%2C512x288_750_m30%2C640x360_1200_m30%2C960x540_2200_m31%2C1280x7
20_3500_h32%2C.mp4.csmil%2F*%7Ehmac%3Dad2e8b0fe901b2b376e6d187ed32cf5209f6a65165
7770c197033f9151b50b5c&__a__=off&__b__=450&__viacc__=NONE
[cli][info] Available streams: 216p (worst), 252p, 288p, 360p, 540p, 720p (best)

[cli][info] Opening stream: 720p (hls)
[download][..t The 2016 MTV EMAs).ts] Written 99.1 MB (1m20s @ 1.3 MB/s)       [
cli][info] Stream ended
```

So again a BIG thanks for your support! (Those 720p clips do look nice on friend's new 50'' TV!!!)

@karlo2105 : Are you refering (by "**you**") to @RosadinTV ? I don' think it was his fault to begin with... 
If you mean the "streamlink" dev team, then yes, this is something they should probably fix... 

Cheers

@Vangelis66 Cool, glad to see it works 😄 
In response to @karlo2105 i dont think is a problem with streamlink itself, problably both @sbstp and me forgive to include the PyCrypto package, in the case of livestreamer PyCrypto is placed inside library.zip file, but in fact is the same (also note by the new way we are using the whole library instead of the reduced one included in livestreamer release)

@karlo2105 This is an open source project run by volunteers, many of which were not familiar with the internal workings of the original project and there hadn't been any development in a year, so sometimes things are going to get missed for rarely used streaming services like MTV. The constant negativity really isn't warranted, and is actively detrimental to the project so please stop. If you don't like something then fix it, you have the ability to open PRs just as much as anyone else. If you don't think development is occurring quickly enough, or you want a specific feature in a more timely manner then please pay someone to work on said feature.

@gravyboat 
I didn't say a single word when Chrippa slowed and stopped developping Livestreamer. I am grateful to anybody who is fixing code and developing furthermore streamlink. All I can do is open issues when i noticed some plugin is broken and to encourage you to keep on. I don't have developer skills. 
You can take any time you want to continue developing or not. I was not aware that pycrypto library wasn't included in Livestreamer fork but I agree it's better to use the whole pycrypto library instead of the reduced one. 

Yeah, it's just an oversight. I based the installer on the setup.py script, and there's no mention of pycrypto in it.

**To all**: 
I never thought my report would create an ill atmosphere between the developers and us, mere users-testers... 

@gravyboat: 
I am very well aware of the way Open Source projects exist, function and continue to develop over time, 
as I am following quite a number of them; all the above is achieved through a considerable effort on the 
part of the developers, taking a serious bite out of their everyday lives/spare time; not to mention the altruistic nature of actually sharing knowledge/code! 

With regards to the comment made by @karlo2105, maybe his actual wording wasn't carefully chosen, so that left some room for misinterpretation (even to me when I first read it...). Please acknowledge that English is not a native language for most of us (including me), so "accidents" may happen...

What I sometimes resent is the attitude from some developers, also echoed in your comment, 
that "_If you don't like something then fix it, you have the ability to open PRs just as much as anyone else_". 
The cruel fact is that I have zero coding skills, so the above suggestion is a no-go for me, 
much like it is for @karlo2105; but I like to contribute to Open Source projects in the best (and only) 
way I can, which is identifying and reporting bugs. I am never pushy or demanding on the devs, 
just letting them know that something doesn't work as intended. It's up to them to follow up 
my report in the best way/time they see fit (and that is why I am so pleasantly surprised by 
@RosadinTV's immediate response!).

Reporting bugs in an efficient fashion also takes spare time for the reporter and is also done on a pure voluntary basis; I would argue my spare time is as precious as a developer's spare time... 
With reference to this specific issue I filed, what I wanted to achieve could be done with the abandoned livestreamer app; I could let the issue slip away and stay silent about it, especially, as you put it,  since it 
involves "_rarely used streaming services like MTV_". But I chose to report it so that, in the long 
run, streamlink would get better...

To conclude and summarize, of course all the credit goes to the coders, but mere users-testers 
like myself and @karlo2105 do play some role in the evolution of the project!

@Vangelis66 Yes, of course, bugs reporting and testing is a really good job, it can be as important as programming.
The important thing about these types of projects is that each contributes what it can.
PS: What is your native language?

@RosadinTV asked:

> What is your native language?

... Well, I'd have thought my username gave that away already, but it's actually **_Greek_**!

@Vangelis66 Cool, in my case is Spanish .. It's good to see so much diversity.

@Vangelis66 You're absolutely right and my comment was not targeted at you (your bug report was great) and I could have done a better job thinking about how it sounded when others read the comment I was responding to and my response. My apologies @karlo2105. 

Reporting bugs and doing testing is critical to an open source project and your help is greatly appreciated. I apologize if my comment came off negatively, it was not intended to. I would never mean to infer that reporting bugs or creating issues is in some way less valuable than the work that developers or anyone else does on an open source project. We all contribute in our own way, I simply want to ensure these interactions are positive and there is understanding between everyone that sometimes things are missed, we are only human after all! We can only fix the things we are aware of, so please keep sharing and providing these excellent troubleshooting steps you have taken to provide us with as much information as possible. Please do not discredit yourself as 'mere user-testers', as software without any users is worthless, and helping to improve that software (whether through code, bug reports, writing documentation, etc.) is one of the most valuable things a project can ask for. This is an international community of people who love this project, and I want to ensure we keep things positive and constructive so we can continue to gain new users, new contributors, new bug reporters, and everything in-between!

While we wait for a new release, you can install pyCrypto for Python 3.5 with this: https://github.com/sfbahr/PyCrypto-Wheels

@gravyboat @beardypig I believe this issue is resolved with the new installer, correct? Maybe we should add pycryptodome to the setup.py as well.

@sbstp I think so, let's double check with @beardypig but we should be able to close this out. I'm not sure about pycrptodome. I assume most users on Linux would just install it themselves, but we can discuss it.

Personally I would add it to the `setup.py` file, the only thing is to double check the external dependencies - I'm not sure if you need any additional header files to compile the extension (which pip will have to do on linux and macOS). I don't think it doesn't require anything extra... 

On a minimal Ubuntu 16.04 VM I installed `pycryptodome` with out installing anything except `python-pip` from apt. 

I'm fine with including it then.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -38,6 +38,9 @@
     # requests >2.12.0 currently has strict IDNA2008 parsing that breaks on some non-compliant URIs (YouTube)
     deps.append("requests>=1.0,<2.12.0")
 
+# this version of pycryptodome is known to work and has a Windows wheel for py2.7, py3.3-3.5
+deps.append("pycryptodome==3.4.3")
+
 # When we build an egg for the Win32 bootstrap we don't want dependency
 # information built into it.
 if environ.get("NO_DEPS"):


Test patch: