Skip to content

Commit

Permalink
Fix for special characters and #15
Browse files Browse the repository at this point in the history
Fix for special characters and #15
  • Loading branch information
Xonshiz committed Jul 5, 2017
1 parent 0285c4f commit 637664c
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 322 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ Temporary Items
anime_dl/build/__main__/warn__main__.txt
*.ass
*.mp4
*.log
*.mkv
anime_dl/sites/funimation - Copy.py
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
- Fix for #12 [2017.05.30]
- Site support for Funimation.com [2017.05.30]
- Fix for #8 [2017.05.30]
- Muxing All The Subtitles [2017.07.03]
- Muxing All The Subtitles [2017.07.03]
- Fix for special characters and #15 [2017.07.05]
5 changes: 4 additions & 1 deletion anime_dl/AnimeDL.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# from urllib.parse import urlparse
try:
from urllib.parse import urlparse
except ImportError:
Expand Down Expand Up @@ -41,6 +40,10 @@ def honcho(self, url):
# Verify that we have a sane url and return which website it belongs
# to.

# Fix for script not responding when www.crunchyrol.com/... type links are given.
if "http://" not in url:
url = "http://" + str(url)

# if there's not http:/, then netloc is empty.
# Gotta add the "if crunchyroll in url..."
# print(url)
Expand Down
3 changes: 3 additions & 0 deletions anime_dl/animeName.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
import subprocess

Expand Down
3 changes: 3 additions & 0 deletions anime_dl/downloader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from cfscrape import create_scraper
from requests import session
from tqdm import tqdm
Expand Down
555 changes: 294 additions & 261 deletions anime_dl/sites/crunchyroll.py

Large diffs are not rendered by default.

173 changes: 116 additions & 57 deletions anime_dl/sites/funimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from requests import session
from bs4 import BeautifulSoup
import re
from anime_dl import downloader, animeName
from subprocess import call
from time import sleep
import json


class Funimation(object):
Expand Down Expand Up @@ -37,73 +39,130 @@ def login(self, userUserName, userPassword):
def singleEpisode(self, url, userCookies, resolution, language):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'Territory': 'US'
'Territory': 'US',
'Referer': 'https://www.funimation.com',
'Origin': 'https://www.funimation.com'

}

sess = session()
sess = create_scraper(sess)
print("This lang : ", language)

if language.lower() in ["japanese", "sub", "jpn"]:
finalUrl = str(url) + "?lang=english"
s = sess.get(finalUrl, headers=headers, cookies=userCookies)
# print(url)

if str(language).lower() in ["english", "dub", "eng"]:
if "?lang=" in str(url):
videoUrl = str(url).lower().replace("japanese", "english")

else:
videoUrl = str(url) + "?lang=english"

elif language.lower() in ["english", "dub", "eng"]:
finalUrl = str(url).replace("simulcast", "uncut") + "?lang=english"
print(finalUrl)
s = sess.get(finalUrl, headers=headers, cookies=userCookies)
print("Got this")
elif str(language).lower() in ["japanese", "sub", "jpn"]:
if "?lang=" in str(url):
videoUrl = str(url).lower().replace("english", "japanese")
else:
videoUrl = str(url) + "?lang=japanese"
else:
s = sess.get(url + "?lang=english", headers=headers, cookies=userCookies)

cookies = sess.cookies

page_source = s.text.encode('utf-8')
htmlSource = str(BeautifulSoup(page_source, "lxml"))

videoID = int(str(re.search('id\:\ \'(.*?)\'\,', htmlSource).group(1)).strip())
seasonNumber = int(str(re.search('seasonNum: (.*?),', htmlSource).group(1)).strip())
episodeNumber = int(str(re.search('episodeNum: (.*?),', htmlSource).group(1)).strip())
showName = str(
re.search('KANE_customdimensions.showName\ \=\ \'(.*?)\'\;', htmlSource).group(1)).strip().replace("'",
"'").replace(
"&", "$")
fileName = str(showName) + " - " + str(episodeNumber) + ".mkv"
bDubNumber = int(str(re.search('"/player/(.*?)/\?bdub=0', htmlSource).group(1)).strip())
print(videoID, seasonNumber, episodeNumber, showName, bDubNumber)
videoPlayerLink = "https://www.funimation.com/player/%s/?bdub=0" % bDubNumber
print(videoPlayerLink)
sleep(10)
videoUrl = str(url)


fetchConnect = sess.get(videoUrl, headers = headers, cookies = userCookies).text.encode("utf-8")

anime_name = str(str(url).split("/")[4]).strip()

playerID = str(re.search(r'\"\/player\/(.*?)\"\>', str(fetchConnect)).group(1))

episodeNumber = str(re.search(r'episodeNum\:\ (.*?)\,', str(fetchConnect)).group(1))
seasonNumber = str(re.search(r'seasonNum\:\ (.*?)\,', str(fetchConnect)).group(1))


# https://prod-api-funimationnow.dadcdigital.com/api/source/catalog/video/<playerID>/signed/

headersNew = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'Territory': 'US',
'Referer' : '%s' % finalUrl
'Referer' : 'https://www.funimation.com/player/%s/?bdub=0' % playerID,
'Origin' : 'https://www.funimation.com'

}
playerSource = sess.get(videoPlayerLink, headers=headersNew).text
print(playerSource)
main_m3u8Link = str(re.search('"screenshots":(.*?)"],', playerSource).group(1)).strip().replace("[\"", "").replace("exp/", "")
print(main_m3u8Link)
try:
srtLink = str(re.search('"src":(.*?)\.srt"', playerSource).group(1)).strip().replace("[\"", "").replace("exp/", "")
print(srtLink)
except:
pass

if resolution.lower() in ["1080p", "fhd", "1080"]:
m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer9.m3u8")
elif resolution.lower() in ["720p", "hd", "720"]:
m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer7.m3u8")
elif resolution.lower() in ["540p", "sd", "540"]:
m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer5.m3u8")
elif resolution.lower() in ["360p", "crap", "360"]:
m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer4.m3u8")
elif resolution.lower() in ["270p", "cancer", "270"]:
m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer2.m3u8")
elif resolution.lower() in ["234p", "killme", "234"]:
m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer1.m3u8")

print(m3u8LinkFinal)
ffmpegCommand = "ffmpeg -i \"%s\" -c copy \"%s\"" % (m3u8LinkFinal, fileName)
call(ffmpegCommand)

pageReferer = 'https://www.funimation.com/player/%s/?bdub=0' % playerID

apiUrl = "https://prod-api-funimationnow.dadcdigital.com/api/source/catalog/video/%s/signed/" % playerID
jsonReply = sess.get(apiUrl, headers = headersNew, cookies = userCookies).text

jsonLoad = json.loads(jsonReply)
mp4Link = str(jsonLoad['items'][0]['src'])
m3u8Link = str(jsonLoad['items'][1]['src'])


reso = str(resolution)
fileName = animeName.animeName().nameEditFuni(anime_name, seasonNumber, episodeNumber, reso)

# downloader.downloader().File_Downloader(mp4Link.replace("English", "Japanese"), fileName, pageReferer, userCookies)
downloader.downloader().parseurl(m3u8Link)



# if language.lower() in ["japanese", "sub", "jpn"]:
# finalUrl = str(url) + "?lang=english"
# s = sess.get(finalUrl, headers=headers, cookies=userCookies)
#
# elif language.lower() in ["english", "dub", "eng"]:
# finalUrl = str(url).replace("simulcast", "uncut") + "?lang=english"
# print(finalUrl)
# s = sess.get(finalUrl, headers=headers, cookies=userCookies)
# print("Got this")
# else:
# s = sess.get(url + "?lang=english", headers=headers, cookies=userCookies)
#
# cookies = sess.cookies
#
# page_source = s.text.encode('utf-8')
# htmlSource = str(BeautifulSoup(page_source, "lxml"))
#
# videoID = int(str(re.search('id\:\ \'(.*?)\'\,', htmlSource).group(1)).strip())
# seasonNumber = int(str(re.search('seasonNum: (.*?),', htmlSource).group(1)).strip())
# episodeNumber = int(str(re.search('episodeNum: (.*?),', htmlSource).group(1)).strip())
# showName = str(
# re.search('KANE_customdimensions.showName\ \=\ \'(.*?)\'\;', htmlSource).group(1)).strip().replace("&#39;",
# "'").replace(
# "&amp;", "$")
# fileName = str(showName) + " - " + str(episodeNumber) + ".mkv"
# bDubNumber = int(str(re.search('"/player/(.*?)/\?bdub=0', htmlSource).group(1)).strip())
# print(videoID, seasonNumber, episodeNumber, showName, bDubNumber)
# videoPlayerLink = "https://www.funimation.com/player/%s/?bdub=0" % bDubNumber
# print(videoPlayerLink)
# sleep(10)
# headersNew = {
# 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
# 'Territory': 'US',
# 'Referer' : '%s' % finalUrl
#
# }
# playerSource = sess.get(videoPlayerLink, headers=headersNew).text
# print(playerSource)
# main_m3u8Link = str(re.search('"screenshots":(.*?)"],', playerSource).group(1)).strip().replace("[\"", "").replace("exp/", "")
# print(main_m3u8Link)
# try:
# srtLink = str(re.search('"src":(.*?)\.srt"', playerSource).group(1)).strip().replace("[\"", "").replace("exp/", "")
# print(srtLink)
# except:
# pass
#
# if resolution.lower() in ["1080p", "fhd", "1080"]:
# m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer9.m3u8")
# elif resolution.lower() in ["720p", "hd", "720"]:
# m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer7.m3u8")
# elif resolution.lower() in ["540p", "sd", "540"]:
# m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer5.m3u8")
# elif resolution.lower() in ["360p", "crap", "360"]:
# m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer4.m3u8")
# elif resolution.lower() in ["270p", "cancer", "270"]:
# m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer2.m3u8")
# elif resolution.lower() in ["234p", "killme", "234"]:
# m3u8LinkFinal = main_m3u8Link.replace(".m3u8", "_Layer1.m3u8")
#
# print(m3u8LinkFinal)
# ffmpegCommand = "ffmpeg -i \"%s\" -c copy \"%s\"" % (m3u8LinkFinal, fileName)
# call(ffmpegCommand)
2 changes: 1 addition & 1 deletion anime_dl/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Format : YY/MM/DD
__version__ = "2017.07.03"
__version__ = "2017.07.05"
3 changes: 2 additions & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
- Fix for #12 [2017.05.30]
- Site support for Funimation.com [2017.05.30]
- Fix for #8 [2017.05.30]
- Muxing All The Subtitles [2017.07.03]
- Muxing All The Subtitles [2017.07.03]
- Fix for special characters and #15 [2017.07.05]

0 comments on commit 637664c

Please sign in to comment.