Fixes Yify/popcorn/#1 

Working version from isra17's fork.