<commit_before>#!/usr/bin/env python

"""ChromeDesk.py: A simple chrome-cast desktop wallpaper parser that allows app to download set as wallpapers images casted by google ."""

__author__  = "<NAME>"
__license__ = "LGPL"
__version__ = "2.1"
__email__   = "<EMAIL>"

import urllib2
import ctypes
import os
import random
import threading
import platform
from functools import partial

class ChromeDesk():

  def __init__( self , t_rotation = 300, dl_dir = 'Wallpapers'):
    self.dl_dir       = dl_dir
    self.t_rotation   = t_rotation
    self.image_links  = None
    self.folder_empty = True
    self.running      = False
    self.imgp         = 0
    self.choice       = ""
    self.cleanup_flg  = False
    self.platform     = ( platform.system(), os.getenv("DESKTOP_SESSION") )

  def get_source( self ):
    return  urllib2.urlopen('https://clients3.google.com/cast/chromecast/home').read()

  def extract_img( self, text ):
    output = {}
    temp   = []

    #Pre proccessing html clean up
    origin = text.find("JSON.parse")
    end_index = text.find(")). constant")
    text = text[origin+19:end_index]
    text = text.replace("\\","")

    while(True):
      #Extract the image URL
      jpeg_start = text.find("https://l")
      jpeg_end = text.find("x22,x22",jpeg_start+1)
      jpeg = text[jpeg_start:jpeg_end]

      #break if find does not 
      if jpeg_start == -1:
        break

      #extract the Author URL
      author_start = jpeg_end+7
      author_end = text.find("x22",author_start+1)
      author = text[author_start:author_end]
      
      #remove the processed data from the string
      text = text[author_end:]
      output[author] = jpeg

    #download the images
    self.download_img(output)
    self.image_links = output
    return output

  def stop_periodic_callback( self ):
    global t1_run_flag
    t1_run_flag = False

  def attach_periodic_callback ( self, cb ):
    global t1_run_flag

    #set the configuration
    t1_run_flag = True

    #Add background processes
    def background_timer( t_cycle, callback ):
      import time
      global t1_run_flag

      ref_time = time.time()
      while ( t1_run_flag ):
        cur_time = time.time()<commit_msg>Fixed an Error on parsing Satellite images Increased the resolution of retrieved images to 1080p<commit_after>#!/usr/bin/env python

"""ChromeDesk.py: A simple chrome-cast desktop wallpaper parser that allows app to download set as wallpapers images casted by google ."""

__author__  = "<NAME>"
__license__ = "LGPL"
__version__ = "2.1"
__email__   = "<EMAIL>"

import urllib2
import ctypes
import os
import random
import threading
import platform
from functools import partial

class ChromeDesk():

  def __init__( self , t_rotation = 300, dl_dir = 'Wallpapers'):
    self.dl_dir       = dl_dir
    self.t_rotation   = t_rotation
    self.image_links  = None
    self.folder_empty = True
    self.running      = False
    self.imgp         = 0
    self.choice       = ""
    self.cleanup_flg  = False
    self.platform     = ( platform.system(), os.getenv("DESKTOP_SESSION") )

  def get_source( self ):
    return  urllib2.urlopen('https://clients3.google.com/cast/chromecast/home').read()

  def extract_img( self, text ):
    output = {}
    temp   = []

    #Pre proccessing html clean up
    origin = text.find("JSON.parse")
    end_index = text.find(")). constant")
    text = text[origin+19:end_index]

    #replace utf-8 '=' char with ASCII equivalent
    text = text.replace("\\u003d","=")
    #remove redundant escape chars
    text = text.replace("\\","")

    while(True):
      #Extract the image URL
      jpeg_start = text.find("https://l")
      jpeg_end = text.find("x22,x22",jpeg_start+1)
      jpeg = text[jpeg_start:jpeg_end]
      #Satellite Fix
      #One of the images broadcast by google is a random google map image
      #it needs to be further processed
      if 'x22' in jpeg:
        #crop the non image related data
        jpeg = jpeg[:jpeg.find('x22')]

      #break if find does not 
      if jpeg_start == -1:
        break

      #Change the request to ask for the 1080 version of the image
      jpeg = jpeg.replace("s1280","s1920")
      jpeg = jpeg.replace("w1280","w1920")
      jpeg = jpeg.replace("h720","h1080")

      #extract the Author URL
      author_start = jpeg_end+7
      author_end = text.find("x22",author_start+1)
      author = text[author_start:author_end]
      #Satellite Fix
      if '.com' in author:
        author = author[:author.find('.com')+4]
      
      #remove the processed data from the string
      text = text[author_end:]
      output[author] = jpeg

    #download the images
    self.download_img(output)
    self.image_links = output
    return output

  def stop_periodic_callback( self ):
    global t1_run_flag
    t1_run_flag = False

  def attach_periodic_callback ( self, cb ):
    global t1_run_flag

    #set the configuration
    t1_run_flag = True

    #Add background processes
    def background_timer( t_cycle, callback ):
      import time
      global t1_run_flag

      ref_time = time.time()
      while ( t1_run_flag ):
        cur_time = time.time()
{'fraction_non_alphanumeric': 0.10289264220539701, 'fraction_numerical': 0.0182488837119006, 'mean_word_length': 2.7715959004392388, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3654794', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1620, 'n_words': 446}