Mythus commited on
Commit
86ef224
·
verified ·
1 Parent(s): 4aa133b

Create streamingwatch.py

Browse files
Files changed (1) hide show
  1. streamingwatch.py +100 -0
streamingwatch.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tmdbv3api import TMDb, Movie, TV
2
+ import requests
3
+ import logging
4
+ from bs4 import BeautifulSoup,SoupStrainer
5
+ from datetime import datetime
6
+ import dateparser
7
+ from convert import get_TMDb_id_from_IMDb_id
8
+ from info import get_info_tmdb, is_movie, get_info_imdb
9
+ import config
10
+ import re
11
+ import json
12
+ SW_DOMAIN = config.SW_DOMAIN
13
+ def search(showname,season,episode,date,ismovie):
14
+ if ismovie == 1:
15
+ query = f'https://www.streamingwatch.{SW_DOMAIN}/wp-admin/admin-ajax.php'
16
+ headers = {
17
+ 'authority': f'www.streamingwatch.{SW_DOMAIN}',
18
+ 'accept': '*/*',
19
+ 'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7',
20
+ 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
21
+ # 'cookie': 'wordpress_test_cookie=WP%20Cookie%20check',
22
+ 'origin': f'https://www.streamingwatch.{SW_DOMAIN}',
23
+ 'referer': f'https://www.streamingwatch.{SW_DOMAIN}',
24
+ 'sec-ch-ua': '"Not-A.Brand";v="99", "Chromium";v="124"',
25
+ 'sec-ch-ua-mobile': '?0',
26
+ 'sec-ch-ua-platform': '"Android"',
27
+ 'sec-fetch-dest': 'empty',
28
+ 'sec-fetch-mode': 'cors',
29
+ 'sec-fetch-site': 'same-origin',
30
+ 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
31
+ 'x-requested-with': 'XMLHttpRequest',
32
+ }
33
+ data = {
34
+ 'action': 'data_fetch',
35
+ 'keyword': showname,
36
+ '_wpnonce': '3a1692f4e7',
37
+ }
38
+ cookies = {
39
+ 'wordpress_test_cookie': 'WP%20Cookie%20check',
40
+ }
41
+ response = requests.post(query,cookies=cookies, headers=headers, data=data)
42
+ print(response.content)
43
+ soup = BeautifulSoup(response.content,'lxml')
44
+ page_date = soup.find(id = 'search-cat-year').text.strip()
45
+ if page_date == date:
46
+ href = soup.find('a')['href']
47
+ response = requests.get(href)
48
+ soup = BeautifulSoup(response.text,'lxml',parse_only=SoupStrainer('iframe'))
49
+ iframe = soup.find('iframe')
50
+ hdplayer = iframe.get('data-lazy-src')
51
+
52
+ return hdplayer
53
+ elif ismovie == 0:
54
+ query = f'https://streamingwatch.{SW_DOMAIN}/wp-json/wp/v2/posts?search={showname}'
55
+ response = requests.get(query)
56
+ data_json = response.text
57
+ data = json.loads(data_json)
58
+ for entry in data:
59
+ if f"stagione-{season}-episodio-{episode}" in entry["slug"]:
60
+ content = entry["content"]["rendered"]
61
+ #"content":{
62
+ # "rendered":"<p><!--baslik:PRO--><iframe loading=\"lazy\" src=\"https:\/\/hdplayer.gives\/embed\/YErLVq64uNTZRNz\" frameborder=\"0\" width=\"700\" height=\"400\" allowfullscreen><\/iframe><\/p>\n","protected":false}
63
+ hdplayer = content[48:]
64
+ end = hdplayer.find('"')
65
+ hdplayer = hdplayer[:end]
66
+ return hdplayer
67
+ def hls_url(hdplayer):
68
+ response = requests.get(hdplayer)
69
+ match = re.search(r'sources:\s*\[\s*\{\s*file\s*:\s*"([^"]*)"', response.text)
70
+ url = match.group(1)
71
+ print(url)
72
+ return url
73
+ def streamingwatch(imdb):
74
+ try:
75
+ general = is_movie(imdb)
76
+ ismovie = general[0]
77
+ imdb_id = general[1]
78
+ type = "StreamingWatch"
79
+ if ismovie == 0:
80
+ season = int(general[2])
81
+ episode = int(general[3])
82
+ if "tt" in imdb:
83
+ tmdba = get_TMDb_id_from_IMDb_id(imdb_id)
84
+ else:
85
+ tmdba = imdb_id
86
+ else:
87
+ season = None
88
+ episode = None
89
+ if "tt" in imdb:
90
+ tmdba = get_TMDb_id_from_IMDb_id(imdb_id)
91
+ else:
92
+ tmdba = imdb_id
93
+ showname,date = get_info_tmdb(tmdba,ismovie,type)
94
+ showname = showname.replace(" ", "+").replace("–", "+").replace("—","+")
95
+ hdplayer = search(showname,season,episode,date,ismovie)
96
+ url = hls_url(hdplayer)
97
+ return url
98
+ except:
99
+ print("StreamingWatch Failed")
100
+ return None