Skip to content

Instantly share code, notes, and snippets.

@Katharine
Last active August 6, 2016 10:26
Show Gist options
  • Save Katharine/4e8decce0ba90ebe60b4bd81e5d12151 to your computer and use it in GitHub Desktop.
Save Katharine/4e8decce0ba90ebe60b4bd81e5d12151 to your computer and use it in GitHub Desktop.
Takes mediafire URLs on stdin, spits out real URLs on stdout.
#!/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