Last active
August 6, 2016 10:26
-
-
Save Katharine/4e8decce0ba90ebe60b4bd81e5d12151 to your computer and use it in GitHub Desktop.
Takes mediafire URLs on stdin, spits out real URLs on stdout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import re | |
import requests | |
def resolve_mediafire(url): | |
result = requests.get(url) | |
if not result.ok: | |
return None | |
matches = re.search(r'kNO = "(.+)";', result.text) | |
if matches is None: | |
return None | |
return matches.group(1) | |
def main(): | |
import fileinput | |
import sys | |
failures = [] | |
for line in fileinput.input(): | |
url = line.strip() | |
resolved = resolve_mediafire(url) | |
if resolved is None: | |
failures.append(url) | |
else: | |
print(resolved) | |
print("------", file=sys.stderr) | |
print("\n".join(failures), file=sys.stderr) | |
print("{} failed.".format(len(failures)), file=sys.stderr) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment